From c93c225fc4b64793fbbdd4cc6e4e0c398aecf793 Mon Sep 17 00:00:00 2001 From: Ben Luca Behring Date: Sat, 30 May 2026 13:33:33 +0200 Subject: [PATCH 1/2] feat(settings): add Reset to Default button --- public/lang/en.json | 3 ++ src-tauri/src/commands/app.rs | 5 +++ src-tauri/src/lib.rs | 1 + src/api/app/index.ts | 3 ++ .../Forms/Settings/SettingsForm.tsx | 31 ++++++++++++++++++- 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/public/lang/en.json b/public/lang/en.json index 0c468171..39308c6f 100644 --- a/public/lang/en.json +++ b/public/lang/en.json @@ -19,6 +19,9 @@ "save": { "label": "Save" }, + "reset_defaults": { + "label": "Reset to Default" + }, "delete": { "label": "Delete" } diff --git a/src-tauri/src/commands/app.rs b/src-tauri/src/commands/app.rs index 0c1f5481..2e77ff97 100644 --- a/src-tauri/src/commands/app.rs +++ b/src-tauri/src/commands/app.rs @@ -37,6 +37,11 @@ pub async fn app_get_settings(app: tauri::State<'_, Mutex>) -> Result< Ok(app.settings.clone()) } +#[tauri::command] +pub async fn app_get_default_settings() -> Result { + Ok(Settings::default()) +} + #[tauri::command] pub async fn app_update_settings( mut settings: Settings, diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 8b7a4883..ee854e90 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -208,6 +208,7 @@ pub fn run() { commands::app::app_exit, commands::app::app_accept_tos, commands::app::app_notify_reset, + commands::app::app_get_default_settings, // Auth commands commands::auth::auth_me, commands::auth::auth_login, diff --git a/src/api/app/index.ts b/src/api/app/index.ts index 266daa6b..bb032cfc 100644 --- a/src/api/app/index.ts +++ b/src/api/app/index.ts @@ -34,4 +34,7 @@ export class AppModule { notify_reset(id: string): Promise { return this.client.sendInvoke("app_notify_reset", { id }); } + getDefaultSettings(): Promise { + return this.client.sendInvoke("app_get_default_settings"); + } } diff --git a/src/components/Forms/Settings/SettingsForm.tsx b/src/components/Forms/Settings/SettingsForm.tsx index 2dd6ef32..47044770 100644 --- a/src/components/Forms/Settings/SettingsForm.tsx +++ b/src/components/Forms/Settings/SettingsForm.tsx @@ -10,6 +10,9 @@ import { SummaryPanel } from "./Tabs/Summary"; import { HttpServerPanel } from "./Tabs/HttpServer"; import { GeneralPanel } from "./Tabs/General"; import { useForm } from "@mantine/form"; +import api from "@api"; +import { useState, useEffect } from "react"; +import { confirm } from "@tauri-apps/plugin-dialog"; export type SettingsFormProps = { value: TauriTypes.Settings & { has_error?: boolean; hide_save_button?: boolean }; @@ -34,6 +37,27 @@ export function SettingsForm({ onSubmit, value }: SettingsFormProps) { }, }); + const [defaultSettings, setDefaultSettings] = useState(null); + + useEffect(() => { + api.app.getDefaultSettings().then(setDefaultSettings).catch(console.error); + }, []); + + const isNotDefault = defaultSettings && JSON.stringify({ ...value, has_error: undefined, hide_save_button: undefined }) !== JSON.stringify(defaultSettings); + + const showButtons = isNotDefault || form.isDirty(); + + const handleReset = async () => { + const confirmed = await confirm("Reset all settings to default values?", { kind: "warning" }); + if (!confirmed) return; + try { + const defaults = await api.app.getDefaultSettings(); + form.setValues(defaults); + } catch (e) { + console.error("Failed to reset to defaults", e); + } + }; + const tabs = [ { label: useTranslateTabs("general.title"), @@ -93,7 +117,12 @@ export function SettingsForm({ onSubmit, value }: SettingsFormProps) { ))} - + + {isNotDefault && ( + + )} From b95b5ce0f61cc441938f1eecbdab62bce046876b Mon Sep 17 00:00:00 2001 From: Ben Luca Behring Date: Tue, 2 Jun 2026 14:33:46 +0200 Subject: [PATCH 2/2] feat(settings): Translate reset confirmation dialog --- public/lang/en.json | 8 +++++++- public/lang/es.json | 11 ++++++++++- public/lang/ru.json | 10 +++++++++- src/components/Forms/Settings/SettingsForm.tsx | 12 ++++++++++-- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/public/lang/en.json b/public/lang/en.json index 39308c6f..e31c8ade 100644 --- a/public/lang/en.json +++ b/public/lang/en.json @@ -26,6 +26,12 @@ "label": "Delete" } }, + "dialogs": { + "reset_settings": { + "title": "Reset settings", + "message": "Reset all settings to default values?" + } + }, "notifications": { "copy_to_clipboard": { "title": "Copied to Clipboard", @@ -2458,4 +2464,4 @@ } } } -} \ No newline at end of file +} diff --git a/public/lang/es.json b/public/lang/es.json index 9e26dfee..df5288ec 100644 --- a/public/lang/es.json +++ b/public/lang/es.json @@ -1 +1,10 @@ -{} \ No newline at end of file +{ + "common": { + "dialogs": { + "reset_settings": { + "title": "Restablecer configuración", + "message": "¿Restablecer toda la configuración a los valores predeterminados?" + } + } + } +} diff --git a/public/lang/ru.json b/public/lang/ru.json index b77751e7..c585b025 100644 --- a/public/lang/ru.json +++ b/public/lang/ru.json @@ -1,4 +1,12 @@ { + "common": { + "dialogs": { + "reset_settings": { + "title": "Сбросить настройки", + "message": "Сбросить все настройки к значениям по умолчанию?" + } + } + }, "context": { "app": { "starting_up": "Запуск...", @@ -39,4 +47,4 @@ } } } -} \ No newline at end of file +} diff --git a/src/components/Forms/Settings/SettingsForm.tsx b/src/components/Forms/Settings/SettingsForm.tsx index 47044770..ffaa6b84 100644 --- a/src/components/Forms/Settings/SettingsForm.tsx +++ b/src/components/Forms/Settings/SettingsForm.tsx @@ -43,12 +43,20 @@ export function SettingsForm({ onSubmit, value }: SettingsFormProps) { api.app.getDefaultSettings().then(setDefaultSettings).catch(console.error); }, []); - const isNotDefault = defaultSettings && JSON.stringify({ ...value, has_error: undefined, hide_save_button: undefined }) !== JSON.stringify(defaultSettings); + const isNotDefault = + defaultSettings && + JSON.stringify({ ...value, has_error: undefined, hide_save_button: undefined }) !== JSON.stringify(defaultSettings); const showButtons = isNotDefault || form.isDirty(); + const resetSettingsDialogTitle = useTranslateCommon("dialogs.reset_settings.title"); + const resetSettingsDialogMessage = useTranslateCommon("dialogs.reset_settings.message"); + const handleReset = async () => { - const confirmed = await confirm("Reset all settings to default values?", { kind: "warning" }); + const confirmed = await confirm(resetSettingsDialogMessage, { + kind: "warning", + title: resetSettingsDialogTitle, + }); if (!confirmed) return; try { const defaults = await api.app.getDefaultSettings();