fix crash when opening files via Finder before appState init
This commit is contained in:
parent
df35ed406e
commit
9c8589de03
|
|
@ -41,11 +41,22 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
self, selector: #selector(settingsDidChange),
|
self, selector: #selector(settingsDidChange),
|
||||||
name: .settingsChanged, object: nil
|
name: .settingsChanged, object: nil
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if let url = pendingOpenURLs.first {
|
||||||
|
pendingOpenURLs = []
|
||||||
|
appState.loadNoteFromFile(url)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var pendingOpenURLs: [URL] = []
|
||||||
|
|
||||||
func application(_ application: NSApplication, open urls: [URL]) {
|
func application(_ application: NSApplication, open urls: [URL]) {
|
||||||
guard let url = urls.first else { return }
|
guard let url = urls.first else { return }
|
||||||
appState.loadNoteFromFile(url)
|
if appState != nil {
|
||||||
|
appState.loadNoteFromFile(url)
|
||||||
|
} else {
|
||||||
|
pendingOpenURLs = [url]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue