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表示需要更新(远程版本更高)
bool _compareVersions(String currentVersion, String remoteVersion) {
try {
final current = _parseVersion(currentVersion);
final remote = _parseVersion(remoteVersion);
for (int i = 0; i < 3; i++) {
if (remote[i] > current[i]) {
return true;
} else if (remote[i] < current[i]) {
return false;
}
}
return false; // 版本相同
} catch (e) {
_logger.e('版本比较失败: $e');
return false;
bool _compareVersions(String current, String latest) {
// 拆分版本号与构建号
final currentParts = current.split('+');
final latestParts = latest.split('+');
// 解析版本号 (major.minor.patch)
final currentVersions = currentParts[0].split('.').map(int.parse).toList();
final latestVersions = latestParts[0].split('.').map(int.parse).toList();
// 逐级比较版本号
for (var i = 0; i < currentVersions.length; i++) {
if (latestVersions[i] > currentVersions[i]) return true;
if (latestVersions[i] < currentVersions[i]) 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() {
// 延迟执行版本检查,避免影响启动速度
Timer(const Duration(seconds: 2), () async {
Timer(const Duration(seconds: 1), () async {
try {
final versionService = VersionUpdateService.to;
final updateInfo = await versionService.checkForUpdate();

Loading…
Cancel
Save