From 18e680b2988f0e7d60c52241cc72b06b9449ec48 Mon Sep 17 00:00:00 2001 From: aAbed Date: Tue, 12 Dec 2023 10:37:35 +0545 Subject: [PATCH] fix: Unable to unselect new patches --- lib/ui/views/patcher/patcher_viewmodel.dart | 31 +++++++++++++++++-- .../patches_selector_viewmodel.dart | 15 ++------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/lib/ui/views/patcher/patcher_viewmodel.dart b/lib/ui/views/patcher/patcher_viewmodel.dart index 19d7072160..480babec96 100644 --- a/lib/ui/views/patcher/patcher_viewmodel.dart +++ b/lib/ui/views/patcher/patcher_viewmodel.dart @@ -24,6 +24,7 @@ class PatcherViewModel extends BaseViewModel { final NavigationService _navigationService = locator(); final ManagerAPI _managerAPI = locator(); final PatcherAPI _patcherAPI = locator(); + Set savedPatchNames = {}; PatchedApplication? selectedApp; BuildContext? ctx; List selectedPatches = []; @@ -174,7 +175,8 @@ class PatcherViewModel extends BaseViewModel { if (suggestedVersion.isNotEmpty) { await openDefaultBrowser( - '${selectedApp!.packageName} apk version v$suggestedVersion'); + '${selectedApp!.packageName} apk version v$suggestedVersion', + ); } else { await openDefaultBrowser('${selectedApp!.packageName} apk'); } @@ -216,6 +218,20 @@ class PatcherViewModel extends BaseViewModel { } } + bool isPatchNew(Patch patch) { + if (savedPatchNames.isEmpty) { + savedPatchNames = _managerAPI + .getSavedPatches(selectedApp!.packageName) + .map((p) => p.name) + .toSet(); + } + if (savedPatchNames.isEmpty) { + return false; + } else { + return !savedPatchNames.contains(patch.name); + } + } + Future loadLastSelectedPatches() async { this.selectedPatches.clear(); removedPatches.clear(); @@ -238,13 +254,24 @@ class PatcherViewModel extends BaseViewModel { .selectedPatches .removeWhere((patch) => patch.compatiblePackages.isEmpty); } + this.selectedPatches.addAll( + patches.where( + (patch) => + isPatchNew(patch) && + !patch.excluded && + !this.selectedPatches.contains(patch), + ), + ); final usedPatches = _managerAPI.getUsedPatches(selectedApp!.packageName); for (final patch in usedPatches) { if (!patches.any((p) => p.name == patch.name)) { removedPatches.add('• ${patch.name}'); for (final option in patch.options) { _managerAPI.clearPatchOption( - selectedApp!.packageName, patch.name, option.key); + selectedApp!.packageName, + patch.name, + option.key, + ); } } } diff --git a/lib/ui/views/patches_selector/patches_selector_viewmodel.dart b/lib/ui/views/patches_selector/patches_selector_viewmodel.dart index 399fe34945..71d073a9d5 100644 --- a/lib/ui/views/patches_selector/patches_selector_viewmodel.dart +++ b/lib/ui/views/patches_selector/patches_selector_viewmodel.dart @@ -26,8 +26,6 @@ class PatchesSelectorViewModel extends BaseViewModel { PatchedApplication? selectedApp = locator().selectedApp; String? patchesVersion = ''; - Set savedPatchNames = {}; - bool isDefaultPatchesRepo() { return _managerAPI.getPatchesRepo() == 'revanced/revanced-patches'; } @@ -52,16 +50,13 @@ class PatchesSelectorViewModel extends BaseViewModel { currentSelection.clear(); currentSelection.addAll(selectedPatches); - savedPatchNames = _managerAPI.getSavedPatches(selectedApp!.packageName).map((p) => p.name).toSet(); - notifyListeners(); } bool isSelected(Patch patch) { return selectedPatches.any( - (element) => element.name == patch.name, - ) || - (isPatchNew(patch) && !patch.excluded); + (element) => element.name == patch.name, + ); } void navigateToPatchOptions(List