in SasquatchMac/SasquatchMacSwift/AppDelegate.swift [31:130]
func applicationDidFinishLaunching(_ notification: Notification) {
// Crashes Delegate.
Crashes.delegate = self;
Crashes.userConfirmationHandler = ({ (errorReports: [ErrorReport]) in
let alert: NSAlert = NSAlert()
alert.messageText = "Sorry about that!"
alert.informativeText = "Do you want to send an anonymous crash report so we can fix the issue?"
alert.addButton(withTitle: "Always send")
alert.addButton(withTitle: "Send")
alert.addButton(withTitle: "Don't send")
alert.alertStyle = .warning
switch (alert.runModal()) {
case .alertFirstButtonReturn:
Crashes.notify(with: .always)
break;
case .alertSecondButtonReturn:
Crashes.notify(with: .send)
break;
case .alertThirdButtonReturn:
Crashes.notify(with: .dontSend)
break;
default:
break;
}
return true
})
// Enable catching uncaught exceptions thrown on the main thread.
UserDefaults.standard.register(defaults: ["NSApplicationCrashOnExceptions": true])
// Set loglevel to verbose.
AppCenter.logLevel = .verbose
// Set custom log URL.
let logUrl = UserDefaults.standard.string(forKey: kMSLogUrl)
if logUrl != nil {
AppCenter.logUrl = logUrl
}
// Set manual session tracker before App Center start.
if UserDefaults.standard.bool(forKey: kMSManualSessionTracker) {
Analytics.enableManualSessionTracker()
}
// Set location manager.
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyKilometer
// Set max storage size.
let storageMaxSize = UserDefaults.standard.object(forKey: kMSStorageMaxSizeKey) as? Int
if storageMaxSize != nil {
AppCenter.setMaxStorageSize(storageMaxSize!, completionHandler: { success in
DispatchQueue.main.async {
if success {
let realSize = Int64(ceil(Double(storageMaxSize!) / Double(kMSStoragePageSize))) * Int64(kMSStoragePageSize)
UserDefaults.standard.set(realSize, forKey: kMSStorageMaxSizeKey)
} else {
// Remove invalid value.
UserDefaults.standard.removeObject(forKey: kMSStorageMaxSizeKey)
}
}
})
}
// Start AppCenter.
let services = [Analytics.self, Crashes.self]
let startTarget = StartupMode(rawValue: UserDefaults.standard.integer(forKey: kMSStartTargetKey))!
let appSecret = UserDefaults.standard.string(forKey: kMSAppSecret) ?? kMSSwiftAppSecret
switch startTarget {
case .appCenter:
AppCenter.start(withAppSecret:appSecret, services: services)
break
case .oneCollector:
AppCenter.start(withAppSecret: "target=\(kMSSwiftTargetToken)", services: services)
break
case .both:
AppCenter.start(withAppSecret: "appsecret=\(appSecret);target=\(kMSSwiftTargetToken)", services: services)
break
case .none:
AppCenter.start(services: services)
break
case .skip:
break
}
// Set user id.
let userId = UserDefaults.standard.string(forKey: kMSUserIdKey)
if userId != nil {
AppCenter.userId = userId
}
AppCenterProvider.shared().appCenter = AppCenterDelegateSwift()
initUI()
overrideCountryCode()
}