From 9be68e83466e26a9bb143d716a27cf0aefe850c4 Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Mon, 8 Oct 2018 21:38:21 -0400 Subject: [PATCH] Always update shortcuts on app launch --- Classes/Systems/AppRouter/AppController.swift | 7 ++++++- Classes/Systems/ShortcutHandler.swift | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Classes/Systems/AppRouter/AppController.swift b/Classes/Systems/AppRouter/AppController.swift index 23986c0cc..ca0c45723 100644 --- a/Classes/Systems/AppRouter/AppController.swift +++ b/Classes/Systems/AppRouter/AppController.swift @@ -30,6 +30,7 @@ final class AppController: LoginSplashViewControllerDelegate, GitHubSessionListe } splitViewController = controller + resetShortcuts() if let focused = sessionManager.focusedUserSession { resetViewControllers(userSession: focused) resetWatchSync(userSession: focused) @@ -83,6 +84,10 @@ final class AppController: LoginSplashViewControllerDelegate, GitHubSessionListe watchAppSync?.start() } + private func resetShortcuts() { + ShortcutHandler.configure(sessionUsernames: sessionManager.userSessions.compactMap { $0.username }) + } + private func resetViewControllers(userSession: GitHubUserSession) { let appClient = GithubClient(userSession: userSession) self.appClient = appClient @@ -140,7 +145,7 @@ final class AppController: LoginSplashViewControllerDelegate, GitHubSessionListe splitViewController.presentedViewController?.dismiss(animated: trueUnlessReduceMotionEnabled) } - ShortcutHandler.configure(sessionUsernames: manager.userSessions.compactMap { $0.username }) + resetShortcuts() if let watch = watchAppSync { watch.sync(userSession: userSession) } else { diff --git a/Classes/Systems/ShortcutHandler.swift b/Classes/Systems/ShortcutHandler.swift index fec1d7102..ccbbe187e 100644 --- a/Classes/Systems/ShortcutHandler.swift +++ b/Classes/Systems/ShortcutHandler.swift @@ -45,6 +45,8 @@ struct ShortcutHandler { } private static func generateItems(sessionUsernames: [String]) -> [UIApplicationShortcutItem] { + guard sessionUsernames.count > 0 else { return [] } + var items = [ UIApplicationShortcutItem.from( route: SearchShortcutRoute(),