Refactor AppServices into assembly, feature facades, and lifecycle coordinator.
Extract dependency wiring and session lifecycle from the container and RootViewController, split NetworkBundle by domain, and add module-level feature services while keeping flat accessors for compatibility. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -11,11 +11,13 @@ import UIKit
|
||||
final class RootViewController: UIViewController {
|
||||
|
||||
private let services: AppServices
|
||||
private let lifecycleCoordinator: AppSessionLifecycleCoordinator
|
||||
private var currentAuthChild: UIViewController?
|
||||
|
||||
/// 初始化实例。
|
||||
init(services: AppServices = .shared) {
|
||||
self.services = services
|
||||
lifecycleCoordinator = AppSessionLifecycleCoordinator(services: services)
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
}
|
||||
|
||||
@ -34,64 +36,14 @@ final class RootViewController: UIViewController {
|
||||
}
|
||||
|
||||
applyRoot(for: services.appSession.phase)
|
||||
bootstrapSession()
|
||||
services.configurePushNotifications()
|
||||
}
|
||||
|
||||
/// 冷启动时恢复本地会话,并在已登录时申请推送权限。
|
||||
private func bootstrapSession() {
|
||||
Task {
|
||||
await services.globalLoading.withLoading {
|
||||
await services.sessionBootstrapper.restore(
|
||||
appSession: services.appSession,
|
||||
accountContext: services.accountContext,
|
||||
permissionContext: services.permissionContext,
|
||||
profileAPI: services.profileAPI,
|
||||
accountContextAPI: services.accountContextAPI,
|
||||
toastCenter: services.toastCenter
|
||||
)
|
||||
}
|
||||
|
||||
if services.appSession.isLoggedIn, !AppUITestLaunchState.isRunningUITests {
|
||||
PushNotificationManager.shared.requestAuthorizationAndRegister()
|
||||
}
|
||||
}
|
||||
lifecycleCoordinator.bootstrapSession()
|
||||
lifecycleCoordinator.configurePushNotifications()
|
||||
}
|
||||
|
||||
/// 登录阶段变化时切换 window 根控制器,并在登出时清理各上下文状态。
|
||||
private func handleSessionPhaseChange() {
|
||||
applyRoot(for: services.appSession.phase)
|
||||
|
||||
switch services.appSession.phase {
|
||||
case .loggedIn:
|
||||
if !AppUITestLaunchState.isRunningUITests {
|
||||
PushNotificationManager.shared.requestAuthorizationAndRegister()
|
||||
}
|
||||
Task { await reloadScenicSpotContextIfNeeded() }
|
||||
case .loggedOut:
|
||||
// 登出后重置账号、权限、路由与排队运行时,避免残留旧状态
|
||||
services.accountContext.reset()
|
||||
services.permissionContext.reset()
|
||||
services.scenicSpotContext.reset()
|
||||
services.appNavigator.resetAllStacks()
|
||||
services.appNavigator.detach()
|
||||
services.toastCenter.dismiss()
|
||||
services.scenicQueueRuntime.stop()
|
||||
case .restoring:
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
/// 登录成功后按当前景区 ID 刷新景区上下文。
|
||||
private func reloadScenicSpotContextIfNeeded() async {
|
||||
guard services.appSession.isLoggedIn else {
|
||||
services.scenicSpotContext.reset()
|
||||
return
|
||||
}
|
||||
await services.scenicSpotContext.reload(
|
||||
scenicId: services.accountContext.currentScenic?.id,
|
||||
api: services.accountContextAPI
|
||||
)
|
||||
lifecycleCoordinator.handleSessionPhaseChange()
|
||||
}
|
||||
|
||||
/// 按登录阶段切换 window 根控制器。
|
||||
|
||||
Reference in New Issue
Block a user