mirror of
				https://github.com/ImranR98/Obtainium.git
				synced 2025-10-31 05:23: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'], |               ['true'], | ||||||
|               null, |               null, | ||||||
|               false, |               false, | ||||||
|  |               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 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 App says is is not installed but installedInfo exists, set it to the real installed version | ||||||
|   // ...if the latestVersion seems to match the version in installedInfo (not guaranteed) |   // If the internal version does not match the real one, sync them if the App supports enhanced version detection | ||||||
|   // If that fails, just set it to the actual version string (all we can do at that point) |   // 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) |   // 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 |   // If in a background isolate, return null straight away as the required plugin won't work anyways | ||||||
|   App? getCorrectedInstallStatusAppIfPossible(App app, AppInfo? installedInfo) { |   App? getCorrectedInstallStatusAppIfPossible(App app, AppInfo? installedInfo) { | ||||||
| @@ -416,29 +416,12 @@ class AppsProvider with ChangeNotifier { | |||||||
|         !app.trackOnly) { |         !app.trackOnly) { | ||||||
|       app.installedVersion = null; |       app.installedVersion = null; | ||||||
|       modded = true; |       modded = true; | ||||||
|     } |     } else if (installedInfo != null && app.installedVersion == null) { | ||||||
|     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; |       app.installedVersion = installedInfo.versionName; | ||||||
|       } |       modded = true; | ||||||
|  |     } else if (installedInfo?.versionName != app.installedVersion && | ||||||
|  |         app.enhancedVersionDetection) { | ||||||
|  |       app.installedVersion = installedInfo?.versionName; | ||||||
|       modded = true; |       modded = true; | ||||||
|     } |     } | ||||||
|     return modded ? app : null; |     return modded ? app : null; | ||||||
|   | |||||||
| @@ -28,8 +28,15 @@ class AppNames { | |||||||
| class APKDetails { | class APKDetails { | ||||||
|   late String version; |   late String version; | ||||||
|   late List<String> apkUrls; |   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 { | class App { | ||||||
| @@ -45,6 +52,7 @@ class App { | |||||||
|   late DateTime? lastUpdateCheck; |   late DateTime? lastUpdateCheck; | ||||||
|   bool pinned = false; |   bool pinned = false; | ||||||
|   bool trackOnly = false; |   bool trackOnly = false; | ||||||
|  |   bool enhancedVersionDetection = true; | ||||||
|   App( |   App( | ||||||
|       this.id, |       this.id, | ||||||
|       this.url, |       this.url, | ||||||
| @@ -57,7 +65,8 @@ class App { | |||||||
|       this.additionalData, |       this.additionalData, | ||||||
|       this.lastUpdateCheck, |       this.lastUpdateCheck, | ||||||
|       this.pinned, |       this.pinned, | ||||||
|       this.trackOnly); |       this.trackOnly, | ||||||
|  |       this.enhancedVersionDetection); | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   String toString() { |   String toString() { | ||||||
| @@ -86,7 +95,8 @@ class App { | |||||||
|           ? null |           ? null | ||||||
|           : DateTime.fromMicrosecondsSinceEpoch(json['lastUpdateCheck']), |           : DateTime.fromMicrosecondsSinceEpoch(json['lastUpdateCheck']), | ||||||
|       json['pinned'] ?? false, |       json['pinned'] ?? false, | ||||||
|       json['trackOnly'] ?? false); |       json['trackOnly'] ?? false, | ||||||
|  |       json['enhancedVersionDetection'] ?? true); | ||||||
|  |  | ||||||
|   Map<String, dynamic> toJson() => { |   Map<String, dynamic> toJson() => { | ||||||
|         'id': id, |         'id': id, | ||||||
| @@ -100,7 +110,8 @@ class App { | |||||||
|         'additionalData': jsonEncode(additionalData), |         'additionalData': jsonEncode(additionalData), | ||||||
|         'lastUpdateCheck': lastUpdateCheck?.microsecondsSinceEpoch, |         'lastUpdateCheck': lastUpdateCheck?.microsecondsSinceEpoch, | ||||||
|         'pinned': pinned, |         'pinned': pinned, | ||||||
|         'trackOnly': trackOnly |         'trackOnly': trackOnly, | ||||||
|  |         'enhancedVersionDetection': enhancedVersionDetection | ||||||
|       }; |       }; | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -190,6 +201,11 @@ ObtainiumError getObtainiumHttpError(Response res) { | |||||||
|       tr('errorWithHttpStatusCode', args: [res.statusCode.toString()])); |       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 { | abstract class MassAppUrlSource { | ||||||
|   late String name; |   late String name; | ||||||
|   late List<String> requiredArgs; |   late List<String> requiredArgs; | ||||||
| @@ -285,7 +301,8 @@ class SourceProvider { | |||||||
|         additionalData, |         additionalData, | ||||||
|         DateTime.now(), |         DateTime.now(), | ||||||
|         pinned, |         pinned, | ||||||
|         trackOnly); |         trackOnly, | ||||||
|  |         apk.isStandardVersionName); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   // Returns errors in [results, errors] instead of throwing them |   // Returns errors in [results, errors] instead of throwing them | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user