Added setting

This commit is contained in:
Benjamin Halko 2023-11-25 11:32:33 -08:00
parent 8ac25bfb40
commit cebf97464d
No known key found for this signature in database
GPG Key ID: 790C70040EB331A0
8 changed files with 92 additions and 10 deletions

View File

@ -239,6 +239,9 @@
"universalPatchesLabel": "Show universal patches",
"universalPatchesHint": "Display all apps and universal patches (may slow down the app list)",
"patchHistoryLabel": "Save patched app",
"patchHistoryHint": "Save the last patched app to install/export later",
"versionCompatibilityCheckLabel": "Version compatibility check",
"versionCompatibilityCheckHint": "Restricts patches to supported app versions",
"requireSuggestedAppVersionLabel": "Require suggested app version",

View File

@ -268,6 +268,14 @@ class ManagerAPI {
await _prefs.setBool('requireSuggestedAppVersionEnabled', value);
}
bool isPatchHistoryEnabled() {
return _prefs.getBool('patchHistoryEnabled') ?? true;
}
Future<void> enablePatchHistoryStatus(bool value) async {
await _prefs.setBool('patchHistoryEnabled', value);
}
Future<void> setKeystorePassword(String password) async {
await _prefs.setString('keystorePassword', password);
}

View File

@ -51,16 +51,25 @@ class HomeView extends StatelessWidget {
const SizedBox(height: 10),
LatestCommitCard(model: model, parentContext: context),
const SizedBox(height: 23),
I18nText(
'homeView.patchHistorySubtitle',
child: Text(
'',
style: Theme.of(context).textTheme.titleLarge,
),
Visibility(
visible: model.isPatchHistoryEnabled(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
I18nText(
'homeView.patchHistorySubtitle',
child: Text(
'',
style: Theme.of(context).textTheme.titleLarge,
),
),
const SizedBox(height: 10),
PatchHistoryCard(),
const SizedBox(height: 10),
],
),
),
const SizedBox(height: 10),
PatchHistoryCard(),
const SizedBox(height: 10),
I18nText(
'homeView.patchedSubtitle',
child: Text(

View File

@ -112,6 +112,10 @@ class HomeViewModel extends BaseViewModel {
notifyListeners();
}
bool isPatchHistoryEnabled() {
return _managerAPI.isPatchHistoryEnabled();
}
Future<bool> hasManagerUpdates() async {
String currentVersion = await _managerAPI.getCurrentManagerVersion();

View File

@ -147,7 +147,11 @@ class InstallerViewModel extends BaseViewModel {
_patches,
);
_app.appliedPatches = _patches.map((p) => p.name).toList();
await _managerAPI.setLastPatchedApp(_app, _patcherAPI.outFile!);
if (_managerAPI.isPatchHistoryEnabled()) {
await _managerAPI.setLastPatchedApp(_app, _patcherAPI.outFile!);
} else {
_app.patchedFilePath = _patcherAPI.outFile!.path;
}
locator<HomeViewModel>().initialize(context);
} on Exception catch (e) {
update(

View File

@ -131,6 +131,18 @@ class SettingsViewModel extends BaseViewModel {
notifyListeners();
}
bool isPatchHistoryEnabled() {
return _managerAPI.isPatchHistoryEnabled();
}
void usePatchHistory(bool value) {
_managerAPI.enablePatchHistoryStatus(value);
if (!value) {
_managerAPI.deleteLastPatchedApp();
}
notifyListeners();
}
bool isVersionCompatibilityCheckEnabled() {
return _managerAPI.isVersionCompatibilityCheckEnabled();
}

View File

@ -5,6 +5,7 @@ import 'package:revanced_manager/ui/views/settings/settingsFragment/settings_man
import 'package:revanced_manager/ui/views/settings/settingsFragment/settings_manage_sources.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_auto_update_patches.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_enable_patches_selection.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_patch_history.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_require_suggested_app_version.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_section.dart';
import 'package:revanced_manager/ui/widgets/settingsView/settings_universal_patches.dart';
@ -24,6 +25,7 @@ class SAdvancedSection extends StatelessWidget {
SRequireSuggestedAppVersion(),
SVersionCompatibilityCheck(),
SUniversalPatches(),
SPatchHistory(),
SManageSourcesUI(),
SManageApiUrlUI(),
],

View File

@ -0,0 +1,40 @@
import 'package:flutter/material.dart';
import 'package:flutter_i18n/widgets/I18nText.dart';
import 'package:revanced_manager/ui/views/settings/settings_viewmodel.dart';
class SPatchHistory extends StatefulWidget {
const SPatchHistory({super.key});
@override
State<SPatchHistory> createState() =>
_SPatchHistoryState();
}
final _settingsViewModel = SettingsViewModel();
class _SPatchHistoryState
extends State<SPatchHistory> {
@override
Widget build(BuildContext context) {
return SwitchListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 20.0),
title: I18nText(
'settingsView.patchHistoryLabel',
child: const Text(
'',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w500,
),
),
),
subtitle: I18nText('settingsView.patchHistoryHint'),
value: _settingsViewModel.isPatchHistoryEnabled(),
onChanged: (value) {
setState(() {
_settingsViewModel.usePatchHistory(value);
});
},
);
}
}