Tusker/Tusker/AppDelegate.swift

85 lines
2.6 KiB
Swift

//
// AppDelegate.swift
// Tusker
//
// Created by Shadowfacts on 8/15/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import UIKit
import CrashReporter
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
static private(set) var crashReporter: PLCrashReporter!
static var pendingCrashReport: PLCrashReport?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
#if !DEBUG
setupCrashReporter()
#endif
AppShortcutItem.createItems(for: application)
DispatchQueue.global(qos: .userInitiated).async {
AudioSessionHelper.disable()
AudioSessionHelper.setDefault()
}
return true
}
private func setupCrashReporter() {
let config = PLCrashReporterConfig(signalHandlerType: .BSD, symbolicationStrategy: .all)
AppDelegate.crashReporter = PLCrashReporter(configuration: config)
if AppDelegate.crashReporter.hasPendingCrashReport() {
let data = try! AppDelegate.crashReporter.loadPendingCrashReportDataAndReturnError()
AppDelegate.crashReporter.purgePendingCrashReport()
let report = try! PLCrashReport(data: data)
AppDelegate.pendingCrashReport = report
}
AppDelegate.crashReporter.enable()
}
override func buildMenu(with builder: UIMenuBuilder) {
super.buildMenu(with: builder)
if builder.system == .main {
MenuController.buildMainMenu(builder: builder)
}
}
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
let name = getSceneNameForActivity(options.userActivities.first)
return UISceneConfiguration(name: name, sessionRole: connectingSceneSession.role)
}
private func getSceneNameForActivity(_ activity: NSUserActivity?) -> String {
guard let activity = activity,
let type = UserActivityType(rawValue: activity.activityType) else {
return "main-scene"
}
switch type {
case .mainScene:
return "main-scene"
case .showConversation,
.showTimeline,
.checkNotifications,
.search,
.bookmarks,
.myProfile,
.showProfile:
return "auxiliary"
case .newPost:
return "compose"
}
}
}