Skip to content

Commit

Permalink
fix: Unable to unselect new patches
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAabedKhan committed Dec 12, 2023
1 parent 6ef1b07 commit 18e680b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
31 changes: 29 additions & 2 deletions lib/ui/views/patcher/patcher_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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();
Expand All @@ -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,
);
}
}
}
Expand Down
15 changes: 3 additions & 12 deletions lib/ui/views/patches_selector/patches_selector_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 18e680b

Please sign in to comment.