diff --git a/public/lang/en.json b/public/lang/en.json index 0c468171..e31c8ade 100644 --- a/public/lang/en.json +++ b/public/lang/en.json @@ -19,10 +19,19 @@ "save": { "label": "Save" }, + "reset_defaults": { + "label": "Reset to Default" + }, "delete": { "label": "Delete" } }, + "dialogs": { + "reset_settings": { + "title": "Reset settings", + "message": "Reset all settings to default values?" + } + }, "notifications": { "copy_to_clipboard": { "title": "Copied to Clipboard", @@ -2455,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-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..ffaa6b84 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,35 @@ 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 resetSettingsDialogTitle = useTranslateCommon("dialogs.reset_settings.title"); + const resetSettingsDialogMessage = useTranslateCommon("dialogs.reset_settings.message"); + + const handleReset = async () => { + const confirmed = await confirm(resetSettingsDialogMessage, { + kind: "warning", + title: resetSettingsDialogTitle, + }); + 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 +125,12 @@ export function SettingsForm({ onSubmit, value }: SettingsFormProps) { ))} - + + {isNotDefault && ( + + )}