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 {
|
class PreferencesNavigationController: UINavigationController {
|
||||||
|
|
||||||
|
private var isSwitchingAccounts = false
|
||||||
|
|
||||||
init(mastodonController: MastodonController) {
|
init(mastodonController: MastodonController) {
|
||||||
let view = PreferencesView()
|
let view = PreferencesView()
|
||||||
let hostingController = UIHostingController(rootView: view)
|
let hostingController = UIHostingController(rootView: view)
|
||||||
|
@ -33,9 +35,11 @@ class PreferencesNavigationController: UINavigationController {
|
||||||
override func viewWillDisappear(_ animated: Bool) {
|
override func viewWillDisappear(_ animated: Bool) {
|
||||||
super.viewWillDisappear(animated)
|
super.viewWillDisappear(animated)
|
||||||
|
|
||||||
|
if !isSwitchingAccounts {
|
||||||
// workaround for onDisappear not being called when a modally presented UIHostingController is dismissed
|
// workaround for onDisappear not being called when a modally presented UIHostingController is dismissed
|
||||||
NotificationCenter.default.post(name: .preferencesChanged, object: nil)
|
NotificationCenter.default.post(name: .preferencesChanged, object: nil)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@objc func donePressed() {
|
@objc func donePressed() {
|
||||||
dismiss(animated: true)
|
dismiss(animated: true)
|
||||||
|
@ -55,6 +59,7 @@ class PreferencesNavigationController: UINavigationController {
|
||||||
@objc func activateAccount(_ notification: Notification) {
|
@objc func activateAccount(_ notification: Notification) {
|
||||||
let account = notification.userInfo!["account"] as! LocalData.UserAccountInfo
|
let account = notification.userInfo!["account"] as! LocalData.UserAccountInfo
|
||||||
let sceneDelegate = self.view.window!.windowScene!.delegate as! SceneDelegate
|
let sceneDelegate = self.view.window!.windowScene!.delegate as! SceneDelegate
|
||||||
|
isSwitchingAccounts = true
|
||||||
dismiss(animated: true) { // dismiss preferences
|
dismiss(animated: true) { // dismiss preferences
|
||||||
sceneDelegate.activateAccount(account)
|
sceneDelegate.activateAccount(account)
|
||||||
}
|
}
|
||||||
|
@ -62,6 +67,7 @@ class PreferencesNavigationController: UINavigationController {
|
||||||
|
|
||||||
@objc func userLoggedOut() {
|
@objc func userLoggedOut() {
|
||||||
let sceneDelegate = self.view.window!.windowScene!.delegate as! SceneDelegate
|
let sceneDelegate = self.view.window!.windowScene!.delegate as! SceneDelegate
|
||||||
|
isSwitchingAccounts = true
|
||||||
dismiss(animated: true) { // dismiss preferences
|
dismiss(animated: true) { // dismiss preferences
|
||||||
sceneDelegate.logoutCurrent()
|
sceneDelegate.logoutCurrent()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue