diff --git a/src/AppDelegate.swift b/src/AppDelegate.swift index ae7cd4c..c37a226 100644 --- a/src/AppDelegate.swift +++ b/src/AppDelegate.swift @@ -41,11 +41,22 @@ class AppDelegate: NSObject, NSApplicationDelegate { self, selector: #selector(settingsDidChange), name: .settingsChanged, object: nil ) + + if let url = pendingOpenURLs.first { + pendingOpenURLs = [] + appState.loadNoteFromFile(url) + } } + private var pendingOpenURLs: [URL] = [] + func application(_ application: NSApplication, open urls: [URL]) { guard let url = urls.first else { return } - appState.loadNoteFromFile(url) + if appState != nil { + appState.loadNoteFromFile(url) + } else { + pendingOpenURLs = [url] + } } func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {