diff --git a/lib/main.dart b/lib/main.dart index d00f485..1605cdd 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -161,6 +161,7 @@ class _ObtainiumState extends State { ['true'], null, false, + false, false) ]); } diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index 7ade187..26702a6 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -401,9 +401,9 @@ class AppsProvider with ChangeNotifier { } // If the App says it is installed but installedInfo is null, set it to not installed - // If the App says is is not installed but installedInfo exists, try to set it to installed as latest version... - // ...if the latestVersion seems to match the version in installedInfo (not guaranteed) - // If that fails, just set it to the actual version string (all we can do at that point) + // If the App says is is not installed but installedInfo exists, set it to the real installed version + // If the internal version does not match the real one, sync them if the App supports enhanced version detection + // Enhanced version detection will be true if the version extracted from source matches the standard version format // Don't save changes, just return the object if changes were made (else null) // If in a background isolate, return null straight away as the required plugin won't work anyways App? getCorrectedInstallStatusAppIfPossible(App app, AppInfo? installedInfo) { @@ -416,29 +416,12 @@ class AppsProvider with ChangeNotifier { !app.trackOnly) { app.installedVersion = null; modded = true; - } - if (installedInfo != null && app.installedVersion == null) { - if (app.latestVersion.characters - .where((p0) => [ - // TODO: Won't work for other charsets - '0', - '1', - '2', - '3', - '4', - '5', - '6', - '7', - '8', - '9', - '.' - ].contains(p0)) - .join('') == - installedInfo.versionName) { - app.installedVersion = app.latestVersion; - } else { - app.installedVersion = installedInfo.versionName; - } + } else if (installedInfo != null && app.installedVersion == null) { + app.installedVersion = installedInfo.versionName; + modded = true; + } else if (installedInfo?.versionName != app.installedVersion && + app.enhancedVersionDetection) { + app.installedVersion = installedInfo?.versionName; modded = true; } return modded ? app : null; diff --git a/lib/providers/source_provider.dart b/lib/providers/source_provider.dart index ac192a8..0a01a2c 100644 --- a/lib/providers/source_provider.dart +++ b/lib/providers/source_provider.dart @@ -28,8 +28,15 @@ class AppNames { class APKDetails { late String version; late List apkUrls; + late bool isStandardVersionName; - APKDetails(this.version, this.apkUrls); + APKDetails(this.version, this.apkUrls) { + var standardVersion = extractStandardVersionName(version); + isStandardVersionName = standardVersion != null; + if (isStandardVersionName) { + version = standardVersion!; + } + } } class App { @@ -45,6 +52,7 @@ class App { late DateTime? lastUpdateCheck; bool pinned = false; bool trackOnly = false; + bool enhancedVersionDetection = true; App( this.id, this.url, @@ -57,7 +65,8 @@ class App { this.additionalData, this.lastUpdateCheck, this.pinned, - this.trackOnly); + this.trackOnly, + this.enhancedVersionDetection); @override String toString() { @@ -86,7 +95,8 @@ class App { ? null : DateTime.fromMicrosecondsSinceEpoch(json['lastUpdateCheck']), json['pinned'] ?? false, - json['trackOnly'] ?? false); + json['trackOnly'] ?? false, + json['enhancedVersionDetection'] ?? true); Map toJson() => { 'id': id, @@ -100,7 +110,8 @@ class App { 'additionalData': jsonEncode(additionalData), 'lastUpdateCheck': lastUpdateCheck?.microsecondsSinceEpoch, 'pinned': pinned, - 'trackOnly': trackOnly + 'trackOnly': trackOnly, + 'enhancedVersionDetection': enhancedVersionDetection }; } @@ -190,6 +201,11 @@ ObtainiumError getObtainiumHttpError(Response res) { tr('errorWithHttpStatusCode', args: [res.statusCode.toString()])); } +String? extractStandardVersionName(String version) { + var match = RegExp('[0-9]+(\\.[0-9]+)*').firstMatch(version); + return match != null ? version.substring(match.start, match.end) : null; +} + abstract class MassAppUrlSource { late String name; late List requiredArgs; @@ -285,7 +301,8 @@ class SourceProvider { additionalData, DateTime.now(), pinned, - trackOnly); + trackOnly, + apk.isStandardVersionName); } // Returns errors in [results, errors] instead of throwing them