From e7bf178f6bac14dd6b8c7866f6a84b2b1c2dc8d7 Mon Sep 17 00:00:00 2001 From: lxm <1274844347@qq.com> Date: Sat, 20 Dec 2025 17:54:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor(version=5Fupdate):=20=E7=AE=80?= =?UTF-8?q?=E5=8C=96=E6=B8=A0=E9=81=93=E5=BA=94=E7=94=A8=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 移除_getChannelAppInfo方法,直接使用品牌渠道或环境渠道信息 --- lib/data/services/version_update_service.dart | 42 +++++++------------ 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/lib/data/services/version_update_service.dart b/lib/data/services/version_update_service.dart index b25f861b2..106e0d9a7 100644 --- a/lib/data/services/version_update_service.dart +++ b/lib/data/services/version_update_service.dart @@ -147,14 +147,14 @@ class VersionUpdateService extends GetxService { final brandChannel = platformInfo.channel; // 环境变量渠道用于游客登录配置 - final envChannelName = dotenv.env['Channel'] ?? 'OFFICIAL'; - final envChannel = UserChannel.fromName(envChannelName); + // final envChannelName = dotenv.env['Channel'] ?? 'OFFICIAL'; + final envChannel = _channel; final AppInfo? envAppInfo = appIndex[envChannel]; // 若不存在品牌渠道信息,降级为环境渠道;仍不存在则返回无更新 - final AppInfo? chosenAppInfo = - _getChannelAppInfo(appIndex, brandChannel, envChannel); - if (chosenAppInfo == null) { + final AppInfo? brandAppInfo = appIndex[brandChannel] ?? envAppInfo; + + if (brandAppInfo == null) { _logger.w('lxm--未找到品牌或环境渠道的应用信息,返回无更新'); return VersionUpdateInfo( hasUpdate: false, @@ -164,14 +164,14 @@ class VersionUpdateService extends GetxService { ); } - _appInfo = chosenAppInfo; - _latestVersion = chosenAppInfo.version; - _updateUrl = chosenAppInfo.address; + _appInfo = brandAppInfo; + _latestVersion = brandAppInfo.version; + _updateUrl = brandAppInfo.address; // 设置游客登录显示状态(先用当前渠道结果作为回退,再用.env渠道覆盖以保持一致) - _isShowTourists = (envAppInfo ?? chosenAppInfo).tourists; + _isShowTourists = (envAppInfo ?? brandAppInfo).tourists; _allowSkipDeviceBinding = - (envAppInfo ?? chosenAppInfo).allowskipdevicebinding; + (envAppInfo ?? brandAppInfo).allowskipdevicebinding; _logger.d('lxm--从服务器获取游客登录配置(最终): ${_isShowTourists}'); @@ -186,21 +186,21 @@ class VersionUpdateService extends GetxService { // } // final appInfo = channelAppResponse.data!.app; - _hasUpdate = _compareVersions(currentVersion, chosenAppInfo.version); + _hasUpdate = _compareVersions(currentVersion, brandAppInfo.version); // 判断更新类型:如果主版本号不同则强制更新 UpdateType updateType = UpdateType.none; if (_hasUpdate!) { _isForceUpdate = - _shouldForceUpdate(currentVersion, chosenAppInfo.version); + _shouldForceUpdate(currentVersion, brandAppInfo.version); updateType = _isForceUpdate! ? UpdateType.force : UpdateType.optional; } //[3]返回版本更新信息 return VersionUpdateInfo( hasUpdate: _hasUpdate!, currentVersion: currentVersion.split('+')[0], - latestVersion: chosenAppInfo.version.split('+')[0], - appInfo: chosenAppInfo, + latestVersion: brandAppInfo.version.split('+')[0], + appInfo: brandAppInfo, updateType: updateType, ); } catch (e) { @@ -427,20 +427,6 @@ class VersionUpdateService extends GetxService { return index; } - /// 获取渠道信息,带备选策略 - /// - /// 优先返回主渠道的信息,如果主渠道不存在则返回备选渠道的信息。 - /// 主要用于: - /// 1. 版本更新:优先使用设备品牌渠道,备选使用环境变量渠道 - /// 2. 功能配置:优先使用环境变量渠道,备选使用版本更新渠道 - AppInfo? _getChannelAppInfo( - Map index, - UserChannel primary, - UserChannel? fallback, - ) { - return index[primary] ?? (fallback != null ? index[fallback] : null); - } - /// 解析版本号字符串为数字数组 List _parseVersion(String version) { final parts = version.split('.');