mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-28 20:13:28 +01:00 
			
		
		
		
	Attempting to add enhanced version detection #132
This commit is contained in:
		| @@ -161,6 +161,7 @@ class _ObtainiumState extends State<Obtainium> { | ||||
|               ['true'], | ||||
|               null, | ||||
|               false, | ||||
|               false, | ||||
|               false) | ||||
|         ]); | ||||
|       } | ||||
|   | ||||
| @@ -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; | ||||
|   | ||||
| @@ -28,8 +28,15 @@ class AppNames { | ||||
| class APKDetails { | ||||
|   late String version; | ||||
|   late List<String> 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<String, dynamic> 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<String> requiredArgs; | ||||
| @@ -285,7 +301,8 @@ class SourceProvider { | ||||
|         additionalData, | ||||
|         DateTime.now(), | ||||
|         pinned, | ||||
|         trackOnly); | ||||
|         trackOnly, | ||||
|         apk.isStandardVersionName); | ||||
|   } | ||||
|  | ||||
|   // Returns errors in [results, errors] instead of throwing them | ||||
|   | ||||
		Reference in New Issue
	
	Block a user