No need update check for web

This commit is contained in:
2026-03-12 20:38:19 +08:00
parent 0bd2a94ece
commit 9267ebee2c
5 changed files with 83 additions and 31 deletions
+34 -11
View File
@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:ota_update/ota_update.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:pub_semver/pub_semver.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
@@ -48,26 +49,48 @@ class AppUpdateService {
/// (network down, no supabase instance) are simply rethrown; the caller can
/// decide whether to ignore them or surface them to the user.
Future<AppUpdateInfo> checkForUpdate() async {
final pkg = await PackageInfo.fromPlatform();
final currentBuild = int.tryParse(pkg.buildNumber) ?? 0;
final serverVersion = await _fetchLatestVersion();
if (serverVersion == null) {
// table empty nothing to do
// only run on Android devices; web and other platforms skip
if (!Platform.isAndroid) {
return AppUpdateInfo(
currentBuildNumber: currentBuild,
currentBuildNumber: '',
latestVersion: null,
isUpdateAvailable: false,
isForceUpdate: false,
);
}
final available = currentBuild < serverVersion.versionCode;
final force = currentBuild < serverVersion.minVersionRequired;
final pkg = await PackageInfo.fromPlatform();
final currentVersion = pkg.buildNumber.trim();
final serverVersion = await _fetchLatestVersion();
if (serverVersion == null) {
return AppUpdateInfo(
currentBuildNumber: currentVersion,
latestVersion: null,
isUpdateAvailable: false,
isForceUpdate: false,
);
}
// compare using semantic versioning where possible
Version safeParse(String s) {
try {
return Version.parse(s);
} catch (_) {
return Version(0, 0, 0);
}
}
final vCurrent = safeParse(currentVersion);
final vLatest = safeParse(serverVersion.versionCode);
final vMin = safeParse(serverVersion.minVersionRequired);
final available = vCurrent < vLatest;
final force = vCurrent < vMin;
return AppUpdateInfo(
currentBuildNumber: currentBuild,
currentBuildNumber: currentVersion,
latestVersion: serverVersion,
isUpdateAvailable: available,
isForceUpdate: force,