Fix crash when activating account in My Profile scene
This commit is contained in:
parent
23e4541eb7
commit
a13d5d5a82
|
@ -193,7 +193,6 @@ class ConversationTableViewController: EnhancedTableViewController {
|
|||
let parentIDs = self.getDirectParents(inReplyTo: mainStatusInReplyToID, from: context.ancestors)
|
||||
let parentStatuses = context.ancestors.filter { parentIDs.contains($0.id) }
|
||||
|
||||
// todo: should this really be blindly adding all the descendants?
|
||||
await mastodonController.persistentContainer.addAll(statuses: parentStatuses + context.descendants)
|
||||
self.contextLoaded(mainStatus: mainStatus, context: context, parentIDs: parentIDs)
|
||||
|
||||
|
|
|
@ -487,7 +487,6 @@ fileprivate extension MainTabBarViewController.Tab {
|
|||
case .explore:
|
||||
return "magnifyingglass"
|
||||
case .myProfile:
|
||||
// todo: use user avatar image
|
||||
return "person"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,42 +61,50 @@ class PreferencesNavigationController: UINavigationController {
|
|||
// 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,
|
||||
// todo: my profile can be torn off into a separate window, this doesn't work
|
||||
let sceneDelegate = windowScene.delegate as? MainSceneDelegate else {
|
||||
guard let windowScene = self.view.window?.windowScene else {
|
||||
return
|
||||
}
|
||||
let account = notification.userInfo!["account"] as! LocalData.UserAccountInfo
|
||||
if let sceneDelegate = windowScene.delegate as? MainSceneDelegate {
|
||||
isSwitchingAccounts = true
|
||||
dismiss(animated: true) { // dismiss preferences
|
||||
sceneDelegate.activateAccount(account, animated: true)
|
||||
}
|
||||
} else {
|
||||
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: UserActivityManager.mainSceneActivity(accountID: account.id), options: nil)
|
||||
}
|
||||
}
|
||||
|
||||
@objc func userLoggedOut() {
|
||||
guard let window = self.view.window,
|
||||
let windowScene = window.windowScene,
|
||||
// todo: my profile can be torn off into a separate window, this doesn't work
|
||||
let sceneDelegate = windowScene.delegate as? MainSceneDelegate else {
|
||||
guard let windowScene = self.view.window?.windowScene else {
|
||||
return
|
||||
}
|
||||
if let sceneDelegate = windowScene.delegate as? MainSceneDelegate {
|
||||
isSwitchingAccounts = true
|
||||
dismiss(animated: true) { // dismiss preferences
|
||||
sceneDelegate.logoutCurrent()
|
||||
}
|
||||
} else {
|
||||
LocalData.shared.removeAccount(LocalData.shared.getMostRecentAccount()!)
|
||||
let accountID = LocalData.shared.getMostRecentAccount()?.id
|
||||
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: UserActivityManager.mainSceneActivity(accountID: accountID), options: nil)
|
||||
UIApplication.shared.requestSceneSessionDestruction(windowScene.session, options: nil)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension PreferencesNavigationController: OnboardingViewControllerDelegate {
|
||||
func didFinishOnboarding(account: LocalData.UserAccountInfo) {
|
||||
DispatchQueue.main.async {
|
||||
// todo: my profile can be torn off into a separate window, this will crash
|
||||
let sceneDelegate = self.view.window!.windowScene!.delegate as! MainSceneDelegate
|
||||
guard let windowScene = self.view.window?.windowScene else {
|
||||
return
|
||||
}
|
||||
self.dismiss(animated: true) { // dismiss instance selector
|
||||
self.dismiss(animated: true) { // dismiss preferences
|
||||
if let sceneDelegate = windowScene.delegate as? MainSceneDelegate {
|
||||
sceneDelegate.activateAccount(account, animated: false)
|
||||
} else {
|
||||
UIApplication.shared.requestSceneSessionActivation(nil, userActivity: UserActivityManager.mainSceneActivity(accountID: account.id), options: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,8 +136,6 @@ class SearchResultsViewController: EnhancedTableViewController {
|
|||
if let sourceDataSource = source.dataSource {
|
||||
dataSource.apply(sourceDataSource.snapshot())
|
||||
}
|
||||
// todo: check if the search needs to be performed before searching
|
||||
// performSearch(query: currentQuery)
|
||||
}
|
||||
|
||||
func performSearch(query: String?) {
|
||||
|
|
|
@ -46,11 +46,13 @@ class UserActivityManager {
|
|||
}
|
||||
|
||||
// MARK: - Main Scene
|
||||
static func mainSceneActivity(accountID: String) -> NSUserActivity {
|
||||
static func mainSceneActivity(accountID: String?) -> NSUserActivity {
|
||||
let activity = NSUserActivity(type: .mainScene)
|
||||
if let accountID {
|
||||
activity.userInfo = [
|
||||
"accountID": accountID,
|
||||
]
|
||||
}
|
||||
return activity
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue