fix: improve get compatible packages and patches

This commit is contained in:
Alberto Ponces 2022-08-10 00:50:02 +01:00
parent cc47584643
commit cfad7222ab

View File

@ -39,18 +39,21 @@ class PatcherAPI {
Future<List<AppInfo>> getFilteredInstalledApps() async { Future<List<AppInfo>> getFilteredInstalledApps() async {
if (_patchBundleFile != null && _filteredPackages.isEmpty) { if (_patchBundleFile != null && _filteredPackages.isEmpty) {
List<AppInfo> all = await InstalledApps.getInstalledApps(false, true);
try { try {
List<String>? patchesPackages = List<String>? patchesPackages =
await platform.invokeListMethod<String>('getCompatiblePackages'); await platform.invokeListMethod<String>('getCompatiblePackages');
if (patchesPackages != null) { if (patchesPackages != null) {
for (AppInfo app in all) { for (String package in patchesPackages) {
if (patchesPackages.contains(app.packageName)) { try {
AppInfo app = await InstalledApps.getAppInfo(package);
_filteredPackages.add(app); _filteredPackages.add(app);
} catch (e) {
continue;
} }
} }
} }
} on Exception { } on PlatformException {
_filteredPackages.clear();
return List.empty(); return List.empty();
} }
} }
@ -73,6 +76,8 @@ class PatcherAPI {
); );
if (patches != null) { if (patches != null) {
for (var patch in patches) { for (var patch in patches) {
if (!_filteredPatches[targetApp.packageName]!
.any((element) => element.name == patch['name'])) {
_filteredPatches[targetApp.packageName]!.add( _filteredPatches[targetApp.packageName]!.add(
Patch( Patch(
name: patch['name'], name: patch['name'],
@ -81,13 +86,15 @@ class PatcherAPI {
.split('-') .split('-')
.join(' ') .join(' ')
.toTitleCase(), .toTitleCase(),
version: patch['version'] ?? 'unknown', version: patch['version'] ?? '?.?.?',
description: patch['description'] ?? 'unknown', description: patch['description'] ?? 'N/A',
), ),
); );
} }
} }
} on Exception { }
} on PlatformException {
_filteredPatches[targetApp.packageName]!.clear();
return List.empty(); return List.empty();
} }
} }