|
|
|
@ -14,6 +14,9 @@ class VersionUpdateService extends GetxService { |
|
|
|
|
|
|
|
final Logger _logger = Logger(); |
|
|
|
|
|
|
|
// 游客登录显示状态 |
|
|
|
final isShowTourists = false.obs; |
|
|
|
|
|
|
|
/// 获取当前应用版本信息 |
|
|
|
Future<String> getCurrentVersion() async { |
|
|
|
try { |
|
|
|
@ -31,7 +34,7 @@ class VersionUpdateService extends GetxService { |
|
|
|
return const PlatformInfo( |
|
|
|
platform: 'web', |
|
|
|
storeType: AppStoreType.official, |
|
|
|
channel: '官方网站', |
|
|
|
channel: UserChannel.OFFICIAL, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@ -39,7 +42,7 @@ class VersionUpdateService extends GetxService { |
|
|
|
return const PlatformInfo( |
|
|
|
platform: 'ios', |
|
|
|
storeType: AppStoreType.appStore, |
|
|
|
channel: 'App Store', |
|
|
|
channel: UserChannel.GLOBAL_APPLE, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@ -51,7 +54,7 @@ class VersionUpdateService extends GetxService { |
|
|
|
return const PlatformInfo( |
|
|
|
platform: 'unknown', |
|
|
|
storeType: AppStoreType.unknown, |
|
|
|
channel: '未知', |
|
|
|
channel: UserChannel.UNKNOWN, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
@ -65,7 +68,7 @@ class VersionUpdateService extends GetxService { |
|
|
|
return const PlatformInfo( |
|
|
|
platform: 'android', |
|
|
|
storeType: AppStoreType.official, |
|
|
|
channel: 'officialTesting', |
|
|
|
channel: UserChannel.OFFICIAL, |
|
|
|
); |
|
|
|
|
|
|
|
// switch (brand) { |
|
|
|
@ -110,7 +113,7 @@ class VersionUpdateService extends GetxService { |
|
|
|
return const PlatformInfo( |
|
|
|
platform: 'android', |
|
|
|
storeType: AppStoreType.googlePlay, |
|
|
|
channel: 'Google Play', |
|
|
|
channel: UserChannel.UNKNOWN, |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -123,7 +126,7 @@ class VersionUpdateService extends GetxService { |
|
|
|
|
|
|
|
// 调用后端接口获取最新版本信息 |
|
|
|
final response = |
|
|
|
await Api.getChannelApp({'channel': platformInfo.channel}); |
|
|
|
await Api.getChannelApp({'channel': platformInfo.channel.value}); |
|
|
|
|
|
|
|
print('获取渠道包信息:$response'); |
|
|
|
|
|
|
|
@ -140,6 +143,10 @@ class VersionUpdateService extends GetxService { |
|
|
|
// 直接从response中获取app信息 |
|
|
|
final appInfo = AppInfo.fromJson(response['app']); |
|
|
|
|
|
|
|
// 设置游客登录显示状态 |
|
|
|
isShowTourists.value = appInfo.tourists; |
|
|
|
_logger.d('从服务器获取游客登录配置: ${appInfo.tourists}'); |
|
|
|
|
|
|
|
// if (channelAppResponse.code != 0 || channelAppResponse.data == null) { |
|
|
|
// _logger.w('获取版本信息失败: ${channelAppResponse.msg}'); |
|
|
|
// return VersionUpdateInfo( |
|
|
|
@ -152,7 +159,6 @@ class VersionUpdateService extends GetxService { |
|
|
|
|
|
|
|
// final appInfo = channelAppResponse.data!.app; |
|
|
|
final hasUpdate = _compareVersions(currentVersion, appInfo.version); |
|
|
|
//final isShowTourists = appInfo.tourists; // 获取是否显示游客登录的标志 |
|
|
|
|
|
|
|
return VersionUpdateInfo( |
|
|
|
hasUpdate: hasUpdate, |
|
|
|
@ -163,6 +169,8 @@ class VersionUpdateService extends GetxService { |
|
|
|
); |
|
|
|
} catch (e) { |
|
|
|
_logger.e('检查版本更新失败: $e'); |
|
|
|
// 发生错误时,保持默认值 false |
|
|
|
isShowTourists.value = false; |
|
|
|
final currentVersion = await getCurrentVersion(); |
|
|
|
return VersionUpdateInfo( |
|
|
|
hasUpdate: false, |
|
|
|
@ -238,9 +246,9 @@ class VersionUpdateService extends GetxService { |
|
|
|
case AppStoreType.honor: |
|
|
|
return await _openHonorStore(); |
|
|
|
case AppStoreType.official: |
|
|
|
return await _openOfficialDownload(updateInfo.appInfo!.address); |
|
|
|
return await _openOfficialDownload(updateInfo.appInfo!.address!); |
|
|
|
default: |
|
|
|
return await _openOfficialDownload(updateInfo.appInfo!.address); |
|
|
|
return await _openOfficialDownload(updateInfo.appInfo!.address!); |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
_logger.e('执行更新失败: $e'); |
|
|
|
|