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,21 +76,25 @@ class PatcherAPI {
); );
if (patches != null) { if (patches != null) {
for (var patch in patches) { for (var patch in patches) {
_filteredPatches[targetApp.packageName]!.add( if (!_filteredPatches[targetApp.packageName]!
Patch( .any((element) => element.name == patch['name'])) {
name: patch['name'], _filteredPatches[targetApp.packageName]!.add(
simpleName: (patch['name'] as String) Patch(
.replaceAll('-', ' ') name: patch['name'],
.split('-') simpleName: (patch['name'] as String)
.join(' ') .replaceAll('-', ' ')
.toTitleCase(), .split('-')
version: patch['version'] ?? 'unknown', .join(' ')
description: patch['description'] ?? 'unknown', .toTitleCase(),
), version: patch['version'] ?? '?.?.?',
); description: patch['description'] ?? 'N/A',
),
);
}
} }
} }
} on Exception { } on PlatformException {
_filteredPatches[targetApp.packageName]!.clear();
return List.empty(); return List.empty();
} }
} }