diff --git a/Tusker/Screens/Preferences/PreferencesNavigationController.swift b/Tusker/Screens/Preferences/PreferencesNavigationController.swift index 3b4d7b4f..302eb832 100644 --- a/Tusker/Screens/Preferences/PreferencesNavigationController.swift +++ b/Tusker/Screens/Preferences/PreferencesNavigationController.swift @@ -57,8 +57,16 @@ class PreferencesNavigationController: UINavigationController { } @objc func activateAccount(_ notification: Notification) { + // TODO: this is a temporary measure + // when switching accounts shortly after adding a new one, there is an old instance of PreferncesNavigationController still around + // which tries to handle the notification but is unable to because it no longer is in a window (and therefore doesn't have a scene delegate) + // the propper fix would be to figure out what's leaking instances of this class + guard let window = self.view.window, + let windowScene = window.windowScene, + let sceneDelegate = windowScene.delegate as? SceneDelegate else { + return + } let account = notification.userInfo!["account"] as! LocalData.UserAccountInfo - let sceneDelegate = self.view.window!.windowScene!.delegate as! SceneDelegate isSwitchingAccounts = true dismiss(animated: true) { // dismiss preferences sceneDelegate.activateAccount(account) @@ -66,7 +74,11 @@ class PreferencesNavigationController: UINavigationController { } @objc func userLoggedOut() { - let sceneDelegate = self.view.window!.windowScene!.delegate as! SceneDelegate + guard let window = self.view.window, + let windowScene = window.windowScene, + let sceneDelegate = windowScene.delegate as? SceneDelegate else { + return + } isSwitchingAccounts = true dismiss(animated: true) { // dismiss preferences sceneDelegate.logoutCurrent()