Tusker/Tusker/AppDelegate.swift

103 lines
3.4 KiB
Swift
Raw Normal View History

2018-08-16 02:27:48 +00:00
//
// AppDelegate.swift
// Tusker
//
// Created by Shadowfacts on 8/15/18.
// Copyright © 2018 Shadowfacts. All rights reserved.
//
import UIKit
2020-06-21 03:11:35 +00:00
import CrashReporter
import CoreData
2018-08-16 02:27:48 +00:00
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
2020-06-21 03:11:35 +00:00
static private(set) var crashReporter: PLCrashReporter!
static var pendingCrashReport: PLCrashReport?
2018-08-16 02:27:48 +00:00
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
2020-06-21 03:11:35 +00:00
#if !DEBUG
setupCrashReporter()
#endif
2019-09-19 20:55:15 +00:00
AppShortcutItem.createItems(for: application)
DispatchQueue.global(qos: .userInitiated).async {
AudioSessionHelper.disable()
AudioSessionHelper.setDefault()
}
if let oldSavedData = SavedDataManager.load() {
do {
for account in oldSavedData.accountIDs {
guard let account = LocalData.shared.getAccount(id: account) else {
continue
}
let controller = MastodonController.getForAccount(account)
try oldSavedData.migrateToCoreData(accountID: account.id, context: controller.persistentContainer.viewContext)
if controller.persistentContainer.viewContext.hasChanges {
try controller.persistentContainer.viewContext.save()
}
}
try SavedDataManager.destroy()
} catch {
// no-op
}
}
2018-08-16 02:27:48 +00:00
return true
}
2020-06-21 03:11:35 +00:00
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(),
let report = try? PLCrashReport(data: data) {
2020-06-21 03:11:35 +00:00
AppDelegate.crashReporter.purgePendingCrashReport()
AppDelegate.pendingCrashReport = report
}
AppDelegate.crashReporter.enable()
}
2020-11-14 16:10:20 +00:00
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"
}
}
2018-08-16 02:27:48 +00:00
}