fix(mobile): always check for updates and add debug logs
- 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 <noreply@anthropic.com>
This commit is contained in:
parent
2ed1658c16
commit
53320df220
|
|
@ -19,13 +19,16 @@ class SelfHostedUpdater {
|
||||||
|
|
||||||
/// 检查并提示更新
|
/// 检查并提示更新
|
||||||
Future<void> checkAndPromptUpdate(BuildContext context) async {
|
Future<void> checkAndPromptUpdate(BuildContext context) async {
|
||||||
|
debugPrint('[SelfHostedUpdater] 开始检查更新...');
|
||||||
final versionInfo = await versionChecker.checkForUpdate();
|
final versionInfo = await versionChecker.checkForUpdate();
|
||||||
|
|
||||||
if (versionInfo == null) {
|
if (versionInfo == null) {
|
||||||
debugPrint('Already latest version');
|
debugPrint('[SelfHostedUpdater] 已是最新版本,无需更新');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debugPrint('[SelfHostedUpdater] 发现新版本: ${versionInfo.version}, versionCode: ${versionInfo.versionCode}');
|
||||||
|
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
|
|
||||||
// 检测安装来源
|
// 检测安装来源
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ class VersionChecker {
|
||||||
Future<VersionInfo?> fetchLatestVersion() async {
|
Future<VersionInfo?> fetchLatestVersion() async {
|
||||||
try {
|
try {
|
||||||
final currentInfo = await getCurrentVersion();
|
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(
|
final response = await _dio.get(
|
||||||
'/api/app/version/check',
|
'/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) {
|
if (response.statusCode == 200 && response.data != null) {
|
||||||
// 检查是否需要更新
|
// 检查是否需要更新
|
||||||
final needUpdate = response.data['needUpdate'] as bool? ?? true;
|
final needUpdate = response.data['needUpdate'] as bool? ?? true;
|
||||||
if (!needUpdate) {
|
if (!needUpdate) {
|
||||||
|
debugPrint('[VersionChecker] 服务器返回无需更新');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
debugPrint('[VersionChecker] 服务器返回需要更新');
|
||||||
return VersionInfo.fromJson(response.data);
|
return VersionInfo.fromJson(response.data);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('Fetch version failed: $e');
|
debugPrint('[VersionChecker] 获取版本失败: $e');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,14 +69,8 @@ class _SplashPageState extends ConsumerState<SplashPage> {
|
||||||
context.go(RoutePaths.onboarding);
|
context.go(RoutePaths.onboarding);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取目标路由用于后续检查
|
// 总是检查应用更新(跳转后执行,避免阻塞启动)
|
||||||
final targetRoute = authState.isWalletCreated ? RoutePaths.ranking : null;
|
checkForAppUpdate(context);
|
||||||
|
|
||||||
// 延迟检查应用更新(跳转后执行,避免阻塞启动)
|
|
||||||
if (targetRoute == RoutePaths.ranking) {
|
|
||||||
// 只在进入主页面时检查更新
|
|
||||||
checkForAppUpdate(context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue