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
|
2022-05-11 02:57:46 +00:00
|
|
|
import CoreData
|
2022-05-13 21:10:18 +00:00
|
|
|
import OSLog
|
2022-10-30 21:10:58 +00:00
|
|
|
import Sentry
|
2022-05-13 21:10:18 +00:00
|
|
|
|
|
|
|
let stateRestorationLogger = Logger(subsystem: Bundle.main.bundleIdentifier!, category: "StateRestoration")
|
2018-08-16 02:27:48 +00:00
|
|
|
|
|
|
|
@UIApplicationMain
|
|
|
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
2020-06-21 03:11:35 +00:00
|
|
|
|
2018-08-16 02:27:48 +00:00
|
|
|
|
|
|
|
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
|
2022-10-30 21:10:58 +00:00
|
|
|
configureSentry()
|
2022-11-02 00:49:07 +00:00
|
|
|
swizzleStatusBar()
|
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
|
|
|
|
2022-10-30 21:10:58 +00:00
|
|
|
private func configureSentry() {
|
|
|
|
guard let dsn = Bundle.main.object(forInfoDictionaryKey: "SentryDSN") as? String,
|
|
|
|
!dsn.isEmpty else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
SentrySDK.start { options in
|
|
|
|
#if DEBUG
|
|
|
|
options.debug = true
|
|
|
|
options.environment = "dev"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// the '//' in the full url can't be escaped, so we have to add the scheme back
|
|
|
|
options.dsn = "https://\(dsn)"
|
|
|
|
|
|
|
|
options.enableSwizzling = false
|
2022-10-31 18:23:28 +00:00
|
|
|
// required to support releases/release health
|
|
|
|
options.enableAutoSessionTracking = true
|
2022-10-30 21:10:58 +00:00
|
|
|
options.enableOutOfMemoryTracking = false
|
|
|
|
options.enableAutoPerformanceTracking = false
|
|
|
|
options.enableNetworkTracking = false
|
|
|
|
options.enableAppHangTracking = false
|
|
|
|
options.enableCoreDataTracking = false
|
2022-10-31 18:23:28 +00:00
|
|
|
// we don't care about events like battery, keyboard show/hide
|
|
|
|
options.enableAutoBreadcrumbTracking = false
|
2022-10-30 22:17:53 +00:00
|
|
|
|
|
|
|
options.beforeSend = { event in
|
2022-10-31 18:23:28 +00:00
|
|
|
// just no, why would anyone need this information
|
|
|
|
event.context?.removeValue(forKey: "culture")
|
|
|
|
return Preferences.shared.reportErrorsAutomatically ? event : nil
|
2022-10-30 22:17:53 +00:00
|
|
|
}
|
2020-06-21 03:11:35 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-14 16:10:20 +00:00
|
|
|
|
|
|
|
override func buildMenu(with builder: UIMenuBuilder) {
|
|
|
|
|
|
|
|
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"
|
2022-05-13 21:10:18 +00:00
|
|
|
|
2020-12-14 03:37:37 +00:00
|
|
|
case .showConversation,
|
|
|
|
.showTimeline,
|
|
|
|
.checkNotifications,
|
|
|
|
.search,
|
|
|
|
.bookmarks,
|
|
|
|
.myProfile,
|
|
|
|
.showProfile:
|
2022-05-13 21:10:18 +00:00
|
|
|
if activity.displaysAuxiliaryScene {
|
|
|
|
stateRestorationLogger.info("Using auxiliary scene for \(type.rawValue, privacy: .public)")
|
|
|
|
return "auxiliary"
|
|
|
|
} else {
|
|
|
|
return "main-scene"
|
|
|
|
}
|
2020-12-14 03:37:37 +00:00
|
|
|
|
|
|
|
case .newPost:
|
|
|
|
return "compose"
|
|
|
|
}
|
|
|
|
}
|
2022-05-15 14:34:24 +00:00
|
|
|
|
|
|
|
@objc func closeWindow() {
|
|
|
|
guard let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) else {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
UIApplication.shared.requestSceneSessionDestruction(scene.session, options: nil)
|
|
|
|
}
|
2022-11-02 00:49:07 +00:00
|
|
|
|
|
|
|
private func swizzleStatusBar() {
|
|
|
|
let selector = Selector(("handleTapAction:"))
|
|
|
|
var originalIMP: IMP?
|
|
|
|
let imp = imp_implementationWithBlock({ (self: UIStatusBarManager, sender: AnyObject) in
|
|
|
|
let original = unsafeBitCast(originalIMP!, to: (@convention(c) (UIStatusBarManager, Selector, AnyObject) -> Void).self)
|
|
|
|
guard let windowScene = self.perform(Selector(("windowScene"))).takeUnretainedValue() as? UIWindowScene,
|
|
|
|
let xPosition = sender.value(forKey: "xPosition") as? CGFloat,
|
|
|
|
let delegate = windowScene.delegate as? TuskerSceneDelegate else {
|
|
|
|
original(self, selector, sender)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
switch delegate.handleStatusBarTapped(xPosition: xPosition) {
|
|
|
|
case .stop:
|
|
|
|
return
|
|
|
|
case .continue:
|
|
|
|
original(self, selector, sender)
|
|
|
|
}
|
|
|
|
} as @convention(block) (UIStatusBarManager, AnyObject) -> Void)
|
|
|
|
originalIMP = class_replaceMethod(UIStatusBarManager.self, selector, imp, "v@:@")
|
|
|
|
if originalIMP == nil {
|
|
|
|
Logging.general.error("Unable to swizzle status bar manager")
|
|
|
|
}
|
|
|
|
}
|
2018-08-16 02:27:48 +00:00
|
|
|
}
|