Skip to content

Commit

Permalink
fix(settings): inverted version compatibility switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ushie committed Oct 15, 2023
1 parent 53677e2 commit 59adb91
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/services/manager_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ class ManagerAPI {
Future<List<String>> getDefaultPatches() async {
final List<Patch> patches = await getPatches();
final List<String> defaultPatches = [];
if (isVersionCompatibilityCheckEnabled() == false) {
if (isVersionCompatibilityCheckEnabled() == true) {
defaultPatches.addAll(
patches
.where(
Expand Down
12 changes: 7 additions & 5 deletions lib/ui/views/patcher/patcher_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class PatcherViewModel extends BaseViewModel {
}

bool checkRequiredPatchOption(BuildContext context) {
if (getNullRequiredOptions(selectedPatches, selectedApp!.packageName).isNotEmpty) {
if (getNullRequiredOptions(selectedPatches, selectedApp!.packageName)
.isNotEmpty) {
showRequiredOptionDialog(context);
return false;
}
Expand Down Expand Up @@ -190,7 +191,7 @@ class PatcherViewModel extends BaseViewModel {
this.selectedPatches.clear();
this.selectedPatches.addAll(patches.where((patch) => !patch.excluded));
}
if (!_managerAPI.isVersionCompatibilityCheckEnabled()) {
if (_managerAPI.isVersionCompatibilityCheckEnabled()) {
this.selectedPatches.removeWhere((patch) => !isPatchSupported(patch));
}
if (!_managerAPI.areUniversalPatchesEnabled()) {
Expand All @@ -199,11 +200,12 @@ class PatcherViewModel extends BaseViewModel {
.removeWhere((patch) => patch.compatiblePackages.isEmpty);
}
final usedPatches = _managerAPI.getUsedPatches(selectedApp!.packageName);
for (final patch in usedPatches){
if (!patches.any((p) => p.name == patch.name)){
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);
_managerAPI.clearPatchOption(
selectedApp!.packageName, patch.name, option.key);
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions lib/ui/views/patches_selector/patches_selector_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ class PatchesSelectorViewModel extends BaseViewModel {
.where(
(element) =>
!element.excluded &&
(_managerAPI.isVersionCompatibilityCheckEnabled() ||
(!_managerAPI.isVersionCompatibilityCheckEnabled() ||
isPatchSupported(element)),
),
);
Expand Down Expand Up @@ -209,7 +209,10 @@ class PatchesSelectorViewModel extends BaseViewModel {
query.isEmpty ||
query.length < 2 ||
patch.name.toLowerCase().contains(query.toLowerCase()) ||
patch.name.replaceAll(RegExp(r'[^\w\s]+'), '').toLowerCase().contains(query.toLowerCase()),
patch.name
.replaceAll(RegExp(r'[^\w\s]+'), '')
.toLowerCase()
.contains(query.toLowerCase()),
)
.toList();
if (_managerAPI.areUniversalPatchesEnabled()) {
Expand Down Expand Up @@ -281,7 +284,7 @@ class PatchesSelectorViewModel extends BaseViewModel {
this.selectedPatches.addAll(
patches.where((patch) => selectedPatches.contains(patch.name)),
);
if (!_managerAPI.isVersionCompatibilityCheckEnabled()) {
if (_managerAPI.isVersionCompatibilityCheckEnabled()) {
this.selectedPatches.removeWhere((patch) => !isPatchSupported(patch));
}
} else {
Expand Down
17 changes: 10 additions & 7 deletions lib/ui/widgets/patchesSelectorView/patch_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ class _PatchItemState extends State<PatchItem> {
Widget build(BuildContext context) {
widget.isSelected = widget.isSelected &&
(!widget.isUnsupported ||
widget._managerAPI.isVersionCompatibilityCheckEnabled()) && !widget.hasUnsupportedPatchOption;
!widget._managerAPI.isVersionCompatibilityCheckEnabled()) &&
!widget.hasUnsupportedPatchOption;
return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0),
child: Opacity(
opacity: widget.isUnsupported &&
widget._managerAPI.isVersionCompatibilityCheckEnabled() == false
widget._managerAPI.isVersionCompatibilityCheckEnabled() == true
? 0.5
: 1,
child: CustomCard(
Expand All @@ -65,7 +66,7 @@ class _PatchItemState extends State<PatchItem> {
),
onTap: () {
if (widget.isUnsupported &&
!widget._managerAPI.isVersionCompatibilityCheckEnabled()) {
widget._managerAPI.isVersionCompatibilityCheckEnabled()) {
widget.isSelected = false;
widget.toast.showBottom('patchItem.unsupportedPatchVersion');
} else if (widget.isChangeEnabled) {
Expand All @@ -79,7 +80,7 @@ class _PatchItemState extends State<PatchItem> {
setState(() {});
}
if (!widget.isUnsupported ||
widget._managerAPI.isVersionCompatibilityCheckEnabled()) {
!widget._managerAPI.isVersionCompatibilityCheckEnabled()) {
widget.onChanged(widget.isSelected);
}
},
Expand All @@ -98,7 +99,8 @@ class _PatchItemState extends State<PatchItem> {
),
onChanged: (newValue) {
if (widget.isUnsupported &&
!widget._managerAPI.isVersionCompatibilityCheckEnabled()) {
widget._managerAPI
.isVersionCompatibilityCheckEnabled()) {
widget.isSelected = false;
widget.toast.showBottom(
'patchItem.unsupportedPatchVersion',
Expand All @@ -114,7 +116,8 @@ class _PatchItemState extends State<PatchItem> {
setState(() {});
}
if (!widget.isUnsupported ||
widget._managerAPI.isVersionCompatibilityCheckEnabled()) {
!widget._managerAPI
.isVersionCompatibilityCheckEnabled()) {
widget.onChanged(widget.isSelected);
}
},
Expand Down Expand Up @@ -154,7 +157,7 @@ class _PatchItemState extends State<PatchItem> {
runSpacing: 4,
children: [
if (widget.isUnsupported &&
widget._managerAPI
!widget._managerAPI
.isVersionCompatibilityCheckEnabled())
Padding(
padding: const EdgeInsets.only(top: 8),
Expand Down

0 comments on commit 59adb91

Please sign in to comment.