From 6b0f7764bfa3decce77ba092369761487f69f583 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 17 Jun 2025 03:38:11 +0200 Subject: [PATCH] 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 --- VibeTunnel/Core/Services/ServerManager.swift | 2 +- VibeTunnel/Utilities/ApplicationMover.swift | 33 +++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/VibeTunnel/Core/Services/ServerManager.swift b/VibeTunnel/Core/Services/ServerManager.swift index 3efd68f6..4487d086 100644 --- a/VibeTunnel/Core/Services/ServerManager.swift +++ b/VibeTunnel/Core/Services/ServerManager.swift @@ -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() } } diff --git a/VibeTunnel/Utilities/ApplicationMover.swift b/VibeTunnel/Utilities/ApplicationMover.swift index 2c00334e..b3fd69fc 100644 --- a/VibeTunnel/Utilities/ApplicationMover.swift +++ b/VibeTunnel/Utilities/ApplicationMover.swift @@ -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) + } + } + } + } } } }