refactor(apps): 重构数据层目录结构并新增启动预热编排器

This commit is contained in:
zl-q
2026-03-29 20:26:30 +08:00
parent 33340de8f9
commit 4db9a13bfe
108 changed files with 1653 additions and 1320 deletions
+16 -1
View File
@@ -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: [