From 9c8589de03a443aa17c14543d57b62e3f3a956df Mon Sep 17 00:00:00 2001 From: jess Date: Mon, 6 Apr 2026 14:30:36 -0700 Subject: [PATCH] fix crash when opening files via Finder before appState init --- src/AppDelegate.swift | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 {