refactor(apps): 重构数据层目录结构并新增启动预热编排器
This commit is contained in:
@@ -34,6 +34,7 @@ import '../../../features/settings/presentation/screens/work_memory_view_screen.
|
||||
import '../../../features/settings/presentation/screens/user_memory_detail_screen.dart';
|
||||
import '../../../features/settings/presentation/screens/work_memory_detail_screen.dart';
|
||||
import '../../../features/settings/presentation/screens/edit_profile_screen.dart';
|
||||
import '../services/app_prewarm_orchestrator.dart';
|
||||
|
||||
final _homeSecondLevelRoutes = [
|
||||
AppRoutes.shellCalendarBranch,
|
||||
@@ -60,6 +61,7 @@ final _protectedRoutes = [
|
||||
String? resolveAuthRedirect({
|
||||
required AuthState authState,
|
||||
required String matchedLocation,
|
||||
AppPrewarmOrchestrator? prewarm,
|
||||
}) {
|
||||
final isAuthenticated = authState is AuthAuthenticated;
|
||||
final isAuthChecking = authState is AuthInitial || authState is AuthLoading;
|
||||
@@ -71,11 +73,21 @@ String? resolveAuthRedirect({
|
||||
final isProtected =
|
||||
isHomeRoute ||
|
||||
_protectedRoutes.any((route) => matchedLocation.startsWith(route));
|
||||
final prewarmStatus = prewarm?.status ?? AppPrewarmStatus.completed;
|
||||
final shouldBlockForPrewarm =
|
||||
isAuthenticated && prewarmStatus == AppPrewarmStatus.running;
|
||||
|
||||
if (shouldBlockForPrewarm && !isBootRoute) {
|
||||
return AppRoutes.authBoot;
|
||||
}
|
||||
|
||||
if (isAuthChecking && !isBootRoute) {
|
||||
return AppRoutes.authBoot;
|
||||
}
|
||||
if (!isAuthChecking && isBootRoute) {
|
||||
if (shouldBlockForPrewarm) {
|
||||
return null;
|
||||
}
|
||||
return isAuthenticated ? AppRoutes.homeMain : AppRoutes.authLogin;
|
||||
}
|
||||
if (!isAuthenticated && isProtected) {
|
||||
@@ -95,14 +107,17 @@ Widget buildHomeRouteScreen() {
|
||||
}
|
||||
|
||||
GoRouter createAppRouter(AuthBloc authBloc) {
|
||||
final authRefresh = GoRouterRefreshStream(authBloc.stream);
|
||||
final prewarm = sl<AppPrewarmOrchestrator>();
|
||||
return GoRouter(
|
||||
initialLocation: AppRoutes.authBoot,
|
||||
observers: [appRouteObserver],
|
||||
refreshListenable: GoRouterRefreshStream(authBloc.stream),
|
||||
refreshListenable: Listenable.merge([authRefresh, prewarm]),
|
||||
redirect: (context, state) {
|
||||
return resolveAuthRedirect(
|
||||
authState: authBloc.state,
|
||||
matchedLocation: state.matchedLocation,
|
||||
prewarm: prewarm,
|
||||
);
|
||||
},
|
||||
routes: [
|
||||
|
||||
Reference in New Issue
Block a user