From a3a2a37a143474370f1731a71510292046913b6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Ku=C3=9Fowski?= Date: Sun, 8 Mar 2026 11:12:32 +0100 Subject: [PATCH] chore: Add reset button for config viewer --- lib/config/setting_keys.dart | 5 +++++ lib/l10n/intl_en.arb | 3 ++- lib/widgets/config_viewer.dart | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/config/setting_keys.dart b/lib/config/setting_keys.dart index f7d7a13ed..c623ce6c7 100644 --- a/lib/config/setting_keys.dart +++ b/lib/config/setting_keys.dart @@ -75,6 +75,11 @@ enum AppSettings { static SharedPreferences get store => _store!; static SharedPreferences? _store; + static Future reset({bool loadWebConfigFile = true}) async { + await AppSettings._store!.clear(); + await init(loadWebConfigFile: loadWebConfigFile); + } + static Future init({bool loadWebConfigFile = true}) async { if (AppSettings._store != null) return AppSettings.store; diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index ce842573c..4226d4fdc 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -2781,5 +2781,6 @@ "@mute": { "description": "This should be a very short string because there is not much space in the button!" }, - "createNewChat": "Create new chat" + "createNewChat": "Create new chat", + "reset": "Reset" } \ No newline at end of file diff --git a/lib/widgets/config_viewer.dart b/lib/widgets/config_viewer.dart index 82a9d4ba5..8fb826d84 100644 --- a/lib/widgets/config_viewer.dart +++ b/lib/widgets/config_viewer.dart @@ -48,6 +48,11 @@ class _ConfigViewerState extends State { setState(() {}); } + Future _reset() async { + await AppSettings.reset(); + setState(() {}); + } + @override Widget build(BuildContext context) { final theme = Theme.of(context); @@ -55,8 +60,12 @@ class _ConfigViewerState extends State { appBar: AppBar( title: Text(L10n.of(context).advancedConfigurations), leading: BackButton(onPressed: () => context.go('/')), + actions: [ + TextButton(onPressed: _reset, child: Text(L10n.of(context).reset)), + ], ), body: Column( + crossAxisAlignment: .stretch, children: [ Container( margin: const EdgeInsets.all(16), @@ -81,7 +90,13 @@ class _ConfigViewerState extends State { value = appSetting.value.toString(); } if (appSetting is AppSettings) { - value = appSetting.value.toString(); + return SwitchListTile.adaptive( + title: Text(appSetting.name), + subtitle: Text(value), + value: appSetting.value, + onChanged: (value) => + _changeSetting(appSetting, store, (!value).toString()), + ); } if (appSetting is AppSettings) { value = appSetting.value.toString();