fix: experimental/universal patches being used even when turned off (#1090)

Co-authored-by: Pun Butrach <pun.butrach@gmail.com>
This commit is contained in:
aAbed 2023-08-06 10:55:57 +05:45 committed by GitHub
parent 5346f6e1bf
commit 5abcc7191f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 14 deletions

View File

@ -11,6 +11,7 @@ import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/patcher_api.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
import 'package:revanced_manager/utils/about_info.dart';
import 'package:revanced_manager/utils/check_for_supported_patch.dart';
import 'package:stacked/stacked.dart';
import 'package:stacked_services/stacked_services.dart';
@ -156,6 +157,14 @@ class PatcherViewModel extends BaseViewModel {
this
.selectedPatches
.addAll(patches.where((patch) => selectedPatches.contains(patch.name)));
if (!_managerAPI.areExperimentalPatchesEnabled()) {
this.selectedPatches.removeWhere((patch) => !isPatchSupported(patch));
}
if (!_managerAPI.areUniversalPatchesEnabled()) {
this
.selectedPatches
.removeWhere((patch) => patch.compatiblePackages.isEmpty);
}
notifyListeners();
}
}

View File

@ -3,7 +3,6 @@ import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:revanced_manager/app/app.locator.dart';
import 'package:revanced_manager/services/manager_api.dart';
import 'package:revanced_manager/services/toast.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_experimental_patches.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
@ -126,12 +125,6 @@ class _PatchItemState extends State<PatchItem> {
} else {
widget.isSelected = newValue!;
}
if (widget.isUnsupported &&
widget.isSelected &&
!selectedUnsupportedPatches
.contains(widget.name)) {
selectedUnsupportedPatches.add(widget.name);
}
});
widget.onChanged(widget.isSelected);
},

View File

@ -1,7 +1,9 @@
import 'package:flutter/material.dart';
import 'package:flutter_i18n/widgets/I18nText.dart';
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_viewmodel.dart';
import 'package:revanced_manager/ui/views/settings/settings_viewmodel.dart';
import 'package:revanced_manager/utils/check_for_supported_patch.dart';
class SExperimentalPatches extends StatefulWidget {
const SExperimentalPatches({super.key});
@ -11,7 +13,8 @@ class SExperimentalPatches extends StatefulWidget {
}
final _settingsViewModel = SettingsViewModel();
final List<String> selectedUnsupportedPatches = [];
final _patchesSelectorViewModel = PatchesSelectorViewModel();
final _patcherViewModel = PatcherViewModel();
class _SExperimentalPatchesState extends State<SExperimentalPatches> {
@override
@ -35,12 +38,10 @@ class _SExperimentalPatchesState extends State<SExperimentalPatches> {
_settingsViewModel.useExperimentalPatches(value);
});
if (!value) {
for (final patch in selectedUnsupportedPatches) {
PatchesSelectorViewModel()
.selectedPatches
.removeWhere((element) => patch == element.name);
}
selectedUnsupportedPatches.clear();
_patcherViewModel.selectedPatches
.removeWhere((patch) => !isPatchSupported(patch));
_patchesSelectorViewModel.selectedPatches
.removeWhere((patch) => !isPatchSupported(patch));
}
},
);

View File

@ -2,6 +2,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_i18n/widgets/I18nText.dart';
import 'package:revanced_manager/ui/views/settings/settings_viewmodel.dart';
import 'package:revanced_manager/ui/views/patcher/patcher_viewmodel.dart';
import 'package:revanced_manager/ui/views/patches_selector/patches_selector_viewmodel.dart';
class SExperimentalUniversalPatches extends StatefulWidget {
const SExperimentalUniversalPatches({super.key});
@ -11,6 +14,8 @@ class SExperimentalUniversalPatches extends StatefulWidget {
}
final _settingsViewModel = SettingsViewModel();
final _patchesSelectorViewModel = PatchesSelectorViewModel();
final _patcherViewModel = PatcherViewModel();
class _SExperimentalUniversalPatchesState
extends State<SExperimentalUniversalPatches> {
@ -34,6 +39,12 @@ class _SExperimentalUniversalPatchesState
setState(() {
_settingsViewModel.showUniversalPatches(value);
});
if (!value) {
_patcherViewModel.selectedPatches
.removeWhere((patch) => patch.compatiblePackages.isEmpty);
_patchesSelectorViewModel.selectedPatches
.removeWhere((patch) => patch.compatiblePackages.isEmpty);
}
},
);
}