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');