diff --git a/lib/ui/views/patcher/patcher_viewmodel.dart b/lib/ui/views/patcher/patcher_viewmodel.dart index 68f35397..2827eedc 100644 --- a/lib/ui/views/patcher/patcher_viewmodel.dart +++ b/lib/ui/views/patcher/patcher_viewmodel.dart @@ -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(); } } diff --git a/lib/ui/widgets/patchesSelectorView/patch_item.dart b/lib/ui/widgets/patchesSelectorView/patch_item.dart index fd616062..af62f8c6 100644 --- a/lib/ui/widgets/patchesSelectorView/patch_item.dart +++ b/lib/ui/widgets/patchesSelectorView/patch_item.dart @@ -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 { } else { widget.isSelected = newValue!; } - if (widget.isUnsupported && - widget.isSelected && - !selectedUnsupportedPatches - .contains(widget.name)) { - selectedUnsupportedPatches.add(widget.name); - } }); widget.onChanged(widget.isSelected); }, diff --git a/lib/ui/widgets/settingsView/settings_experimental_patches.dart b/lib/ui/widgets/settingsView/settings_experimental_patches.dart index 1b2e2542..be704c73 100644 --- a/lib/ui/widgets/settingsView/settings_experimental_patches.dart +++ b/lib/ui/widgets/settingsView/settings_experimental_patches.dart @@ -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 selectedUnsupportedPatches = []; +final _patchesSelectorViewModel = PatchesSelectorViewModel(); +final _patcherViewModel = PatcherViewModel(); class _SExperimentalPatchesState extends State { @override @@ -35,12 +38,10 @@ class _SExperimentalPatchesState extends State { _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)); } }, ); diff --git a/lib/ui/widgets/settingsView/settings_experimental_universal_patches.dart b/lib/ui/widgets/settingsView/settings_experimental_universal_patches.dart index 38e534fb..fa9dad27 100644 --- a/lib/ui/widgets/settingsView/settings_experimental_universal_patches.dart +++ b/lib/ui/widgets/settingsView/settings_experimental_universal_patches.dart @@ -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 { @@ -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); + } }, ); }