From 8cf68a6fc2be9144852879451baca433b0b06e62 Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Fri, 13 Mar 2026 00:14:21 +0700 Subject: [PATCH 1/2] fix: clean up session and UI when driver plugin is missing on connect --- TablePro/Core/Database/DatabaseManager.swift | 15 ++++++++++++++- .../Views/Connection/ConnectionFormView.swift | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/TablePro/Core/Database/DatabaseManager.swift b/TablePro/Core/Database/DatabaseManager.swift index 45f096a41..1ec1a86b9 100644 --- a/TablePro/Core/Database/DatabaseManager.swift +++ b/TablePro/Core/Database/DatabaseManager.swift @@ -114,7 +114,20 @@ final class DatabaseManager { } // Create appropriate driver with effective connection - let driver = try DatabaseDriverFactory.createDriver(for: effectiveConnection) + let driver: DatabaseDriver + do { + driver = try DatabaseDriverFactory.createDriver(for: effectiveConnection) + } catch { + // Close tunnel if SSH was established + if connection.sshConfig.enabled { + Task { + try? await SSHTunnelManager.shared.closeTunnel(connectionId: connection.id) + } + } + activeSessions.removeValue(forKey: connection.id) + currentSessionId = nil + throw error + } do { try await driver.connect() diff --git a/TablePro/Views/Connection/ConnectionFormView.swift b/TablePro/Views/Connection/ConnectionFormView.swift index b6abb4b49..9e48d05cd 100644 --- a/TablePro/Views/Connection/ConnectionFormView.swift +++ b/TablePro/Views/Connection/ConnectionFormView.swift @@ -1014,6 +1014,13 @@ struct ConnectionFormView: View { } else { Self.logger.error( "Failed to connect: \(error.localizedDescription, privacy: .public)") + NSApplication.shared.closeWindows(withId: "main") + openWindow(id: "welcome") + AlertHelper.showErrorSheet( + title: String(localized: "Connection Failed"), + message: error.localizedDescription, + window: nil + ) } } } From a2835c18291b4ee7aa59f4b741e369ac3642c5db Mon Sep 17 00:00:00 2001 From: Ngo Quoc Dat Date: Fri, 13 Mar 2026 00:16:27 +0700 Subject: [PATCH 2/2] fix: close stuck main window on connectAfterInstall failure --- TablePro/Views/Connection/ConnectionFormView.swift | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/TablePro/Views/Connection/ConnectionFormView.swift b/TablePro/Views/Connection/ConnectionFormView.swift index 9e48d05cd..a2de72222 100644 --- a/TablePro/Views/Connection/ConnectionFormView.swift +++ b/TablePro/Views/Connection/ConnectionFormView.swift @@ -1042,6 +1042,13 @@ struct ConnectionFormView: View { } catch { Self.logger.error( "Failed to connect after plugin install: \(error.localizedDescription, privacy: .public)") + NSApplication.shared.closeWindows(withId: "main") + openWindow(id: "welcome") + AlertHelper.showErrorSheet( + title: String(localized: "Connection Failed"), + message: error.localizedDescription, + window: nil + ) } } }