diff --git a/Delta/AppDelegate.swift b/Delta/AppDelegate.swift index 8631eff..49743a0 100644 --- a/Delta/AppDelegate.swift +++ b/Delta/AppDelegate.swift @@ -19,6 +19,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate var window: UIWindow? private let deepLinkController = DeepLinkController() + private var appLaunchDeepLink: DeepLink? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { @@ -40,10 +41,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate // Controllers ExternalGameControllerManager.shared.startMonitoring() + // Notifications + NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.databaseManagerDidStart(_:)), name: DatabaseManager.didStartNotification, object: DatabaseManager.shared) + // Deep Links if let shortcut = launchOptions?[.shortcutItem] as? UIApplicationShortcutItem { - self.deepLinkController.handle(.shortcut(shortcut)) + self.appLaunchDeepLink = .shortcut(shortcut) // false = we handled the deep link, so no need to call delegate method separately. return false @@ -164,3 +168,15 @@ extension AppDelegate } } +private extension AppDelegate +{ + @objc func databaseManagerDidStart(_ notification: Notification) + { + guard let deepLink = self.appLaunchDeepLink else { return } + + DispatchQueue.main.async { + self.deepLinkController.handle(deepLink) + } + } +} + diff --git a/Delta/Database/DatabaseManager.swift b/Delta/Database/DatabaseManager.swift index e10248d..c158901 100644 --- a/Delta/Database/DatabaseManager.swift +++ b/Delta/Database/DatabaseManager.swift @@ -15,6 +15,11 @@ import Harmony import Roxas import ZIPFoundation +extension DatabaseManager +{ + static let didStartNotification = Notification.Name("databaseManagerDidStartNotification") +} + extension DatabaseManager { enum ImportError: Error, Hashable @@ -97,6 +102,9 @@ extension DatabaseManager self.prepareDatabase { self.isStarted = true + + NotificationCenter.default.post(name: DatabaseManager.didStartNotification, object: self) + completionHandler(nil) } } diff --git a/Delta/Launch/LaunchViewController.swift b/Delta/Launch/LaunchViewController.swift index 8ee0936..95f34d4 100644 --- a/Delta/Launch/LaunchViewController.swift +++ b/Delta/Launch/LaunchViewController.swift @@ -105,7 +105,9 @@ extension LaunchViewController UIView.transition(with: self.view, duration: 0.3, options: [.transitionCrossDissolve], animations: { showGameViewController() - }, completion: nil) + }) { (finished) in + self.gameViewController.startEmulation() + } } else {