Skip to content

Commit 789b292

Browse files
committed
fix: replace guard-return with if-block so SQL handler doesn't block SQLite opens
1 parent 4b75de4 commit 789b292

1 file changed

Lines changed: 30 additions & 27 deletions

File tree

TablePro/AppDelegate.swift

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class AppDelegate: NSObject, NSApplicationDelegate {
6060
"mssql", "sqlserver", "oracle"
6161
]
6262

63+
private static let sqliteFileExtensions: Set<String> = [
64+
"sqlite", "sqlite3", "db3", "s3db", "sl3", "sqlitedb"
65+
]
66+
6367
func applicationDockMenu(_ sender: NSApplication) -> NSMenu? {
6468
let menu = NSMenu()
6569

@@ -200,8 +204,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
200204
}
201205

202206
// Handle SQLite database files (double-click from Finder)
203-
let sqliteExtensions: Set<String> = ["sqlite", "sqlite3", "db3", "s3db", "sl3", "sqlitedb"]
204-
let sqliteFileURLs = urls.filter { sqliteExtensions.contains($0.pathExtension.lowercased()) }
207+
let sqliteFileURLs = urls.filter { Self.sqliteFileExtensions.contains($0.pathExtension.lowercased()) }
205208
if !sqliteFileURLs.isEmpty {
206209
isHandlingFileOpen = true
207210
fileOpenSuppressionCount += 1
@@ -217,34 +220,34 @@ class AppDelegate: NSObject, NSApplicationDelegate {
217220
}
218221
}
219222

220-
// Handle SQL files (existing logic unchanged)
223+
// Handle SQL files
221224
let sqlURLs = urls.filter { $0.pathExtension.lowercased() == "sql" }
222-
guard !sqlURLs.isEmpty else { return }
223-
224-
if DatabaseManager.shared.currentSession != nil {
225-
// Suppress any welcome window that SwiftUI may create as a
226-
// side-effect of the app being activated by the file-open event.
227-
isHandlingFileOpen = true
228-
fileOpenSuppressionCount += 1
225+
if !sqlURLs.isEmpty {
226+
if DatabaseManager.shared.currentSession != nil {
227+
// Suppress any welcome window that SwiftUI may create as a
228+
// side-effect of the app being activated by the file-open event.
229+
isHandlingFileOpen = true
230+
fileOpenSuppressionCount += 1
231+
232+
// Already connected — bring main window to front and open files
233+
for window in NSApp.windows where isMainWindow(window) {
234+
window.makeKeyAndOrderFront(nil)
235+
}
236+
// Close welcome window if it's already open
237+
for window in NSApp.windows where isWelcomeWindow(window) {
238+
window.close()
239+
}
240+
NotificationCenter.default.post(name: .openSQLFiles, object: sqlURLs)
229241

230-
// Already connected — bring main window to front and open files
231-
for window in NSApp.windows where isMainWindow(window) {
232-
window.makeKeyAndOrderFront(nil)
233-
}
234-
// Close welcome window if it's already open
235-
for window in NSApp.windows where isWelcomeWindow(window) {
236-
window.close()
242+
// SwiftUI may asynchronously create a welcome window after this
243+
// method returns (scene restoration on activation). Schedule
244+
// multiple cleanup passes so we catch windows that appear late.
245+
scheduleWelcomeWindowSuppression()
246+
} else {
247+
// Not connected — queue and show welcome window
248+
queuedFileURLs.append(contentsOf: sqlURLs)
249+
openWelcomeWindow()
237250
}
238-
NotificationCenter.default.post(name: .openSQLFiles, object: sqlURLs)
239-
240-
// SwiftUI may asynchronously create a welcome window after this
241-
// method returns (scene restoration on activation). Schedule
242-
// multiple cleanup passes so we catch windows that appear late.
243-
scheduleWelcomeWindowSuppression()
244-
} else {
245-
// Not connected — queue and show welcome window
246-
queuedFileURLs.append(contentsOf: sqlURLs)
247-
openWelcomeWindow()
248251
}
249252
}
250253

0 commit comments

Comments
 (0)