2019-06-28 10:28:02 -05:00
|
|
|
//
|
|
|
|
// AppDelegate.swift
|
|
|
|
// NetNewsWire
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 6/28/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2019-10-03 09:53:21 -05:00
|
|
|
import UserNotifications
|
2019-09-02 15:45:09 -05:00
|
|
|
import Account
|
2019-06-28 10:28:02 -05:00
|
|
|
|
2019-06-29 13:35:12 -05:00
|
|
|
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|
|
|
|
2019-06-28 10:28:02 -05:00
|
|
|
var window: UIWindow?
|
2019-09-01 12:43:07 -05:00
|
|
|
var coordinator = SceneCoordinator()
|
2019-07-19 11:59:08 -05:00
|
|
|
|
2019-06-28 10:28:02 -05:00
|
|
|
// UIWindowScene delegate
|
|
|
|
|
|
|
|
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
2019-09-06 10:29:00 -05:00
|
|
|
|
2019-07-26 09:58:46 -05:00
|
|
|
window = UIWindow(windowScene: scene as! UIWindowScene)
|
2019-09-18 02:49:57 -05:00
|
|
|
window!.tintColor = AppAssets.primaryAccentColor
|
2020-03-15 04:25:25 -05:00
|
|
|
updateUserInterfaceStyle()
|
2019-09-09 16:59:24 -05:00
|
|
|
window!.rootViewController = coordinator.start(for: window!.frame.size)
|
2019-06-28 10:28:02 -05:00
|
|
|
|
2019-11-26 20:23:12 -06:00
|
|
|
coordinator.restoreWindowState(session.stateRestorationActivity)
|
2019-11-26 16:33:11 -06:00
|
|
|
|
2020-03-15 04:25:25 -05:00
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(userDefaultsDidChange), name: UserDefaults.didChangeNotification, object: nil)
|
|
|
|
|
2019-09-01 16:54:07 -05:00
|
|
|
if let shortcutItem = connectionOptions.shortcutItem {
|
2019-09-06 10:29:00 -05:00
|
|
|
window!.makeKeyAndVisible()
|
2019-09-01 16:54:07 -05:00
|
|
|
handleShortcutItem(shortcutItem)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-03 09:53:21 -05:00
|
|
|
if let notificationResponse = connectionOptions.notificationResponse {
|
|
|
|
window!.makeKeyAndVisible()
|
2020-02-17 17:40:40 -08:00
|
|
|
coordinator.handle(notificationResponse)
|
2019-10-03 09:53:21 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-08-25 17:49:09 -05:00
|
|
|
if let userActivity = connectionOptions.userActivities.first ?? session.stateRestorationActivity {
|
2020-02-17 17:40:40 -08:00
|
|
|
coordinator.handle(userActivity)
|
2019-08-25 17:49:09 -05:00
|
|
|
}
|
2019-09-06 10:29:00 -05:00
|
|
|
|
|
|
|
window!.makeKeyAndVisible()
|
2019-06-28 10:28:02 -05:00
|
|
|
}
|
|
|
|
|
2019-09-01 16:54:07 -05:00
|
|
|
func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
|
2020-01-10 16:32:06 -07:00
|
|
|
appDelegate.resumeDatabaseProcessingIfNecessary()
|
2019-09-01 16:54:07 -05:00
|
|
|
handleShortcutItem(shortcutItem)
|
|
|
|
completionHandler(true)
|
|
|
|
}
|
|
|
|
|
2019-08-24 19:31:29 -05:00
|
|
|
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
|
2020-01-10 16:32:06 -07:00
|
|
|
appDelegate.resumeDatabaseProcessingIfNecessary()
|
2020-02-17 17:40:40 -08:00
|
|
|
coordinator.handle(userActivity)
|
2019-08-24 19:31:29 -05:00
|
|
|
}
|
|
|
|
|
2019-06-28 10:28:02 -05:00
|
|
|
func sceneDidEnterBackground(_ scene: UIScene) {
|
2019-10-20 02:28:00 -05:00
|
|
|
ArticleStringFormatter.emptyCaches()
|
2019-06-28 10:28:02 -05:00
|
|
|
appDelegate.prepareAccountsForBackground()
|
|
|
|
}
|
|
|
|
|
|
|
|
func sceneWillEnterForeground(_ scene: UIScene) {
|
2020-01-10 16:32:06 -07:00
|
|
|
appDelegate.resumeDatabaseProcessingIfNecessary()
|
2019-06-28 10:28:02 -05:00
|
|
|
appDelegate.prepareAccountsForForeground()
|
2020-04-28 17:16:34 -05:00
|
|
|
coordinator.configurePanelMode(for: window!.frame.size)
|
|
|
|
coordinator.resetFocus()
|
2019-06-28 10:28:02 -05:00
|
|
|
}
|
|
|
|
|
2019-08-31 19:30:21 -05:00
|
|
|
func stateRestorationActivity(for scene: UIScene) -> NSUserActivity? {
|
|
|
|
return coordinator.stateRestorationActivity
|
|
|
|
}
|
2019-10-03 09:53:21 -05:00
|
|
|
|
|
|
|
// API
|
|
|
|
|
|
|
|
func handle(_ response: UNNotificationResponse) {
|
2020-01-10 16:32:06 -07:00
|
|
|
appDelegate.resumeDatabaseProcessingIfNecessary()
|
2020-02-17 17:40:40 -08:00
|
|
|
coordinator.handle(response)
|
2019-10-03 09:53:21 -05:00
|
|
|
}
|
2019-06-28 10:28:02 -05:00
|
|
|
|
2019-12-02 14:14:35 -06:00
|
|
|
func suspend() {
|
|
|
|
coordinator.suspend()
|
|
|
|
}
|
|
|
|
|
2020-03-24 16:00:01 -05:00
|
|
|
func cleanUp(conditional: Bool) {
|
|
|
|
coordinator.cleanUp(conditional: conditional)
|
2020-03-11 14:47:00 -06:00
|
|
|
}
|
|
|
|
|
2019-06-28 10:28:02 -05:00
|
|
|
}
|
2019-09-01 16:54:07 -05:00
|
|
|
|
|
|
|
private extension SceneDelegate {
|
|
|
|
|
|
|
|
func handleShortcutItem(_ shortcutItem: UIApplicationShortcutItem) {
|
|
|
|
switch shortcutItem.type {
|
|
|
|
case "com.ranchero.NetNewsWire.FirstUnread":
|
|
|
|
coordinator.selectFirstUnreadInAllUnread()
|
2019-09-01 17:41:46 -05:00
|
|
|
case "com.ranchero.NetNewsWire.ShowSearch":
|
|
|
|
coordinator.showSearch()
|
2019-09-02 15:14:26 -05:00
|
|
|
case "com.ranchero.NetNewsWire.ShowAdd":
|
2020-08-11 16:27:42 -05:00
|
|
|
coordinator.showAddWebFeed()
|
2019-09-01 16:54:07 -05:00
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-15 04:25:25 -05:00
|
|
|
@objc func userDefaultsDidChange() {
|
|
|
|
updateUserInterfaceStyle()
|
|
|
|
}
|
|
|
|
|
|
|
|
func updateUserInterfaceStyle() {
|
2020-07-27 19:35:41 -05:00
|
|
|
DispatchQueue.main.async {
|
|
|
|
switch AppDefaults.userInterfaceColorPalette {
|
|
|
|
case .automatic:
|
|
|
|
self.window!.overrideUserInterfaceStyle = .unspecified
|
|
|
|
case .light:
|
|
|
|
self.window!.overrideUserInterfaceStyle = .light
|
|
|
|
case .dark:
|
|
|
|
self.window!.overrideUserInterfaceStyle = .dark
|
|
|
|
}
|
2020-03-15 04:25:25 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-01 16:54:07 -05:00
|
|
|
}
|