Tusker/Tusker/AppDelegate.swift

88 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
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
2018-10-20 16:03:18 +00:00
window = UIWindow(frame: UIScreen.main.bounds)
2018-08-16 22:55:40 +00:00
2018-08-20 21:23:35 +00:00
if LocalData.shared.onboardingComplete {
2018-10-20 16:03:18 +00:00
showAppUI()
2018-08-19 20:14:04 +00:00
} else {
2018-10-20 16:03:18 +00:00
showOnboardingUI()
2018-08-19 20:14:04 +00:00
}
2018-08-16 22:55:40 +00:00
2018-10-20 16:03:18 +00:00
window!.makeKeyAndVisible()
2018-08-16 02:27:48 +00:00
return true
}
2018-08-19 20:14:04 +00:00
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if url.host == "x-callback-url" {
return XCBManager.handle(url: url)
}
return false
}
2018-10-20 14:54:59 +00:00
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
return userActivity.handleResume()
}
2018-08-16 02:27:48 +00:00
func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}
func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
2018-08-28 23:16:17 +00:00
Preferences.save()
2018-10-23 02:09:11 +00:00
DraftsManager.save()
2018-08-16 02:27:48 +00:00
}
func applicationWillEnterForeground(_ application: UIApplication) {
// Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
func applicationWillTerminate(_ application: UIApplication) {
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
2018-10-20 16:03:18 +00:00
func showAppUI() {
MastodonController.createClient()
MastodonController.getOwnAccount()
MastodonController.getOwnInstance()
let tabBarController = MainTabBarViewController()
window!.rootViewController = tabBarController
2018-10-20 16:03:18 +00:00
}
func showOnboardingUI() {
let onboarding = OnboardingViewController()
onboarding.delegate = self
window!.rootViewController = onboarding
}
2018-08-16 02:27:48 +00:00
2018-08-19 20:14:04 +00:00
}
2018-08-16 02:27:48 +00:00
2018-08-19 20:14:04 +00:00
extension AppDelegate: OnboardingViewControllerDelegate {
func didFinishOnboarding() {
2018-08-20 21:23:35 +00:00
LocalData.shared.onboardingComplete = true
2018-10-20 16:03:18 +00:00
showAppUI()
2018-08-19 20:14:04 +00:00
}
2018-08-16 02:27:48 +00:00
}