diff --git a/VibeTunnel/Presentation/Views/Welcome/VTCommandPageView.swift b/VibeTunnel/Presentation/Views/Welcome/VTCommandPageView.swift index 04f4c1dd..d6e09e6e 100644 --- a/VibeTunnel/Presentation/Views/Welcome/VTCommandPageView.swift +++ b/VibeTunnel/Presentation/Views/Welcome/VTCommandPageView.swift @@ -92,12 +92,8 @@ struct VTCommandPageView: View { .frame(maxWidth: .infinity, maxHeight: .infinity) .padding() .onAppear { - Task { - // This happens on startup, but we wanna refresh before showing. - await MainActor.run { - cliInstaller.checkInstallationStatus() - } - } + // Check installation status synchronously on appear + cliInstaller.checkInstallationStatus() } } } diff --git a/VibeTunnel/Presentation/Views/WelcomeView.swift b/VibeTunnel/Presentation/Views/WelcomeView.swift index 8a34d338..189a7b24 100644 --- a/VibeTunnel/Presentation/Views/WelcomeView.swift +++ b/VibeTunnel/Presentation/Views/WelcomeView.swift @@ -123,10 +123,19 @@ struct WelcomeView: View { currentPage += 1 } } else { - // Finish action - open Settings + // Finish action - save welcome version and close window welcomeVersion = AppConstants.currentWelcomeVersion - dismiss() - SettingsOpener.openSettings() + + // Close the window properly through the window controller + if let window = NSApp.windows.first(where: { $0.contentViewController is NSHostingController }) { + window.close() + } + + // Open settings after a delay to ensure the window is fully closed + Task { @MainActor in + try? await Task.sleep(for: .milliseconds(200)) + SettingsOpener.openSettings() + } } } } diff --git a/VibeTunnel/Utilities/WelcomeWindowController.swift b/VibeTunnel/Utilities/WelcomeWindowController.swift index 68806ef2..f2b3b965 100644 --- a/VibeTunnel/Utilities/WelcomeWindowController.swift +++ b/VibeTunnel/Utilities/WelcomeWindowController.swift @@ -26,6 +26,9 @@ final class WelcomeWindowController: NSWindowController, NSWindowDelegate { window.isReleasedWhenClosed = false // Use normal window level instead of floating window.level = .normal + + // Set content view mode to ensure proper cleanup + hostingController.sizingOptions = [.preferredContentSize] super.init(window: window) @@ -76,6 +79,16 @@ final class WelcomeWindowController: NSWindowController, NSWindowDelegate { private func handleShowWelcomeNotification() { show() } + + // MARK: - NSWindowDelegate + + func windowWillClose(_ notification: Notification) { + // Ensure any async tasks are cancelled + Task { @MainActor in + // Give SwiftUI time to clean up + try? await Task.sleep(for: .milliseconds(100)) + } + } }