Fixes a crash in macOS 26

This commit is contained in:
Peter Steinberger 2025-06-19 05:16:09 +02:00
parent ba7d66aa88
commit 3c31ae0692
3 changed files with 27 additions and 9 deletions

View file

@ -92,12 +92,8 @@ struct VTCommandPageView: View {
.frame(maxWidth: .infinity, maxHeight: .infinity) .frame(maxWidth: .infinity, maxHeight: .infinity)
.padding() .padding()
.onAppear { .onAppear {
Task { // Check installation status synchronously on appear
// This happens on startup, but we wanna refresh before showing. cliInstaller.checkInstallationStatus()
await MainActor.run {
cliInstaller.checkInstallationStatus()
}
}
} }
} }
} }

View file

@ -123,10 +123,19 @@ struct WelcomeView: View {
currentPage += 1 currentPage += 1
} }
} else { } else {
// Finish action - open Settings // Finish action - save welcome version and close window
welcomeVersion = AppConstants.currentWelcomeVersion 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<WelcomeView> }) {
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()
}
} }
} }
} }

View file

@ -27,6 +27,9 @@ final class WelcomeWindowController: NSWindowController, NSWindowDelegate {
// Use normal window level instead of floating // Use normal window level instead of floating
window.level = .normal window.level = .normal
// Set content view mode to ensure proper cleanup
hostingController.sizingOptions = [.preferredContentSize]
super.init(window: window) super.init(window: window)
// Set self as window delegate // Set self as window delegate
@ -77,6 +80,16 @@ final class WelcomeWindowController: NSWindowController, NSWindowDelegate {
show() 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))
}
}
} }
// MARK: - Notification Extension // MARK: - Notification Extension