From 53320df220af61b8ba5cb170b87d212aed5731ca Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 9 Dec 2025 07:52:00 -0800 Subject: [PATCH] fix(mobile): always check for updates and add debug logs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Remove condition that only checked updates when wallet was created - Add debug logging to version checker and self hosted updater - Updates should now prompt on every app launch 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../lib/core/updater/channels/self_hosted_updater.dart | 5 ++++- .../mobile-app/lib/core/updater/version_checker.dart | 9 ++++++++- .../features/auth/presentation/pages/splash_page.dart | 10 ++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/frontend/mobile-app/lib/core/updater/channels/self_hosted_updater.dart b/frontend/mobile-app/lib/core/updater/channels/self_hosted_updater.dart index ad66d49d..82e3b9c2 100644 --- a/frontend/mobile-app/lib/core/updater/channels/self_hosted_updater.dart +++ b/frontend/mobile-app/lib/core/updater/channels/self_hosted_updater.dart @@ -19,13 +19,16 @@ class SelfHostedUpdater { /// 检查并提示更新 Future checkAndPromptUpdate(BuildContext context) async { + debugPrint('[SelfHostedUpdater] 开始检查更新...'); final versionInfo = await versionChecker.checkForUpdate(); if (versionInfo == null) { - debugPrint('Already latest version'); + debugPrint('[SelfHostedUpdater] 已是最新版本,无需更新'); return; } + debugPrint('[SelfHostedUpdater] 发现新版本: ${versionInfo.version}, versionCode: ${versionInfo.versionCode}'); + if (!context.mounted) return; // 检测安装来源 diff --git a/frontend/mobile-app/lib/core/updater/version_checker.dart b/frontend/mobile-app/lib/core/updater/version_checker.dart index 2c46c189..6c8fe9dc 100644 --- a/frontend/mobile-app/lib/core/updater/version_checker.dart +++ b/frontend/mobile-app/lib/core/updater/version_checker.dart @@ -25,6 +25,8 @@ class VersionChecker { Future fetchLatestVersion() async { try { final currentInfo = await getCurrentVersion(); + debugPrint('[VersionChecker] 当前版本: ${currentInfo.version}, buildNumber: ${currentInfo.buildNumber}'); + debugPrint('[VersionChecker] API URL: $apiBaseUrl/api/app/version/check'); final response = await _dio.get( '/api/app/version/check', @@ -35,17 +37,22 @@ class VersionChecker { }, ); + debugPrint('[VersionChecker] 响应状态: ${response.statusCode}'); + debugPrint('[VersionChecker] 响应数据: ${response.data}'); + if (response.statusCode == 200 && response.data != null) { // 检查是否需要更新 final needUpdate = response.data['needUpdate'] as bool? ?? true; if (!needUpdate) { + debugPrint('[VersionChecker] 服务器返回无需更新'); return null; } + debugPrint('[VersionChecker] 服务器返回需要更新'); return VersionInfo.fromJson(response.data); } return null; } catch (e) { - debugPrint('Fetch version failed: $e'); + debugPrint('[VersionChecker] 获取版本失败: $e'); return null; } } diff --git a/frontend/mobile-app/lib/features/auth/presentation/pages/splash_page.dart b/frontend/mobile-app/lib/features/auth/presentation/pages/splash_page.dart index 5fbfb918..484c4595 100644 --- a/frontend/mobile-app/lib/features/auth/presentation/pages/splash_page.dart +++ b/frontend/mobile-app/lib/features/auth/presentation/pages/splash_page.dart @@ -69,14 +69,8 @@ class _SplashPageState extends ConsumerState { context.go(RoutePaths.onboarding); } - // 获取目标路由用于后续检查 - final targetRoute = authState.isWalletCreated ? RoutePaths.ranking : null; - - // 延迟检查应用更新(跳转后执行,避免阻塞启动) - if (targetRoute == RoutePaths.ranking) { - // 只在进入主页面时检查更新 - checkForAppUpdate(context); - } + // 总是检查应用更新(跳转后执行,避免阻塞启动) + checkForAppUpdate(context); } @override