Browse Source

Merge branch 'new_dev' of https://github.com/deepcloud2048/deep_voice into new_dev

newdev_shunjiawei
tanlongsheng 10 months ago
parent
commit
db499803f1
  1. 42
      lib/data/services/version_update_service.dart

42
lib/data/services/version_update_service.dart

@ -147,14 +147,14 @@ class VersionUpdateService extends GetxService {
final brandChannel = platformInfo.channel; final brandChannel = platformInfo.channel;
// 环境变量渠道用于游客登录配置 // 环境变量渠道用于游客登录配置
final envChannelName = dotenv.env['Channel'] ?? 'OFFICIAL'; // final envChannelName = dotenv.env['Channel'] ?? 'OFFICIAL';
final envChannel = UserChannel.fromName(envChannelName); final envChannel = _channel;
final AppInfo? envAppInfo = appIndex[envChannel]; final AppInfo? envAppInfo = appIndex[envChannel];
// 若不存在品牌渠道信息,降级为环境渠道;仍不存在则返回无更新 // 若不存在品牌渠道信息,降级为环境渠道;仍不存在则返回无更新
final AppInfo? chosenAppInfo = final AppInfo? brandAppInfo = appIndex[brandChannel] ?? envAppInfo;
_getChannelAppInfo(appIndex, brandChannel, envChannel);
if (chosenAppInfo == null) { if (brandAppInfo == null) {
_logger.w('lxm--未找到品牌或环境渠道的应用信息,返回无更新'); _logger.w('lxm--未找到品牌或环境渠道的应用信息,返回无更新');
return VersionUpdateInfo( return VersionUpdateInfo(
hasUpdate: false, hasUpdate: false,
@ -164,14 +164,14 @@ class VersionUpdateService extends GetxService {
); );
} }
_appInfo = chosenAppInfo; _appInfo = brandAppInfo;
_latestVersion = chosenAppInfo.version; _latestVersion = brandAppInfo.version;
_updateUrl = chosenAppInfo.address; _updateUrl = brandAppInfo.address;
// 设置游客登录显示状态(先用当前渠道结果作为回退,再用.env渠道覆盖以保持一致) // 设置游客登录显示状态(先用当前渠道结果作为回退,再用.env渠道覆盖以保持一致)
_isShowTourists = (envAppInfo ?? chosenAppInfo).tourists; _isShowTourists = (envAppInfo ?? brandAppInfo).tourists;
_allowSkipDeviceBinding = _allowSkipDeviceBinding =
(envAppInfo ?? chosenAppInfo).allowskipdevicebinding; (envAppInfo ?? brandAppInfo).allowskipdevicebinding;
_logger.d('lxm--从服务器获取游客登录配置(最终): ${_isShowTourists}'); _logger.d('lxm--从服务器获取游客登录配置(最终): ${_isShowTourists}');
@ -186,21 +186,21 @@ class VersionUpdateService extends GetxService {
// } // }
// final appInfo = channelAppResponse.data!.app; // final appInfo = channelAppResponse.data!.app;
_hasUpdate = _compareVersions(currentVersion, chosenAppInfo.version); _hasUpdate = _compareVersions(currentVersion, brandAppInfo.version);
// 判断更新类型:如果主版本号不同则强制更新 // 判断更新类型:如果主版本号不同则强制更新
UpdateType updateType = UpdateType.none; UpdateType updateType = UpdateType.none;
if (_hasUpdate!) { if (_hasUpdate!) {
_isForceUpdate = _isForceUpdate =
_shouldForceUpdate(currentVersion, chosenAppInfo.version); _shouldForceUpdate(currentVersion, brandAppInfo.version);
updateType = _isForceUpdate! ? UpdateType.force : UpdateType.optional; updateType = _isForceUpdate! ? UpdateType.force : UpdateType.optional;
} }
//[3]返回版本更新信息 //[3]返回版本更新信息
return VersionUpdateInfo( return VersionUpdateInfo(
hasUpdate: _hasUpdate!, hasUpdate: _hasUpdate!,
currentVersion: currentVersion.split('+')[0], currentVersion: currentVersion.split('+')[0],
latestVersion: chosenAppInfo.version.split('+')[0], latestVersion: brandAppInfo.version.split('+')[0],
appInfo: chosenAppInfo, appInfo: brandAppInfo,
updateType: updateType, updateType: updateType,
); );
} catch (e) { } catch (e) {
@ -427,20 +427,6 @@ class VersionUpdateService extends GetxService {
return index; return index;
} }
/// 获取渠道信息,带备选策略
///
/// 优先返回主渠道的信息,如果主渠道不存在则返回备选渠道的信息。
/// 主要用于:
/// 1. 版本更新:优先使用设备品牌渠道,备选使用环境变量渠道
/// 2. 功能配置:优先使用环境变量渠道,备选使用版本更新渠道
AppInfo? _getChannelAppInfo(
Map<UserChannel, AppInfo> index,
UserChannel primary,
UserChannel? fallback,
) {
return index[primary] ?? (fallback != null ? index[fallback] : null);
}
/// 解析版本号字符串为数字数组 /// 解析版本号字符串为数字数组
List<int> _parseVersion(String version) { List<int> _parseVersion(String version) {
final parts = version.split('.'); final parts = version.split('.');

Loading…
Cancel
Save