Browse Source

fix(version): 修复版本更新检查逻辑bug

weicu
lxm 1 year ago
parent
commit
835bf79ab5
  1. 35
      lib/data/services/version_update_service.dart
  2. 2
      lib/modules/splash/controllers/splash_controller.dart

35
lib/data/services/version_update_service.dart

@ -174,23 +174,26 @@ class VersionUpdateService extends GetxService {
/// 比较版本号 /// 比较版本号
/// 返回true表示需要更新(远程版本更高) /// 返回true表示需要更新(远程版本更高)
bool _compareVersions(String currentVersion, String remoteVersion) { bool _compareVersions(String current, String latest) {
try { // 拆分版本号与构建号
final current = _parseVersion(currentVersion); final currentParts = current.split('+');
final remote = _parseVersion(remoteVersion); final latestParts = latest.split('+');
for (int i = 0; i < 3; i++) { // 解析版本号 (major.minor.patch)
if (remote[i] > current[i]) { final currentVersions = currentParts[0].split('.').map(int.parse).toList();
return true; final latestVersions = latestParts[0].split('.').map(int.parse).toList();
} else if (remote[i] < current[i]) {
return false; // 逐级比较版本号
} for (var i = 0; i < currentVersions.length; i++) {
} if (latestVersions[i] > currentVersions[i]) return true;
return false; // 版本相同 if (latestVersions[i] < currentVersions[i]) return false;
} catch (e) { }
_logger.e('版本比较失败: $e');
return false; // 版本号相同则比较构建号
if (latestParts.length > 1 && currentParts.length > 1) {
return int.parse(latestParts[1]) > int.parse(currentParts[1]);
} }
return false;
} }
/// 解析版本号字符串为数字数组 /// 解析版本号字符串为数字数组

2
lib/modules/splash/controllers/splash_controller.dart

@ -160,7 +160,7 @@ class SplashController extends GetxController {
/// 检查版本更新(后台执行,不阻塞启动流程) /// 检查版本更新(后台执行,不阻塞启动流程)
void _checkVersionUpdate() { void _checkVersionUpdate() {
// 延迟执行版本检查,避免影响启动速度 // 延迟执行版本检查,避免影响启动速度
Timer(const Duration(seconds: 2), () async { Timer(const Duration(seconds: 1), () async {
try { try {
final versionService = VersionUpdateService.to; final versionService = VersionUpdateService.to;
final updateInfo = await versionService.checkForUpdate(); final updateInfo = await versionService.checkForUpdate();

Loading…
Cancel
Save