diff --git a/Whisky/AppDelegate.swift b/Whisky/AppDelegate.swift index 25524cc3..0d5366ae 100644 --- a/Whisky/AppDelegate.swift +++ b/Whisky/AppDelegate.swift @@ -22,6 +22,16 @@ import SwiftUI class AppDelegate: NSObject, NSApplicationDelegate { @AppStorage("hasShownMoveToApplicationsAlert") private var hasShownMoveToApplicationsAlert = false + func application(_ application: NSApplication, open urls: [URL]) { + // Test if automatic window tabbing is enabled + // as it is disabled when ContentView appears + if NSWindow.allowsAutomaticWindowTabbing, let url = urls.first { + // Reopen the file after Whisky has been opened + // so that the `onOpenURL` handler is actually called + NSWorkspace.shared.open(url) + } + } + func applicationDidFinishLaunching(_ notification: Notification) { if !hasShownMoveToApplicationsAlert && !AppDelegate.insideAppsFolder { DispatchQueue.main.asyncAfter(deadline: .now()) { diff --git a/Whisky/Views/FileOpenView.swift b/Whisky/Views/FileOpenView.swift index 562b7ac0..2e87af28 100644 --- a/Whisky/Views/FileOpenView.swift +++ b/Whisky/Views/FileOpenView.swift @@ -57,12 +57,14 @@ struct FileOpenView: View { } .frame(minWidth: 400, minHeight: 115) .onAppear { - selection = bottles.first(where: { $0.url == currentBottle })?.url ?? bottles[0].url - if bottles.count <= 1 { // If the user only has one bottle // there's nothing for them to select run() + } else if bottles.count > 0 { + // Makes sure there are more than 0 bottles. + // Otherwise, it will crash on the nil cascade + selection = bottles.first(where: { $0.url == currentBottle })?.url ?? bottles[0].url } } }