From 1fdb5e9004409e708a7d80fbe4ef66804ffcb8be Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Mon, 9 Mar 2026 23:00:17 +0700 Subject: [PATCH] fix: close main window before reopening welcome on connection failure --- .../Views/Connection/WelcomeWindowView.swift | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/TablePro/Views/Connection/WelcomeWindowView.swift b/TablePro/Views/Connection/WelcomeWindowView.swift index de88bda0..90869319 100644 --- a/TablePro/Views/Connection/WelcomeWindowView.swift +++ b/TablePro/Views/Connection/WelcomeWindowView.swift @@ -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") + 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)