diff --git a/frontend/mobile-app/lib/features/home/presentation/pages/home_shell_page.dart b/frontend/mobile-app/lib/features/home/presentation/pages/home_shell_page.dart index bde3175f..b16e4172 100644 --- a/frontend/mobile-app/lib/features/home/presentation/pages/home_shell_page.dart +++ b/frontend/mobile-app/lib/features/home/presentation/pages/home_shell_page.dart @@ -7,6 +7,7 @@ import '../../../../core/theme/app_colors.dart'; import '../../../../core/di/injection_container.dart'; import '../../../../core/services/contract_check_service.dart'; import '../../../../core/updater/update_service.dart'; +import '../../../../core/providers/maintenance_provider.dart'; import '../../../../routes/route_paths.dart'; import '../../../../routes/app_router.dart'; import '../../../../bootstrap.dart'; @@ -33,6 +34,9 @@ class _HomeShellPageState extends ConsumerState /// 后台合同检查定时器 Timer? _contractCheckTimer; + /// 维护状态检查定时器 + Timer? _maintenanceCheckTimer; + /// 是否正在显示弹窗(防止重复弹窗) bool _isShowingDialog = false; @@ -40,12 +44,15 @@ class _HomeShellPageState extends ConsumerState void initState() { super.initState(); WidgetsBinding.instance.addObserver(this); - // 首次进入时检查更新和未签署合同 + // 首次进入时检查维护状态、更新和未签署合同 WidgetsBinding.instance.addPostFrameCallback((_) { + _checkMaintenanceStatus(); _checkForUpdateIfNeeded(); _checkContractsAndKyc(); // 启动后台定时检查 _startBackgroundContractCheck(); + // 启动维护状态定时检查 + _startMaintenanceCheck(); }); } @@ -53,19 +60,55 @@ class _HomeShellPageState extends ConsumerState void dispose() { WidgetsBinding.instance.removeObserver(this); _contractCheckTimer?.cancel(); + _maintenanceCheckTimer?.cancel(); super.dispose(); } @override void didChangeAppLifecycleState(AppLifecycleState state) { - // 从后台恢复时检查更新 + // 从后台恢复时检查维护状态和更新 if (state == AppLifecycleState.resumed) { + _checkMaintenanceStatus(); _checkForUpdateIfNeeded(); // 从后台恢复时也触发一次检查 _scheduleNextContractCheck(); + // 恢复维护检查定时器 + _startMaintenanceCheck(); } else if (state == AppLifecycleState.paused) { // 进入后台时取消定时器 _contractCheckTimer?.cancel(); + _maintenanceCheckTimer?.cancel(); + } + } + + /// 启动维护状态定时检查(随机 3-6 秒检查一次) + void _startMaintenanceCheck() { + _scheduleNextMaintenanceCheck(); + } + + /// 安排下一次维护检查 + void _scheduleNextMaintenanceCheck() { + _maintenanceCheckTimer?.cancel(); + // 随机 3-6 秒 + final randomSeconds = 3 + Random().nextInt(4); // 3 + 0~3 = 3~6 + _maintenanceCheckTimer = Timer(Duration(seconds: randomSeconds), () async { + await _checkMaintenanceStatus(); + // 检查完成后安排下一次检查 + if (mounted) { + _scheduleNextMaintenanceCheck(); + } + }); + } + + /// 检查系统维护状态 + Future _checkMaintenanceStatus() async { + if (!mounted) return; + + try { + final maintenanceNotifier = ref.read(maintenanceProvider.notifier); + await maintenanceNotifier.showMaintenanceDialogIfNeeded(context); + } catch (e) { + debugPrint('[HomeShellPage] 检查维护状态失败: $e'); } }