diff --git a/AutoCat.xcodeproj/project.pbxproj b/AutoCat.xcodeproj/project.pbxproj index 4c1a801..098d153 100644 --- a/AutoCat.xcodeproj/project.pbxproj +++ b/AutoCat.xcodeproj/project.pbxproj @@ -547,7 +547,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 5; DEVELOPMENT_TEAM = 46DTTB8X4S; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", @@ -571,7 +571,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 4; + CURRENT_PROJECT_VERSION = 5; DEVELOPMENT_TEAM = 46DTTB8X4S; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", diff --git a/AutoCat/AppDelegate.swift b/AutoCat/AppDelegate.swift index e99f5f5..c280f2a 100644 --- a/AutoCat/AppDelegate.swift +++ b/AutoCat/AppDelegate.swift @@ -1,11 +1,21 @@ import UIKit import SVProgressHUD import RealmSwift +import os.log + +extension OSLog { + static let startup = OSLog(subsystem: "pro.aliencat.autocat.startup", category: "startup") +} + +enum QuickAction { + case none + case check +} @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { - + var quickAction: QuickAction = .none func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { @@ -27,6 +37,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. + + if let shortcutItem = options.shortcutItem { + if shortcutItem.type == "CheckNumberAction" { + self.quickAction = .check + } + } + return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } diff --git a/AutoCat/Controllers/CheckController.swift b/AutoCat/Controllers/CheckController.swift index 5f66052..8981ef2 100644 --- a/AutoCat/Controllers/CheckController.swift +++ b/AutoCat/Controllers/CheckController.swift @@ -62,6 +62,20 @@ class CheckController: UIViewController, MaskedTextFieldDelegateListener { } } + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) + self.handleQuickActions() + } + + func handleQuickActions() { + guard let ad = UIApplication.shared.delegate as? AppDelegate else { return } + + if ad.quickAction == .check { + ad.quickAction = .none + self.number.becomeFirstResponder() + } + } + @IBAction func checkTapped(_ sender: UIButton) { guard let number = self.number.text else { return } diff --git a/AutoCat/Controllers/ReportController.swift b/AutoCat/Controllers/ReportController.swift index 966e062..4bf9365 100644 --- a/AutoCat/Controllers/ReportController.swift +++ b/AutoCat/Controllers/ReportController.swift @@ -93,7 +93,17 @@ class ReportController: UIViewController, UICollectionViewDataSource, UICollecti override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) + guard let ad = UIApplication.shared.delegate as? AppDelegate else { return } + self.navigationController?.setNavigationBarHidden(self.traitCollection.horizontalSizeClass != .compact, animated: false) + + if ad.quickAction == .check { + self.dismiss(animated: false, completion: nil) + } + } + + override func viewDidAppear(_ animated: Bool) { + super.viewDidAppear(animated) } override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { diff --git a/AutoCat/Info.plist b/AutoCat/Info.plist index c34e0f0..f0170f0 100644 --- a/AutoCat/Info.plist +++ b/AutoCat/Info.plist @@ -63,6 +63,17 @@ + UIApplicationShortcutItems + + + UIApplicationShortcutItemIconType + UIApplicationShortcutIconTypeCompose + UIApplicationShortcutItemTitle + Check plate number + UIApplicationShortcutItemType + CheckNumberAction + + UILaunchStoryboardName LaunchScreen UIRequiredDeviceCapabilities diff --git a/AutoCat/SceneDelegate.swift b/AutoCat/SceneDelegate.swift index 696caeb..fee3800 100644 --- a/AutoCat/SceneDelegate.swift +++ b/AutoCat/SceneDelegate.swift @@ -50,6 +50,26 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { // to restore the scene back to its current state. } - + func windowScene(_ windowScene: UIWindowScene, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) { + guard let ad = UIApplication.shared.delegate as? AppDelegate else { return } + + if shortcutItem.type == "CheckNumberAction" { + ad.quickAction = .check + + if let split = self.window?.rootViewController as? MainSplitController, let tabvc = split.viewControllers.first as? UITabBarController { + if tabvc.selectedIndex == 0 { + if let nav = tabvc.selectedViewController as? UINavigationController, let child = nav.topViewController { + if let check = child as? CheckController { + check.handleQuickActions() + } else { + nav.popToRootViewController(animated: false) + } + } + } else { + tabvc.selectedIndex = 0 + } + } + } + } }