From c19b7ec2c664c7cb91acf378898f7a54416f9b81 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 14 Nov 2020 10:45:36 -0500 Subject: [PATCH] Fix crash when logging in for the first time --- Tusker/SceneDelegate.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tusker/SceneDelegate.swift b/Tusker/SceneDelegate.swift index 3ee0eec3..bb50fb30 100644 --- a/Tusker/SceneDelegate.swift +++ b/Tusker/SceneDelegate.swift @@ -142,8 +142,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { } 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) window!.windowScene!.session.mastodonController = MastodonController.getForAccount(account) @@ -151,7 +149,9 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { let newRoot = createAppUI() if let container = window?.rootViewController as? AccountSwitchingContainerViewController { 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 } else { direction = .none