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