Skip to content

Commit

Permalink
fix: rare crash at launch if the app previously crashed
Browse files Browse the repository at this point in the history
  • Loading branch information
lwouis committed Aug 4, 2020
1 parent 6505ca5 commit 6444732
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/logic/AppCenterCrashes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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 {
Expand Down

0 comments on commit 6444732

Please sign in to comment.