Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions TableProMobile/TableProMobile/Views/ConnectedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ struct ConnectedView: View {
.pickerStyle(.segmented)
.padding(.horizontal)
.padding(.vertical, 8)
.background(.bar)
}
.background {
Button("") { selectedTab = .tables }
Expand Down Expand Up @@ -187,6 +186,13 @@ struct ConnectedView: View {
queryHistory = historyStorage.load(for: connection.id)
}
}
.onAppear {
let hasDriver = appState.connectionManager.session(for: connection.id)?.driver != nil
if !hasDriver, !isConnecting {
appError = nil
Task { await connect() }
}
}
.onChange(of: scenePhase) { _, phase in
if phase == .active, session != nil {
Task { await reconnectIfNeeded() }
Expand Down Expand Up @@ -224,27 +230,23 @@ struct ConnectedView: View {
return
}

isConnecting = true
appError = nil

// Reuse existing session if still alive in ConnectionManager
if let existing = appState.connectionManager.session(for: connection.id) {
self.session = existing
do {
self.tables = try await existing.driver.fetchTables(schema: nil)
guard !Task.isCancelled else { return }
isConnecting = false
await loadDatabases()
await loadSchemas()
} catch {
// Session stale — disconnect and reconnect
self.session = nil
await appState.connectionManager.disconnect(connection.id)
await connectFresh()
return
}
isConnecting = false
return
}

isConnecting = true
appError = nil
await connectFresh()
}

Expand Down
Loading