Skip to content

Commit

Permalink
Fix opening through document type (#753)
Browse files Browse the repository at this point in the history
* fix: open document type while Whisky is closed

* fix: crash with zero bottles
  • Loading branch information
TheMoonThatRises authored Dec 31, 2023
1 parent 07328aa commit 199871b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Whisky/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
6 changes: 4 additions & 2 deletions Whisky/Views/FileOpenView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down

0 comments on commit 199871b

Please sign in to comment.