Temporary fix for crash that occurs when switching accounts immediately

after adding a new one
This commit is contained in:
Shadowfacts 2020-02-29 17:36:54 -05:00
parent 804636dcbb
commit af821081b0
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 14 additions and 2 deletions

View File

@ -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()