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
|
2022-05-11 02:57:46 +00:00
|
|
|
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
|
2020-06-21 19:38:51 +00:00
|
|
|
|
2019-09-19 20:55:15 +00:00
|
|
|
AppShortcutItem.createItems(for: application)
|
2020-06-21 19:38:51 +00:00
|
|
|
|
|
|
|
DispatchQueue.global(qos: .userInitiated).async {
|
|
|
|
AudioSessionHelper.disable()
|
|
|
|
AudioSessionHelper.setDefault()
|
|
|
|
}
|
2022-05-11 02:57:46 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
2020-06-21 19:38:51 +00:00
|
|
|
|
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)
|
|
|
|
|
2022-04-08 22:45:09 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
2020-12-14 03:37:37 +00:00
|
|
|
|
|
|
|
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 {
|
2021-06-06 18:55:04 +00:00
|
|
|
case .mainScene:
|
|
|
|
return "main-scene"
|
|
|
|
|
2020-12-14 03:37:37 +00:00
|
|
|
case .showConversation,
|
|
|
|
.showTimeline,
|
|
|
|
.checkNotifications,
|
|
|
|
.search,
|
|
|
|
.bookmarks,
|
|
|
|
.myProfile,
|
|
|
|
.showProfile:
|
|
|
|
return "auxiliary"
|
|
|
|
|
|
|
|
case .newPost:
|
|
|
|
return "compose"
|
|
|
|
}
|
|
|
|
}
|
2018-08-16 02:27:48 +00:00
|
|
|
}
|