Skip to content

Commit 826b4d7

Browse files
authored
fix: clean up session and UI when driver plugin is missing on connect (#297)
* fix: clean up session and UI when driver plugin is missing on connect * fix: close stuck main window on connectAfterInstall failure
1 parent 3db8b99 commit 826b4d7

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

TablePro/Core/Database/DatabaseManager.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,20 @@ final class DatabaseManager {
114114
}
115115

116116
// Create appropriate driver with effective connection
117-
let driver = try DatabaseDriverFactory.createDriver(for: effectiveConnection)
117+
let driver: DatabaseDriver
118+
do {
119+
driver = try DatabaseDriverFactory.createDriver(for: effectiveConnection)
120+
} catch {
121+
// Close tunnel if SSH was established
122+
if connection.sshConfig.enabled {
123+
Task {
124+
try? await SSHTunnelManager.shared.closeTunnel(connectionId: connection.id)
125+
}
126+
}
127+
activeSessions.removeValue(forKey: connection.id)
128+
currentSessionId = nil
129+
throw error
130+
}
118131

119132
do {
120133
try await driver.connect()

TablePro/Views/Connection/ConnectionFormView.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,13 @@ struct ConnectionFormView: View {
10141014
} else {
10151015
Self.logger.error(
10161016
"Failed to connect: \(error.localizedDescription, privacy: .public)")
1017+
NSApplication.shared.closeWindows(withId: "main")
1018+
openWindow(id: "welcome")
1019+
AlertHelper.showErrorSheet(
1020+
title: String(localized: "Connection Failed"),
1021+
message: error.localizedDescription,
1022+
window: nil
1023+
)
10171024
}
10181025
}
10191026
}
@@ -1035,6 +1042,13 @@ struct ConnectionFormView: View {
10351042
} catch {
10361043
Self.logger.error(
10371044
"Failed to connect after plugin install: \(error.localizedDescription, privacy: .public)")
1045+
NSApplication.shared.closeWindows(withId: "main")
1046+
openWindow(id: "welcome")
1047+
AlertHelper.showErrorSheet(
1048+
title: String(localized: "Connection Failed"),
1049+
message: error.localizedDescription,
1050+
window: nil
1051+
)
10381052
}
10391053
}
10401054
}

0 commit comments

Comments
 (0)