From cfad7222ab1238576c828fe8c6569c768321770b Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Wed, 10 Aug 2022 00:50:02 +0100 Subject: [PATCH] fix: improve get compatible packages and patches --- lib/services/patcher_api.dart | 41 ++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/lib/services/patcher_api.dart b/lib/services/patcher_api.dart index b59ff319..a37b068b 100644 --- a/lib/services/patcher_api.dart +++ b/lib/services/patcher_api.dart @@ -39,18 +39,21 @@ class PatcherAPI { Future> getFilteredInstalledApps() async { if (_patchBundleFile != null && _filteredPackages.isEmpty) { - List all = await InstalledApps.getInstalledApps(false, true); try { List? patchesPackages = await platform.invokeListMethod('getCompatiblePackages'); if (patchesPackages != null) { - for (AppInfo app in all) { - if (patchesPackages.contains(app.packageName)) { + for (String package in patchesPackages) { + try { + AppInfo app = await InstalledApps.getAppInfo(package); _filteredPackages.add(app); + } catch (e) { + continue; } } } - } on Exception { + } on PlatformException { + _filteredPackages.clear(); return List.empty(); } } @@ -73,21 +76,25 @@ class PatcherAPI { ); if (patches != null) { for (var patch in patches) { - _filteredPatches[targetApp.packageName]!.add( - Patch( - name: patch['name'], - simpleName: (patch['name'] as String) - .replaceAll('-', ' ') - .split('-') - .join(' ') - .toTitleCase(), - version: patch['version'] ?? 'unknown', - description: patch['description'] ?? 'unknown', - ), - ); + if (!_filteredPatches[targetApp.packageName]! + .any((element) => element.name == patch['name'])) { + _filteredPatches[targetApp.packageName]!.add( + Patch( + name: patch['name'], + simpleName: (patch['name'] as String) + .replaceAll('-', ' ') + .split('-') + .join(' ') + .toTitleCase(), + version: patch['version'] ?? '?.?.?', + description: patch['description'] ?? 'N/A', + ), + ); + } } } - } on Exception { + } on PlatformException { + _filteredPatches[targetApp.packageName]!.clear(); return List.empty(); } }