fix: Unable to unselect new patches

This commit is contained in:
aAbed 2023-12-12 10:37:35 +05:45
parent 6ef1b072e8
commit 18e680b298
No known key found for this signature in database
GPG Key ID: F26611AB3F996827
2 changed files with 32 additions and 14 deletions

View File

@ -24,6 +24,7 @@ class PatcherViewModel extends BaseViewModel {
final NavigationService _navigationService = locator<NavigationService>(); final NavigationService _navigationService = locator<NavigationService>();
final ManagerAPI _managerAPI = locator<ManagerAPI>(); final ManagerAPI _managerAPI = locator<ManagerAPI>();
final PatcherAPI _patcherAPI = locator<PatcherAPI>(); final PatcherAPI _patcherAPI = locator<PatcherAPI>();
Set<String> savedPatchNames = {};
PatchedApplication? selectedApp; PatchedApplication? selectedApp;
BuildContext? ctx; BuildContext? ctx;
List<Patch> selectedPatches = []; List<Patch> selectedPatches = [];
@ -174,7 +175,8 @@ class PatcherViewModel extends BaseViewModel {
if (suggestedVersion.isNotEmpty) { if (suggestedVersion.isNotEmpty) {
await openDefaultBrowser( await openDefaultBrowser(
'${selectedApp!.packageName} apk version v$suggestedVersion'); '${selectedApp!.packageName} apk version v$suggestedVersion',
);
} else { } else {
await openDefaultBrowser('${selectedApp!.packageName} apk'); 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<void> loadLastSelectedPatches() async { Future<void> loadLastSelectedPatches() async {
this.selectedPatches.clear(); this.selectedPatches.clear();
removedPatches.clear(); removedPatches.clear();
@ -238,13 +254,24 @@ class PatcherViewModel extends BaseViewModel {
.selectedPatches .selectedPatches
.removeWhere((patch) => patch.compatiblePackages.isEmpty); .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); final usedPatches = _managerAPI.getUsedPatches(selectedApp!.packageName);
for (final patch in usedPatches) { for (final patch in usedPatches) {
if (!patches.any((p) => p.name == patch.name)) { if (!patches.any((p) => p.name == patch.name)) {
removedPatches.add('${patch.name}'); removedPatches.add('${patch.name}');
for (final option in patch.options) { for (final option in patch.options) {
_managerAPI.clearPatchOption( _managerAPI.clearPatchOption(
selectedApp!.packageName, patch.name, option.key); selectedApp!.packageName,
patch.name,
option.key,
);
} }
} }
} }

View File

@ -26,8 +26,6 @@ class PatchesSelectorViewModel extends BaseViewModel {
PatchedApplication? selectedApp = locator<PatcherViewModel>().selectedApp; PatchedApplication? selectedApp = locator<PatcherViewModel>().selectedApp;
String? patchesVersion = ''; String? patchesVersion = '';
Set<String> savedPatchNames = {};
bool isDefaultPatchesRepo() { bool isDefaultPatchesRepo() {
return _managerAPI.getPatchesRepo() == 'revanced/revanced-patches'; return _managerAPI.getPatchesRepo() == 'revanced/revanced-patches';
} }
@ -52,16 +50,13 @@ class PatchesSelectorViewModel extends BaseViewModel {
currentSelection.clear(); currentSelection.clear();
currentSelection.addAll(selectedPatches); currentSelection.addAll(selectedPatches);
savedPatchNames = _managerAPI.getSavedPatches(selectedApp!.packageName).map((p) => p.name).toSet();
notifyListeners(); notifyListeners();
} }
bool isSelected(Patch patch) { bool isSelected(Patch patch) {
return selectedPatches.any( return selectedPatches.any(
(element) => element.name == patch.name, (element) => element.name == patch.name,
) || );
(isPatchNew(patch) && !patch.excluded);
} }
void navigateToPatchOptions(List<Option> setOptions, Patch patch) { void navigateToPatchOptions(List<Option> setOptions, Patch patch) {
@ -288,11 +283,7 @@ class PatchesSelectorViewModel extends BaseViewModel {
} }
bool isPatchNew(Patch patch) { bool isPatchNew(Patch patch) {
if (savedPatchNames.isEmpty) { return locator<PatcherViewModel>().isPatchNew(patch);
return false;
} else {
return !savedPatchNames.contains(patch.name);
}
} }
List<String> getSupportedVersions(Patch patch) { List<String> getSupportedVersions(Patch patch) {