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 ManagerAPI _managerAPI = locator<ManagerAPI>();
final PatcherAPI _patcherAPI = locator<PatcherAPI>();
Set<String> savedPatchNames = {};
PatchedApplication? selectedApp;
BuildContext? ctx;
List<Patch> 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<void> 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,
);
}
}
}

View File

@ -26,8 +26,6 @@ class PatchesSelectorViewModel extends BaseViewModel {
PatchedApplication? selectedApp = locator<PatcherViewModel>().selectedApp;
String? patchesVersion = '';
Set<String> 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<Option> setOptions, Patch patch) {
@ -288,11 +283,7 @@ class PatchesSelectorViewModel extends BaseViewModel {
}
bool isPatchNew(Patch patch) {
if (savedPatchNames.isEmpty) {
return false;
} else {
return !savedPatchNames.contains(patch.name);
}
return locator<PatcherViewModel>().isPatchNew(patch);
}
List<String> getSupportedVersions(Patch patch) {