From 7e3afe0cb29c72ed85cd9f78dcaeb85953f1f9a2 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 9 Nov 2024 01:46:37 +0100 Subject: [PATCH] perf: Don't recalculate universal patches or compatible packages if not necessary --- lib/services/patcher_api.dart | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/services/patcher_api.dart b/lib/services/patcher_api.dart index 1245cec6..6ac47d2f 100644 --- a/lib/services/patcher_api.dart +++ b/lib/services/patcher_api.dart @@ -18,8 +18,7 @@ import 'package:share_plus/share_plus.dart'; @lazySingleton class PatcherAPI { - static const patcherChannel = - MethodChannel('app.revanced.manager.flutter/patcher'); + static const patcherChannel = MethodChannel('app.revanced.manager.flutter/patcher'); final ManagerAPI _managerAPI = locator(); final RootAPI _rootAPI = RootAPI(); late Directory _dataDir; @@ -27,7 +26,7 @@ class PatcherAPI { late File _keyStoreFile; List _patches = []; List _universalPatches = []; - List _compatiblePackages = []; + Set _compatiblePackages = {}; Map filteredPatches = >{}; File? outFile; @@ -46,8 +45,8 @@ class PatcherAPI { } } - List getCompatiblePackages() { - final List compatiblePackages = []; + Set getCompatiblePackages() { + final Set compatiblePackages = {}; for (final Patch patch in _patches) { for (final Package package in patch.compatiblePackages) { if (!compatiblePackages.contains(package.name)) { @@ -66,16 +65,16 @@ class PatcherAPI { try { if (_patches.isEmpty) { _patches = await _managerAPI.getPatches(); + _universalPatches = getUniversalPatches(); + _compatiblePackages = getCompatiblePackages(); } } on Exception catch (e) { if (kDebugMode) { print(e); } + _patches = List.empty(); } - - _compatiblePackages = getCompatiblePackages(); - _universalPatches = getUniversalPatches(); } Future> getFilteredInstalledApps( @@ -84,6 +83,7 @@ class PatcherAPI { final List filteredApps = []; final bool allAppsIncluded = _universalPatches.isNotEmpty && showUniversalPatches; + if (allAppsIncluded) { final appList = await DeviceApps.getInstalledApplications( includeAppIcons: true, @@ -94,6 +94,7 @@ class PatcherAPI { filteredApps.add(app as ApplicationWithIcon); } } + for (final packageName in _compatiblePackages) { try { if (!filteredApps.any((app) => app.packageName == packageName)) {