Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion TablePro/AppDelegate+ConnectionHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ extension AppDelegate {
openNewConnectionWindow(for: connection)

Task { @MainActor in
defer { self.endFileOpenSuppression() }
do {
try await DatabaseManager.shared.connectToSession(connection)
for window in NSApp.windows where self.isWelcomeWindow(window) {
Expand Down Expand Up @@ -116,6 +117,7 @@ extension AppDelegate {
openNewConnectionWindow(for: connection)

Task { @MainActor in
defer { self.endFileOpenSuppression() }
do {
try await DatabaseManager.shared.connectToSession(connection)
for window in NSApp.windows where self.isWelcomeWindow(window) {
Expand Down Expand Up @@ -161,6 +163,7 @@ extension AppDelegate {
openNewConnectionWindow(for: connection)

Task { @MainActor in
defer { self.endFileOpenSuppression() }
do {
try await DatabaseManager.shared.connectToSession(connection)
for window in NSApp.windows where self.isWelcomeWindow(window) {
Expand Down Expand Up @@ -206,6 +209,7 @@ extension AppDelegate {
openNewConnectionWindow(for: connection)

Task { @MainActor in
defer { self.endFileOpenSuppression() }
do {
try await DatabaseManager.shared.connectToSession(connection)
for window in NSApp.windows where self.isWelcomeWindow(window) {
Expand Down Expand Up @@ -252,7 +256,7 @@ extension AppDelegate {
case .genericDatabaseFile(let url, let dbType): self.handleGenericDatabaseFile(url, type: dbType)
}
}
self.scheduleWelcomeWindowSuppression()
// Flag management is handled by endFileOpenSuppression() in each handler
}
}

Expand Down
6 changes: 3 additions & 3 deletions TablePro/AppDelegate+FileOpen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extension AppDelegate {
suppressWelcomeWindow()
Task { @MainActor in
for url in databaseURLs { self.handleDatabaseURL(url) }
self.scheduleWelcomeWindowSuppression()
// Flag management is handled by endFileOpenSuppression() in each handler
}
}

Expand All @@ -72,7 +72,7 @@ extension AppDelegate {
self.handleGenericDatabaseFile(url, type: dbType)
}
}
self.scheduleWelcomeWindowSuppression()
// Flag management is handled by endFileOpenSuppression() in each handler
}
}

Expand All @@ -87,7 +87,7 @@ extension AppDelegate {
window.close()
}
NotificationCenter.default.post(name: .openSQLFiles, object: sqlFiles)
scheduleWelcomeWindowSuppression()
endFileOpenSuppression()
} else {
queuedFileURLs.append(contentsOf: sqlFiles)
openWelcomeWindow()
Expand Down
36 changes: 21 additions & 15 deletions TablePro/AppDelegate+WindowConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,26 +190,24 @@ extension AppDelegate {

// MARK: - Welcome Window Suppression

func scheduleWelcomeWindowSuppression() {
Task { @MainActor [weak self] in
try? await Task.sleep(for: .milliseconds(200))
self?.closeWelcomeWindowIfMainExists()
try? await Task.sleep(for: .milliseconds(500))
guard let self else { return }
self.closeWelcomeWindowIfMainExists()
self.fileOpenSuppressionCount = max(0, self.fileOpenSuppressionCount - 1)
if self.fileOpenSuppressionCount == 0 {
self.isHandlingFileOpen = false
}
/// Called by connection handlers when the file-open connection attempt finishes
/// (success or failure). Decrements the suppression counter and resets the flag
/// when all outstanding file opens have completed.
func endFileOpenSuppression() {
fileOpenSuppressionCount = max(0, fileOpenSuppressionCount - 1)
if fileOpenSuppressionCount == 0 {
isHandlingFileOpen = false
}
}

private func closeWelcomeWindowIfMainExists() {
@discardableResult
private func closeWelcomeWindowIfMainExists() -> Bool {
let hasMainWindow = NSApp.windows.contains { isMainWindow($0) && $0.isVisible }
guard hasMainWindow else { return }
guard hasMainWindow else { return false }
for window in NSApp.windows where isWelcomeWindow(window) {
window.close()
}
return true
}

// MARK: - Window Notifications
Expand All @@ -219,9 +217,13 @@ extension AppDelegate {
let windowId = ObjectIdentifier(window)

if isWelcomeWindow(window) && isHandlingFileOpen {
window.close()
for mainWin in NSApp.windows where isMainWindow(mainWin) {
// Only close welcome if a main window exists to take its place;
// otherwise just hide it so the user doesn't see a flash.
if let mainWin = NSApp.windows.first(where: { isMainWindow($0) }) {
window.close()
mainWin.makeKeyAndOrderFront(nil)
} else {
window.orderOut(nil)
}
return
}
Expand All @@ -236,6 +238,10 @@ extension AppDelegate {
configuredWindows.insert(windowId)
}

if isMainWindow(window) && isHandlingFileOpen {
closeWelcomeWindowIfMainExists()
}

if isMainWindow(window) && !configuredWindows.contains(windowId) {
window.tabbingMode = .preferred
let pendingId = MainActor.assumeIsolated { WindowOpener.shared.consumePendingConnectionId() }
Expand Down
40 changes: 22 additions & 18 deletions TablePro/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ struct ContentView: View {

@ViewBuilder
private var mainContent: some View {
if let currentSession = currentSession, let rightPanelState, let sessionState {
NavigationSplitView(columnVisibility: $columnVisibility) {
// MARK: - Sidebar (Left) - Table Browser
NavigationSplitView(columnVisibility: $columnVisibility) {
// MARK: - Sidebar (Left) - Table Browser
if let currentSession = currentSession, let sessionState {
VStack(spacing: 0) {
SidebarView(
tables: sessionTablesBinding,
Expand Down Expand Up @@ -198,8 +198,13 @@ struct ContentView: View {
prompt: sidebarSearchPrompt(for: currentSession.connection.id)
)
.navigationSplitViewColumnWidth(min: 200, ideal: 250, max: 600)
} detail: {
// MARK: - Detail (Main workspace with optional right sidebar)
} else {
Color.clear
.navigationSplitViewColumnWidth(min: 200, ideal: 250, max: 600)
}
} detail: {
// MARK: - Detail (Main workspace with optional right sidebar)
if let currentSession = currentSession, let rightPanelState, let sessionState {
HStack(spacing: 0) {
MainContentView(
connection: currentSession.connection,
Expand Down Expand Up @@ -235,21 +240,20 @@ struct ContentView: View {
}
}
.animation(.easeInOut(duration: 0.2), value: rightPanelState.isPresented)
} else {
VStack(spacing: 16) {
ProgressView()
.scaleEffect(1.5)

Text("Connecting...")
.font(.headline)
.foregroundStyle(.secondary)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.navigationTitle(windowTitle)
.navigationSubtitle(currentSession.connection.name)
} else {
VStack(spacing: 16) {
ProgressView()
.scaleEffect(1.5)

Text("Connecting...")
.font(.headline)
.foregroundStyle(.secondary)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.navigationTitle("TablePro")
}
.navigationTitle(windowTitle)
.navigationSubtitle(currentSession?.connection.name ?? "")
}

// Removed: newConnectionSheet and editConnectionSheet helpers
Expand Down
Loading
Loading