From 4c811c9c04d6f185f02f46dc70e08843cf3136b8 Mon Sep 17 00:00:00 2001 From: Imran Remtulla Date: Sat, 30 Sep 2023 10:12:49 -0400 Subject: [PATCH] "Naive" version detection for some Sources (#946) --- lib/app_sources/apkpure.dart | 1 + lib/app_sources/aptoide.dart | 1 + lib/app_sources/uptodown.dart | 1 + lib/providers/apps_provider.dart | 40 ++++++++++++++++++++---------- lib/providers/source_provider.dart | 1 + 5 files changed, 31 insertions(+), 13 deletions(-) diff --git a/lib/app_sources/apkpure.dart b/lib/app_sources/apkpure.dart index d22e9a6..a86fa0d 100644 --- a/lib/app_sources/apkpure.dart +++ b/lib/app_sources/apkpure.dart @@ -22,6 +22,7 @@ class APKPure extends AppSource { APKPure() { host = 'apkpure.com'; allowSubDomains = true; + naiveStandardVersionDetection = true; } @override diff --git a/lib/app_sources/aptoide.dart b/lib/app_sources/aptoide.dart index 9543464..5b92b33 100644 --- a/lib/app_sources/aptoide.dart +++ b/lib/app_sources/aptoide.dart @@ -9,6 +9,7 @@ class Aptoide extends AppSource { host = 'aptoide.com'; name = tr('Aptoide'); allowSubDomains = true; + naiveStandardVersionDetection = true; } @override diff --git a/lib/app_sources/uptodown.dart b/lib/app_sources/uptodown.dart index dd9b68a..7b36cc3 100644 --- a/lib/app_sources/uptodown.dart +++ b/lib/app_sources/uptodown.dart @@ -8,6 +8,7 @@ class Uptodown extends AppSource { Uptodown() { host = 'uptodown.com'; allowSubDomains = true; + naiveStandardVersionDetection = true; } @override diff --git a/lib/providers/apps_provider.dart b/lib/providers/apps_provider.dart index a8c6fdf..2dc7498 100644 --- a/lib/providers/apps_provider.dart +++ b/lib/providers/apps_provider.dart @@ -709,14 +709,21 @@ class AppsProvider with ChangeNotifier { } bool isVersionDetectionPossible(AppInMemory? app) { - return app?.app.additionalSettings['trackOnly'] != true && - app?.app.additionalSettings['versionDetection'] != + if (app?.app == null) { + return false; + } + var naiveStandardVersionDetection = SourceProvider() + .getSource(app!.app.url, overrideSource: app.app.overrideSource) + .naiveStandardVersionDetection; + return app.app.additionalSettings['trackOnly'] != true && + app.app.additionalSettings['versionDetection'] != 'releaseDateAsVersion' && - app?.installedInfo?.versionName != null && - app?.app.installedVersion != null && - reconcileVersionDifferences( - app!.installedInfo!.versionName!, app.app.installedVersion!) != - null; + app.installedInfo?.versionName != null && + app.app.installedVersion != null && + (reconcileVersionDifferences(app.installedInfo!.versionName!, + app.app.installedVersion!) != + null || + naiveStandardVersionDetection); } // Given an App and it's on-device info... @@ -725,8 +732,13 @@ class AppsProvider with ChangeNotifier { App app, PackageInfo? installedInfo) { var modded = false; var trackOnly = app.additionalSettings['trackOnly'] == true; - var noVersionDetection = app.additionalSettings['versionDetection'] != - 'standardVersionDetection'; + var versionDetectionIsStandard = + app.additionalSettings['versionDetection'] == + 'standardVersionDetection'; + var naiveStandardVersionDetection = SourceProvider() + .getSource(app.url, overrideSource: app.overrideSource) + .naiveStandardVersionDetection; + ; // FIRST, COMPARE THE APP'S REPORTED AND REAL INSTALLED VERSIONS, WHERE ONE IS NULL if (installedInfo == null && app.installedVersion != null && !trackOnly) { // App says it's installed but isn't really (and isn't track only) - set to not installed @@ -741,7 +753,7 @@ class AppsProvider with ChangeNotifier { // SECOND, RECONCILE DIFFERENCES BETWEEN THE APP'S REPORTED AND REAL INSTALLED VERSIONS, WHERE NEITHER IS NULL if (installedInfo?.versionName != null && installedInfo!.versionName != app.installedVersion && - !noVersionDetection) { + versionDetectionIsStandard) { // App's reported version and real version don't match (and it uses standard version detection) // If they share a standard format (and are still different under it), update the reported version accordingly var correctedInstalledVersion = reconcileVersionDifferences( @@ -749,12 +761,15 @@ class AppsProvider with ChangeNotifier { if (correctedInstalledVersion?.key == false) { app.installedVersion = correctedInstalledVersion!.value; modded = true; + } else if (naiveStandardVersionDetection) { + app.installedVersion = installedInfo.versionName; + modded = true; } } // THIRD, RECONCILE THE APP'S REPORTED INSTALLED AND LATEST VERSIONS if (app.installedVersion != null && app.installedVersion != app.latestVersion && - !noVersionDetection) { + versionDetectionIsStandard) { // App's reported installed and latest versions don't match (and it uses standard version detection) // If they share a standard format, make sure the App's reported installed version uses that format var correctedInstalledVersion = @@ -766,8 +781,7 @@ class AppsProvider with ChangeNotifier { } // FOURTH, DISABLE VERSION DETECTION IF ENABLED AND THE REPORTED/REAL INSTALLED VERSIONS ARE NOT STANDARDIZED if (installedInfo != null && - app.additionalSettings['versionDetection'] == - 'standardVersionDetection' && + versionDetectionIsStandard && !isVersionDetectionPossible( AppInMemory(app, null, installedInfo, null))) { app.additionalSettings['versionDetection'] = 'noVersionDetection'; diff --git a/lib/providers/source_provider.dart b/lib/providers/source_provider.dart index 43a0f1e..b4b732f 100644 --- a/lib/providers/source_provider.dart +++ b/lib/providers/source_provider.dart @@ -328,6 +328,7 @@ abstract class AppSource { bool changeLogIfAnyIsMarkDown = true; bool appIdInferIsOptional = false; bool allowSubDomains = false; + bool naiveStandardVersionDetection = false; AppSource() { name = runtimeType.toString();