forked from shadowfacts/Tusker
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 parentIDs = self.getDirectParents(inReplyTo: mainStatusInReplyToID, from: context.ancestors)
|
||||||
let parentStatuses = context.ancestors.filter { parentIDs.contains($0.id) }
|
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)
|
await mastodonController.persistentContainer.addAll(statuses: parentStatuses + context.descendants)
|
||||||
self.contextLoaded(mainStatus: mainStatus, context: context, parentIDs: parentIDs)
|
self.contextLoaded(mainStatus: mainStatus, context: context, parentIDs: parentIDs)
|
||||||
|
|
||||||
|
|
|
@ -487,7 +487,6 @@ fileprivate extension MainTabBarViewController.Tab {
|
||||||
case .explore:
|
case .explore:
|
||||||
return "magnifyingglass"
|
return "magnifyingglass"
|
||||||
case .myProfile:
|
case .myProfile:
|
||||||
// todo: use user avatar image
|
|
||||||
return "person"
|
return "person"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,29 +61,34 @@ class PreferencesNavigationController: UINavigationController {
|
||||||
// when switching accounts shortly after adding a new one, there is an old instance of PreferncesNavigationController still around
|
// 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)
|
// 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
|
// the propper fix would be to figure out what's leaking instances of this class
|
||||||
guard let window = self.view.window,
|
guard let windowScene = self.view.window?.windowScene else {
|
||||||
let windowScene = window.windowScene,
|
return
|
||||||
// todo: my profile can be torn off into a separate window, this doesn't work
|
|
||||||
let sceneDelegate = windowScene.delegate as? MainSceneDelegate else {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
let account = notification.userInfo!["account"] as! LocalData.UserAccountInfo
|
let account = notification.userInfo!["account"] as! LocalData.UserAccountInfo
|
||||||
isSwitchingAccounts = true
|
if let sceneDelegate = windowScene.delegate as? MainSceneDelegate {
|
||||||
dismiss(animated: true) { // dismiss preferences
|
isSwitchingAccounts = true
|
||||||
sceneDelegate.activateAccount(account, animated: 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() {
|
@objc func userLoggedOut() {
|
||||||
guard let window = self.view.window,
|
guard let windowScene = self.view.window?.windowScene else {
|
||||||
let windowScene = window.windowScene,
|
return
|
||||||
// todo: my profile can be torn off into a separate window, this doesn't work
|
|
||||||
let sceneDelegate = windowScene.delegate as? MainSceneDelegate else {
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
isSwitchingAccounts = true
|
if let sceneDelegate = windowScene.delegate as? MainSceneDelegate {
|
||||||
dismiss(animated: true) { // dismiss preferences
|
isSwitchingAccounts = true
|
||||||
sceneDelegate.logoutCurrent()
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,12 +96,15 @@ class PreferencesNavigationController: UINavigationController {
|
||||||
|
|
||||||
extension PreferencesNavigationController: OnboardingViewControllerDelegate {
|
extension PreferencesNavigationController: OnboardingViewControllerDelegate {
|
||||||
func didFinishOnboarding(account: LocalData.UserAccountInfo) {
|
func didFinishOnboarding(account: LocalData.UserAccountInfo) {
|
||||||
DispatchQueue.main.async {
|
guard let windowScene = self.view.window?.windowScene else {
|
||||||
// todo: my profile can be torn off into a separate window, this will crash
|
return
|
||||||
let sceneDelegate = self.view.window!.windowScene!.delegate as! MainSceneDelegate
|
}
|
||||||
self.dismiss(animated: true) { // dismiss instance selector
|
self.dismiss(animated: true) { // dismiss instance selector
|
||||||
self.dismiss(animated: true) { // dismiss preferences
|
self.dismiss(animated: true) { // dismiss preferences
|
||||||
|
if let sceneDelegate = windowScene.delegate as? MainSceneDelegate {
|
||||||
sceneDelegate.activateAccount(account, animated: false)
|
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 {
|
if let sourceDataSource = source.dataSource {
|
||||||
dataSource.apply(sourceDataSource.snapshot())
|
dataSource.apply(sourceDataSource.snapshot())
|
||||||
}
|
}
|
||||||
// todo: check if the search needs to be performed before searching
|
|
||||||
// performSearch(query: currentQuery)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func performSearch(query: String?) {
|
func performSearch(query: String?) {
|
||||||
|
|
|
@ -46,11 +46,13 @@ class UserActivityManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Main Scene
|
// MARK: - Main Scene
|
||||||
static func mainSceneActivity(accountID: String) -> NSUserActivity {
|
static func mainSceneActivity(accountID: String?) -> NSUserActivity {
|
||||||
let activity = NSUserActivity(type: .mainScene)
|
let activity = NSUserActivity(type: .mainScene)
|
||||||
activity.userInfo = [
|
if let accountID {
|
||||||
"accountID": accountID,
|
activity.userInfo = [
|
||||||
]
|
"accountID": accountID,
|
||||||
|
]
|
||||||
|
}
|
||||||
return activity
|
return activity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue