-
-
Notifications
You must be signed in to change notification settings - Fork 119
fix: close main window before reopening welcome on connection failure #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -473,21 +473,26 @@ struct WelcomeWindowView: View { | |
| do { | ||
| try await dbManager.connectToSession(connection) | ||
| } catch { | ||
| // Show error to user and re-open welcome window | ||
| await MainActor.run { | ||
| AlertHelper.showErrorSheet( | ||
| title: String(localized: "Connection Failed"), | ||
| message: error.localizedDescription, | ||
| window: nil | ||
| ) | ||
| openWindow(id: "welcome") | ||
| } | ||
| Self.logger.error( | ||
| "Failed to connect: \(error.localizedDescription, privacy: .public)") | ||
| handleConnectionFailure(error: error) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private func handleConnectionFailure(error: Error) { | ||
| // Close the main window first so macOS doesn't merge it with the welcome window | ||
| NSApplication.shared.closeWindows(withId: "main") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| openWindow(id: "welcome") | ||
|
|
||
| // Show error as modal — welcome window is now the only window | ||
| AlertHelper.showErrorSheet( | ||
| title: String(localized: "Connection Failed"), | ||
| message: error.localizedDescription, | ||
| window: nil | ||
| ) | ||
| } | ||
|
|
||
| private func deleteConnection(_ connection: DatabaseConnection) { | ||
| connections.removeAll { $0.id == connection.id } | ||
| storage.deleteConnection(connection) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In
connectToDatabase, thecatchpath now callshandleConnectionFailuredirectly from an unstructuredTask, but that helper performs AppKit/SwiftUI UI work (closeWindows,openWindow,AlertHelper.showErrorSheet). Because the previousawait MainActor.runhop was removed, failed connections can execute UI operations off the main actor, which can trigger AppKit thread-safety crashes or undefined UI behavior during connection errors.Useful? React with 👍 / 👎.