Fix crash when logging in for the first time

This commit is contained in:
Shadowfacts 2020-11-14 10:45:36 -05:00
parent 59c00b01dc
commit c19b7ec2c6
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 3 additions and 3 deletions

View File

@ -142,8 +142,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
} }
func activateAccount(_ account: LocalData.UserAccountInfo, animated: Bool) { func activateAccount(_ account: LocalData.UserAccountInfo, animated: Bool) {
let oldIndex = LocalData.shared.accounts.firstIndex(where: { $0.id == LocalData.shared.mostRecentAccountID })!
let newIndex = LocalData.shared.accounts.firstIndex(of: account)!
LocalData.shared.setMostRecentAccount(account) LocalData.shared.setMostRecentAccount(account)
window!.windowScene!.session.mastodonController = MastodonController.getForAccount(account) window!.windowScene!.session.mastodonController = MastodonController.getForAccount(account)
@ -151,7 +149,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
let newRoot = createAppUI() let newRoot = createAppUI()
if let container = window?.rootViewController as? AccountSwitchingContainerViewController { if let container = window?.rootViewController as? AccountSwitchingContainerViewController {
let direction: AccountSwitchingContainerViewController.AnimationDirection let direction: AccountSwitchingContainerViewController.AnimationDirection
if animated { if animated,
let oldIndex = LocalData.shared.accounts.firstIndex(where: { $0.id == LocalData.shared.mostRecentAccountID }),
let newIndex = LocalData.shared.accounts.firstIndex(of: account) {
direction = newIndex > oldIndex ? .upwards : .downwards direction = newIndex > oldIndex ? .upwards : .downwards
} else { } else {
direction = .none direction = .none