feat: experimental settings to allow patch on any app version.

This commit is contained in:
Aunali321 2022-11-01 15:26:15 +05:30
parent 293f7150f1
commit ba5234e850
6 changed files with 86 additions and 13 deletions

View file

@ -84,7 +84,8 @@
"patchItem": { "patchItem": {
"unsupportedWarningButton": "Warning", "unsupportedWarningButton": "Warning",
"unsupportedDialogTitle": "Warning", "unsupportedDialogTitle": "Warning",
"unsupportedDialogText": "Selecting this patch may result in patching errors.\n\nApp version: {packageVersion}\nCurrent supported versions:\n{supportedVersions}" "unsupportedDialogText": "Selecting this patch may result in patching errors.\n\nApp version: {packageVersion}\nCurrent supported versions:\n{supportedVersions}",
"unsupportedPatchVersion": "Patch is not supported for this app version. Enable experimental toggle in settings to proceed."
}, },
"installerView": { "installerView": {
"widgetTitle": "Installer", "widgetTitle": "Installer",
@ -132,6 +133,9 @@
"apiURLLabel": "API URL", "apiURLLabel": "API URL",
"apiURLHint": "Configure your custom API URL", "apiURLHint": "Configure your custom API URL",
"selectApiURL": "Select URL", "selectApiURL": "Select URL",
"experimentalPatchesLabel": "Experimental Patch support",
"experimentalPatchesHint": "Enable to use unsupported patches in any app version",
"enabledExperimentalPatches": "Experimental patches enabled",
"aboutLabel": "About", "aboutLabel": "About",
"snackbarMessage": "Copied to clipboard", "snackbarMessage": "Copied to clipboard",
"sentryLabel": "Sentry Logging", "sentryLabel": "Sentry Logging",

View file

@ -90,6 +90,14 @@ class ManagerAPI {
// await _prefs.setBool('sentryEnabled', value); // await _prefs.setBool('sentryEnabled', value);
// } // }
bool areExperimentalPatchesEnabled() {
return _prefs.getBool('experimentalPatchesEnabled') ?? false;
}
Future<void> enableExperimentalPatchesStatus(bool value) async {
await _prefs.setBool('experimentalPatchesEnabled', value);
}
Future<void> deleteTempFolder() async { Future<void> deleteTempFolder() async {
final Directory dir = Directory('/data/local/tmp/revanced-manager'); final Directory dir = Directory('/data/local/tmp/revanced-manager');
if (await dir.exists()) { if (await dir.exists()) {

View file

@ -136,6 +136,23 @@ class SettingsView extends StatelessWidget {
subtitle: 'settingsView.sourcesLabelHint', subtitle: 'settingsView.sourcesLabelHint',
onTap: () => model.showSourcesDialog(context), onTap: () => model.showSourcesDialog(context),
), ),
CustomSwitchTile(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
title: I18nText(
'settingsView.experimentalPatchesLabel',
child: const Text(
'',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
),
subtitle:
I18nText('settingsView.experimentalPatchesHint'),
value: model.areExperimentalPatchesEnabled(),
onTap: (value) =>
model.useExperimentalPatches(value)),
ListTile( ListTile(
contentPadding: contentPadding:
const EdgeInsets.symmetric(horizontal: 20.0), const EdgeInsets.symmetric(horizontal: 20.0),

View file

@ -325,6 +325,16 @@ class SettingsViewModel extends BaseViewModel {
// notifyListeners(); // notifyListeners();
// } // }
bool areExperimentalPatchesEnabled() {
return _managerAPI.areExperimentalPatchesEnabled();
}
void useExperimentalPatches(bool value) {
_managerAPI.enableExperimentalPatchesStatus(value);
_toast.showBottom('settingsView.enabledExperimentalPatches');
notifyListeners();
}
void deleteKeystore() { void deleteKeystore() {
_managerAPI.deleteKeystore(); _managerAPI.deleteKeystore();
_toast.showBottom('settingsView.deletedKeystore'); _toast.showBottom('settingsView.deletedKeystore');

View file

@ -1,5 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_i18n/flutter_i18n.dart'; 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/shared/custom_material_button.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_material_button.dart';
import 'package:revanced_manager/ui/widgets/shared/custom_card.dart'; import 'package:revanced_manager/ui/widgets/shared/custom_card.dart';
@ -15,6 +18,8 @@ class PatchItem extends StatefulWidget {
bool isSelected; bool isSelected;
final Function(bool) onChanged; final Function(bool) onChanged;
final Widget? child; final Widget? child;
final toast = locator<Toast>();
final _managerAPI = locator<ManagerAPI>();
PatchItem( PatchItem(
{Key? key, {Key? key,
@ -40,8 +45,21 @@ class _PatchItemState extends State<PatchItem> {
return Padding( return Padding(
padding: const EdgeInsets.symmetric(vertical: 4.0), padding: const EdgeInsets.symmetric(vertical: 4.0),
child: CustomCard( child: CustomCard(
backgroundColor: widget.isUnsupported &&
widget._managerAPI.areExperimentalPatchesEnabled() == false
? Theme.of(context).colorScheme.brightness == Brightness.light
? Colors.grey[400]
: Colors.grey[700]
: null,
onTap: () { onTap: () {
setState(() => widget.isSelected = !widget.isSelected); setState(() {
if (widget.isUnsupported) {
widget.isSelected = false;
widget.toast.showBottom('patchItem.unsupportedPatchVersion');
} else {
widget.isSelected = !widget.isSelected;
}
});
widget.onChanged(widget.isSelected); widget.onChanged(widget.isSelected);
}, },
child: Column( child: Column(
@ -83,7 +101,9 @@ class _PatchItemState extends State<PatchItem> {
overflow: TextOverflow.visible, overflow: TextOverflow.visible,
style: TextStyle( style: TextStyle(
fontSize: 14, fontSize: 14,
color: Theme.of(context).colorScheme.onSecondaryContainer, color: Theme.of(context)
.colorScheme
.onSecondaryContainer,
), ),
), ),
], ],
@ -101,7 +121,18 @@ class _PatchItemState extends State<PatchItem> {
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.primary,
), ),
onChanged: (newValue) { onChanged: (newValue) {
setState(() => widget.isSelected = newValue!); setState(() {
if (widget.isUnsupported &&
widget._managerAPI
.areExperimentalPatchesEnabled() ==
false) {
widget.isSelected = false;
widget.toast
.showBottom('patchItem.unsupportedPatchVersion');
} else {
widget.isSelected = newValue!;
}
});
widget.onChanged(widget.isSelected); widget.onChanged(widget.isSelected);
}, },
), ),

View file

@ -5,22 +5,25 @@ class CustomCard extends StatelessWidget {
final Widget child; final Widget child;
final Function()? onTap; final Function()? onTap;
final EdgeInsetsGeometry? padding; final EdgeInsetsGeometry? padding;
final Color? backgroundColor;
const CustomCard({ const CustomCard(
Key? key, {Key? key,
this.isFilled = true, this.isFilled = true,
required this.child, required this.child,
this.onTap, this.onTap,
this.padding, this.padding,
}) : super(key: key); this.backgroundColor})
: super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Material( return Material(
type: isFilled ? MaterialType.card : MaterialType.transparency, type: isFilled ? MaterialType.card : MaterialType.transparency,
color: isFilled color: isFilled
? Theme.of(context).colorScheme.secondaryContainer.withOpacity(0.4) ? backgroundColor?.withOpacity(0.4) ??
: Colors.transparent, Theme.of(context).colorScheme.secondaryContainer.withOpacity(0.4)
: backgroundColor ?? Colors.transparent,
borderRadius: BorderRadius.circular(16), borderRadius: BorderRadius.circular(16),
child: InkWell( child: InkWell(
onTap: onTap, onTap: onTap,