From a7975f08b923116bb9034d11b22ab069d3ca86fa Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Thu, 28 Aug 2025 22:22:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(version=5Fupdate):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=BF=A1=E6=81=AF=E7=BC=93=E5=AD=98=E5=8F=8A?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 添加_appInfo静态变量缓存应用信息并增加相关getter方法 在关键流程中添加调试日志输出以便排查问题 --- lib/data/services/version_update_service.dart | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/data/services/version_update_service.dart b/lib/data/services/version_update_service.dart index a15251857..23be2291b 100644 --- a/lib/data/services/version_update_service.dart +++ b/lib/data/services/version_update_service.dart @@ -24,6 +24,7 @@ class VersionUpdateService extends GetxService { static bool? _hasUpdate = false; //是否有更新 static bool? _isForceUpdate = false; //是否强制更新 static String? _updateUrl = ""; //更新链接 + static AppInfo? _appInfo; //应用信息 static bool? _isShowTourists = false; //是否显示游客登录 static DateTime? _lastCheckTime; //上次检查时间 static const int _cacheIntervalMinutes = 10; // 可配置化 @@ -62,6 +63,9 @@ class VersionUpdateService extends GetxService { /// 获取缓存的更新地址 String get cachedUpdateUrl => _updateUrl ?? ''; + /// 获取缓存的应用信息 + AppInfo? get cachedAppInfo => _appInfo; + /// 获取缓存的游客登录状态 bool get cachedShowTourists => _isShowTourists ?? false; @@ -183,10 +187,13 @@ class VersionUpdateService extends GetxService { if (_lastCheckTime != null && DateTime.now().difference(_lastCheckTime!).inMinutes < _cacheIntervalMinutes) { + // [1]没有超过10分钟,返回缓存数据 + _logger.d('没有超过10分钟,返回缓存数据'); return VersionUpdateInfo( hasUpdate: _hasUpdate ?? false, currentVersion: _appVersion ?? '1.0.0', latestVersion: (_latestVersion ?? '1.0.0').split('+')[0], + appInfo: _appInfo, updateType: _hasUpdate! ? (_isForceUpdate! ? UpdateType.force : UpdateType.optional) : UpdateType.none, @@ -208,6 +215,8 @@ class VersionUpdateService extends GetxService { _logger.d('获取渠道包信息:$response'); if (response == null || !response.containsKey('app')) { + //[2]获取渠道包信息失败: 响应为空或不包含app字段 + _logger.w('获取渠道包信息失败: 响应为空或不包含app字段'); return VersionUpdateInfo( hasUpdate: false, currentVersion: currentVersion, @@ -219,6 +228,7 @@ class VersionUpdateService extends GetxService { //final channelAppResponse = ChannelAppResponse.fromJson(response); // 直接从response中获取app信息 final appInfo = AppInfo.fromJson(response['app']); + _appInfo = appInfo; _logger.d('获取到的最新版本信息: ${appInfo.toJson()}'); _latestVersion = appInfo.version; _updateUrl = appInfo.address; @@ -246,7 +256,7 @@ class VersionUpdateService extends GetxService { _isForceUpdate = _shouldForceUpdate(currentVersion, appInfo.version); updateType = _isForceUpdate! ? UpdateType.force : UpdateType.optional; } - + //[3]返回版本更新信息 return VersionUpdateInfo( hasUpdate: _hasUpdate!, currentVersion: currentVersion.split('+')[0], @@ -343,11 +353,18 @@ class VersionUpdateService extends GetxService { /// 执行更新操作 Future performUpdate(VersionUpdateInfo updateInfo) async { + print('lxm---updateInfo详情:'); + print('lxm---hasUpdate: ${updateInfo.hasUpdate}'); + print('lxm---currentVersion: ${updateInfo.currentVersion}'); + print('lxm---latestVersion: ${updateInfo.latestVersion}'); + print('lxm---updateType: ${updateInfo.updateType}'); + print('lxm---appInfo: ${updateInfo.appInfo?.toJson()}'); if (!updateInfo.hasUpdate || updateInfo.appInfo == null) { return false; } try { + _logger.d('lxm---执行更新操作,下载地址: ${updateInfo.appInfo!.address}'); return await _openDownloadUrl(updateInfo.appInfo!.address!); } catch (e) { _logger.e('执行更新失败: $e');