From 6444732bc5a89b9c00ebbc56acd20f3743b866db Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Tue, 4 Aug 2020 03:35:48 +0900 Subject: [PATCH] fix: rare crash at launch if the app previously crashed --- src/logic/AppCenterCrashes.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/logic/AppCenterCrashes.swift b/src/logic/AppCenterCrashes.swift index 6970ee13..f2a93525 100644 --- a/src/logic/AppCenterCrashes.swift +++ b/src/logic/AppCenterCrashes.swift @@ -12,9 +12,8 @@ class AppCenterCrash: NSObject, MSCrashesDelegate { // MSAppCenter.setLogLevel(MSLogLevel.none) MSAppCenter.start(AppCenterCrash.secret, withServices: [MSCrashes.self]) MSCrashes.setDelegate(self) - // when the app starts, this code can execute before defaults are set; we pre-set this default in case - defaults.register(defaults: ["crashPolicy": "1"]) MSCrashes.setUserConfirmationHandler({ (errorReports: [MSErrorReport]) in + self.initNecessaryFacilities() if Preferences.crashPolicy == .ask { App.app.activate(ignoringOtherApps: true) let alert = NSAlert() @@ -40,6 +39,16 @@ class AppCenterCrash: NSObject, MSCrashesDelegate { }) } + // at launch, the crash report handler can be called before some things are not yet ready; we ensure they are + func initNecessaryFacilities() { + if defaults.string(forKey: "crashPolicy") == nil { + defaults.register(defaults: ["crashPolicy": "1"]) + } + if BackgroundWork.crashReportsQueue == nil { + BackgroundWork.crashReportsQueue = DispatchQueue.globalConcurrent("crashReportsQueue", .utility) + } + } + func crashButtonIdToUpdate(_ userChoice: NSApplication.ModalResponse, _ checkbox: NSButton) -> Int { if userChoice == .alertFirstButtonReturn { if checkbox.state == .on {