Skip to content

Commit

Permalink
fix: crash with zero bottles
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMoonThatRises committed Dec 31, 2023
1 parent 2d1cc8d commit 8c6a5a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Whisky/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {

func application(_ application: NSApplication, open urls: [URL]) {
// Test if automatic window tabbing is enabled
// as it is disabled when ContentView appears.
// Prevents crashing
// 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
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 8c6a5a8

Please sign in to comment.