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(); } }