fix: 增加登录失效确认弹窗
This commit is contained in:
@ -8,6 +8,7 @@ import UIKit
|
||||
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
|
||||
var window: UIWindow?
|
||||
private var sessionExpiredDialog: SessionExpiredDialogViewController?
|
||||
|
||||
func scene(
|
||||
_ scene: UIScene,
|
||||
@ -86,18 +87,36 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
}
|
||||
|
||||
@objc private func handleSessionDidExpire() {
|
||||
guard AppStore.shared.session.isLoggedIn else { return }
|
||||
guard sessionExpiredDialog == nil else { return }
|
||||
|
||||
GlobalLoadingManager.shared.hideAll()
|
||||
let dialog = SessionExpiredDialogViewController { [weak self] in
|
||||
self?.transitionToLogin()
|
||||
}
|
||||
sessionExpiredDialog = dialog
|
||||
|
||||
guard let presenter = topViewController(from: window?.rootViewController) else {
|
||||
sessionExpiredDialog = nil
|
||||
return
|
||||
}
|
||||
presenter.present(dialog, animated: true)
|
||||
}
|
||||
|
||||
private func transitionToLogin() {
|
||||
sessionExpiredDialog = nil
|
||||
PushNotificationManager.shared.handleLogout()
|
||||
AppStore.shared.logout()
|
||||
AppRouter.setRoot(.login, on: window)
|
||||
}
|
||||
|
||||
@objc private func handleUserDidLogout() {
|
||||
PushNotificationManager.shared.handleLogout()
|
||||
AppStore.shared.logout()
|
||||
AppRouter.setRoot(.login, on: window)
|
||||
transitionToLogin()
|
||||
}
|
||||
|
||||
@objc private func handleUserDidLogin() {
|
||||
sessionExpiredDialog?.dismiss(animated: false)
|
||||
sessionExpiredDialog = nil
|
||||
AppRouter.setRoot(.mainTab, on: window)
|
||||
DispatchQueue.main.async {
|
||||
PushNotificationManager.shared.handleLoginCompleted()
|
||||
@ -108,4 +127,18 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
|
||||
@objc private func handleAccountDidSwitch() {
|
||||
PushNotificationManager.shared.handleAccountSwitched()
|
||||
}
|
||||
|
||||
private func topViewController(from viewController: UIViewController?) -> UIViewController? {
|
||||
guard let viewController else { return nil }
|
||||
if let presented = viewController.presentedViewController {
|
||||
return topViewController(from: presented)
|
||||
}
|
||||
if let navigationController = viewController as? UINavigationController {
|
||||
return topViewController(from: navigationController.visibleViewController)
|
||||
}
|
||||
if let tabBarController = viewController as? UITabBarController {
|
||||
return topViewController(from: tabBarController.selectedViewController)
|
||||
}
|
||||
return viewController
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user