diff --git a/frontend/mining-app/lib/presentation/widgets/main_shell.dart b/frontend/mining-app/lib/presentation/widgets/main_shell.dart index 8a6bd8a2..defd626f 100644 --- a/frontend/mining-app/lib/presentation/widgets/main_shell.dart +++ b/frontend/mining-app/lib/presentation/widgets/main_shell.dart @@ -22,20 +22,24 @@ class _MainShellState extends State with WidgetsBindingObserver { @override void initState() { super.initState(); + debugPrint('[MainShell] initState called, adding WidgetsBindingObserver'); WidgetsBinding.instance.addObserver(this); WidgetsBinding.instance.addPostFrameCallback((_) { + debugPrint('[MainShell] postFrameCallback → 触发首次更新检查'); _checkForUpdateIfNeeded(); }); } @override void dispose() { + debugPrint('[MainShell] dispose called, removing WidgetsBindingObserver'); WidgetsBinding.instance.removeObserver(this); super.dispose(); } @override void didChangeAppLifecycleState(AppLifecycleState state) { + debugPrint('[MainShell] didChangeAppLifecycleState: $state'); if (state == AppLifecycleState.resumed) { _checkForUpdateIfNeeded(); } @@ -45,29 +49,41 @@ class _MainShellState extends State with WidgetsBindingObserver { final now = DateTime.now(); // 如果从未检查过,或者已过冷却时间,则检查 - if (_nextCheckAllowedTime == null || now.isAfter(_nextCheckAllowedTime!)) { - // 设置下次允许检查时间(90-300秒随机间隔) - final randomSeconds = 90 + Random().nextInt(211); - _nextCheckAllowedTime = now.add(Duration(seconds: randomSeconds)); + if (_nextCheckAllowedTime != null && now.isBefore(_nextCheckAllowedTime!)) { + debugPrint('[MainShell] 跳过更新检查,冷却中 (下次: $_nextCheckAllowedTime)'); + return; + } - // 延迟3秒,避免启动时干扰用户 - await Future.delayed(const Duration(seconds: 3)); + // 设置下次允许检查时间(90-300秒随机间隔) + final randomSeconds = 90 + Random().nextInt(211); + _nextCheckAllowedTime = now.add(Duration(seconds: randomSeconds)); + debugPrint('[MainShell] 准备检查更新,延迟3秒...'); + + // 延迟3秒,避免启动时干扰用户 + await Future.delayed(const Duration(seconds: 3)); + if (!mounted) { + debugPrint('[MainShell] widget 已 unmount,取消检查'); + return; + } + + try { + debugPrint('[MainShell] 开始调用 UpdateService.checkForUpdate(force: true)'); + // force: true 跳过 UpdateService 内部的60分钟间隔限制 + // 因为我们已有自己的90-300秒冷却节流 + final result = await UpdateService.instance.checkForUpdate(force: true); + debugPrint('[MainShell] 检查结果: hasUpdate=${result.hasUpdate}, error=${result.error}'); if (!mounted) return; - try { - final result = await UpdateService.instance.checkForUpdate(); - if (!mounted) return; - - if (result.hasUpdate && result.versionInfo != null) { - await SelfHostedUpdater.show( - context, - versionInfo: result.versionInfo!, - isForceUpdate: result.versionInfo!.isForceUpdate, - ); - } - } catch (e) { - debugPrint('[MainShell] 检查更新失败: $e'); + if (result.hasUpdate && result.versionInfo != null) { + debugPrint('[MainShell] 发现新版本: ${result.versionInfo!.versionName},弹出更新对话框'); + await SelfHostedUpdater.show( + context, + versionInfo: result.versionInfo!, + isForceUpdate: result.versionInfo!.isForceUpdate, + ); } + } catch (e) { + debugPrint('[MainShell] 检查更新失败: $e'); } }