forked from shadowfacts/Tusker
Fix weird crashes when switching accounts
This commit is contained in:
parent
ee252c02e9
commit
3aa5aa1bc0
|
@ -11,6 +11,8 @@ import SwiftUI
|
|||
|
||||
class PreferencesNavigationController: UINavigationController {
|
||||
|
||||
private var isSwitchingAccounts = false
|
||||
|
||||
init(mastodonController: MastodonController) {
|
||||
let view = PreferencesView()
|
||||
let hostingController = UIHostingController(rootView: view)
|
||||
|
@ -33,8 +35,10 @@ class PreferencesNavigationController: UINavigationController {
|
|||
override func viewWillDisappear(_ animated: Bool) {
|
||||
super.viewWillDisappear(animated)
|
||||
|
||||
// workaround for onDisappear not being called when a modally presented UIHostingController is dismissed
|
||||
NotificationCenter.default.post(name: .preferencesChanged, object: nil)
|
||||
if !isSwitchingAccounts {
|
||||
// workaround for onDisappear not being called when a modally presented UIHostingController is dismissed
|
||||
NotificationCenter.default.post(name: .preferencesChanged, object: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func donePressed() {
|
||||
|
@ -55,6 +59,7 @@ class PreferencesNavigationController: UINavigationController {
|
|||
@objc func activateAccount(_ notification: Notification) {
|
||||
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)
|
||||
}
|
||||
|
@ -62,6 +67,7 @@ class PreferencesNavigationController: UINavigationController {
|
|||
|
||||
@objc func userLoggedOut() {
|
||||
let sceneDelegate = self.view.window!.windowScene!.delegate as! SceneDelegate
|
||||
isSwitchingAccounts = true
|
||||
dismiss(animated: true) { // dismiss preferences
|
||||
sceneDelegate.logoutCurrent()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue