Fix Swift 6 concurrency issues

- Use .values on NotificationCenter notifications AsyncSequence
- Replace openApplication with open to avoid non-Sendable return type
- Properly handle async operations within MainActor context
This commit is contained in:
Peter Steinberger 2025-06-17 03:38:11 +02:00
parent 4bdf5ebea3
commit 6b0f7764bf
2 changed files with 23 additions and 12 deletions

View file

@ -74,7 +74,7 @@ class ServerManager {
private func setupObservers() {
// Watch for server mode changes when the value actually changes
Task { @MainActor in
for await _ in NotificationCenter.default.notifications(named: UserDefaults.didChangeNotification) {
for await _ in NotificationCenter.default.notifications(named: UserDefaults.didChangeNotification).values {
await handleServerModeChange()
}
}

View file

@ -319,17 +319,28 @@ final class ApplicationMover {
let appURL = URL(fileURLWithPath: newPath)
Task { @MainActor in
do {
let configuration = NSWorkspace.OpenConfiguration()
try await workspace.openApplication(at: appURL, configuration: configuration)
logger.info("Launched app from Applications, quitting current instance")
// Quit current instance after a short delay to ensure the new one starts
try? await Task.sleep(for: .milliseconds(500))
NSApp.terminate(nil)
} catch {
logger.error("Failed to launch app from Applications: \(error)")
showLaunchError(error)
let configuration = NSWorkspace.OpenConfiguration()
// Use openURL instead of openApplication to avoid non-Sendable return type
configuration.activates = true
configuration.promptsUserIfNeeded = true
workspace.open(appURL, configuration: configuration) { (app, error) in
Task { @MainActor in
if let error = error {
self.logger.error("Failed to launch app from Applications: \(error)")
self.showLaunchError(error)
} else {
self.logger.info("Launched app from Applications, quitting current instance")
// Quit current instance after a short delay to ensure the new one starts
Task {
try? await Task.sleep(for: .milliseconds(500))
await MainActor.run {
NSApp.terminate(nil)
}
}
}
}
}
}
}