2019-06-28 17:28:02 +02:00
|
|
|
//
|
|
|
|
// AppDelegate.swift
|
|
|
|
// NetNewsWire
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 6/28/19.
|
|
|
|
// Copyright © 2019 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
2019-10-03 16:53:21 +02:00
|
|
|
import UserNotifications
|
2019-09-02 22:45:09 +02:00
|
|
|
import Account
|
2019-06-28 17:28:02 +02:00
|
|
|
|
2019-06-29 20:35:12 +02:00
|
|
|
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
|
|
|
|
2019-06-28 17:28:02 +02:00
|
|
|
var window: UIWindow?
|
2019-09-01 19:43:07 +02:00
|
|
|
var coordinator = SceneCoordinator()
|
2019-07-19 18:59:08 +02:00
|
|
|
|
2019-06-28 17:28:02 +02:00
|
|
|
// UIWindowScene delegate
|
|
|
|
|
|
|
|
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
|
2019-09-06 17:29:00 +02:00
|
|
|
|
2019-07-26 16:58:46 +02:00
|
|
|
window = UIWindow(windowScene: scene as! UIWindowScene)
|
2019-09-18 09:49:57 +02:00
|
|
|
window!.tintColor = AppAssets.primaryAccentColor
|
2019-09-09 23:59:24 +02:00
|
|
|
window!.rootViewController = coordinator.start(for: window!.frame.size)
|
2019-06-28 17:28:02 +02:00
|
|
|
|
2019-11-27 03:23:12 +01:00
|
|
|
coordinator.restoreWindowState(session.stateRestorationActivity)
|
2019-11-26 23:33:11 +01:00
|
|
|
|
2019-09-01 23:54:07 +02:00
|
|
|
if let shortcutItem = connectionOptions.shortcutItem {
|
2019-09-06 17:29:00 +02:00
|
|
|
window!.makeKeyAndVisible()
|
2019-09-01 23:54:07 +02:00
|
|
|
handleShortcutItem(shortcutItem)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-10-03 16:53:21 +02:00
|
|
|
if let notificationResponse = connectionOptions.notificationResponse {
|
|
|
|
window!.makeKeyAndVisible()
|
|
|
|
coordinator.handle(notificationResponse)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2019-08-26 00:49:09 +02:00
|
|
|
if let userActivity = connectionOptions.userActivities.first ?? session.stateRestorationActivity {
|
2019-10-03 16:53:21 +02:00
|
|
|
coordinator.handle(userActivity)
|
2019-08-26 00:49:09 +02:00
|
|
|
}
|
2019-09-06 17:29:00 +02:00
|
|
|
|
|
|
|
window!.makeKeyAndVisible()
|
2019-06-28 17:28:02 +02:00
|
|
|
}
|
|
|
|
|
2019-09-01 23:54:07 +02:00
|
|
|
func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
|
|
|
|
handleShortcutItem(shortcutItem)
|
|
|
|
completionHandler(true)
|
|
|
|
}
|
|
|
|
|
2019-08-25 02:31:29 +02:00
|
|
|
func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {
|
|
|
|
coordinator.handle(userActivity)
|
|
|
|
}
|
|
|
|
|
2019-06-28 17:28:02 +02:00
|
|
|
func sceneDidEnterBackground(_ scene: UIScene) {
|
2019-10-20 09:28:00 +02:00
|
|
|
ArticleStringFormatter.emptyCaches()
|
2019-06-28 17:28:02 +02:00
|
|
|
appDelegate.prepareAccountsForBackground()
|
|
|
|
}
|
|
|
|
|
|
|
|
func sceneWillEnterForeground(_ scene: UIScene) {
|
|
|
|
appDelegate.prepareAccountsForForeground()
|
2019-11-20 23:41:13 +01:00
|
|
|
self.coordinator.configurePanelMode(for: window!.frame.size)
|
2019-06-28 17:28:02 +02:00
|
|
|
}
|
|
|
|
|
2019-09-01 02:30:21 +02:00
|
|
|
func stateRestorationActivity(for scene: UIScene) -> NSUserActivity? {
|
|
|
|
return coordinator.stateRestorationActivity
|
|
|
|
}
|
2019-10-03 16:53:21 +02:00
|
|
|
|
|
|
|
// API
|
|
|
|
|
|
|
|
func handle(_ response: UNNotificationResponse) {
|
|
|
|
coordinator.handle(response)
|
|
|
|
}
|
2019-06-28 17:28:02 +02:00
|
|
|
|
|
|
|
}
|
2019-09-01 23:54:07 +02:00
|
|
|
|
|
|
|
private extension SceneDelegate {
|
|
|
|
|
|
|
|
func handleShortcutItem(_ shortcutItem: UIApplicationShortcutItem) {
|
|
|
|
switch shortcutItem.type {
|
|
|
|
case "com.ranchero.NetNewsWire.FirstUnread":
|
|
|
|
coordinator.selectFirstUnreadInAllUnread()
|
2019-09-02 00:41:46 +02:00
|
|
|
case "com.ranchero.NetNewsWire.ShowSearch":
|
|
|
|
coordinator.showSearch()
|
2019-09-02 22:14:26 +02:00
|
|
|
case "com.ranchero.NetNewsWire.ShowAdd":
|
2019-09-05 22:07:35 +02:00
|
|
|
coordinator.showAdd(.feed)
|
2019-09-01 23:54:07 +02:00
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|