Skip to content

Commit 6f5ed15

Browse files
authored
Merge pull request #236 from datlechin/fix/connection-failure-window-cleanup
fix: close main window before reopening welcome on connection failure
2 parents ad87bcd + 1fdb5e9 commit 6f5ed15

1 file changed

Lines changed: 14 additions & 9 deletions

File tree

TablePro/Views/Connection/WelcomeWindowView.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -473,21 +473,26 @@ struct WelcomeWindowView: View {
473473
do {
474474
try await dbManager.connectToSession(connection)
475475
} catch {
476-
// Show error to user and re-open welcome window
477-
await MainActor.run {
478-
AlertHelper.showErrorSheet(
479-
title: String(localized: "Connection Failed"),
480-
message: error.localizedDescription,
481-
window: nil
482-
)
483-
openWindow(id: "welcome")
484-
}
485476
Self.logger.error(
486477
"Failed to connect: \(error.localizedDescription, privacy: .public)")
478+
handleConnectionFailure(error: error)
487479
}
488480
}
489481
}
490482

483+
private func handleConnectionFailure(error: Error) {
484+
// Close the main window first so macOS doesn't merge it with the welcome window
485+
NSApplication.shared.closeWindows(withId: "main")
486+
openWindow(id: "welcome")
487+
488+
// Show error as modal — welcome window is now the only window
489+
AlertHelper.showErrorSheet(
490+
title: String(localized: "Connection Failed"),
491+
message: error.localizedDescription,
492+
window: nil
493+
)
494+
}
495+
491496
private func deleteConnection(_ connection: DatabaseConnection) {
492497
connections.removeAll { $0.id == connection.id }
493498
storage.deleteConnection(connection)

0 commit comments

Comments
 (0)