Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix opening through document type #753

Merged
merged 2 commits into from
Dec 31, 2023
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
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