Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion public/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -2455,4 +2464,4 @@
}
}
}
}
}
11 changes: 10 additions & 1 deletion public/lang/es.json
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
{}
{
"common": {
"dialogs": {
"reset_settings": {
"title": "Restablecer configuración",
"message": "¿Restablecer toda la configuración a los valores predeterminados?"
}
}
}
}
10 changes: 9 additions & 1 deletion public/lang/ru.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"common": {
"dialogs": {
"reset_settings": {
"title": "Сбросить настройки",
"message": "Сбросить все настройки к значениям по умолчанию?"
}
}
},
"context": {
"app": {
"starting_up": "Запуск...",
Expand Down Expand Up @@ -39,4 +47,4 @@
}
}
}
}
}
5 changes: 5 additions & 0 deletions src-tauri/src/commands/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ pub async fn app_get_settings(app: tauri::State<'_, Mutex<AppState>>) -> Result<
Ok(app.settings.clone())
}

#[tauri::command]
pub async fn app_get_default_settings() -> Result<Settings, Error> {
Ok(Settings::default())
}

#[tauri::command]
pub async fn app_update_settings(
mut settings: Settings,
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/api/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ export class AppModule {
notify_reset(id: string): Promise<TauriTypes.NotificationSetting> {
return this.client.sendInvoke<TauriTypes.NotificationSetting>("app_notify_reset", { id });
}
getDefaultSettings(): Promise<TauriTypes.Settings> {
return this.client.sendInvoke<TauriTypes.Settings>("app_get_default_settings");
}
}
39 changes: 38 additions & 1 deletion src/components/Forms/Settings/SettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -34,6 +37,35 @@ export function SettingsForm({ onSubmit, value }: SettingsFormProps) {
},
});

const [defaultSettings, setDefaultSettings] = useState<TauriTypes.Settings | null>(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"),
Expand Down Expand Up @@ -93,7 +125,12 @@ export function SettingsForm({ onSubmit, value }: SettingsFormProps) {
</Tabs.Panel>
))}
</Tabs>
<Group justify="flex-end" mt="md" display={form.isDirty() ? "" : "none"}>
<Group justify="flex-end" mt="md" display={showButtons ? "" : "none"}>
{isNotDefault && (
<Button pos="absolute" bottom={10} right={130} onClick={handleReset} color="red" variant="outline">
{useTranslateCommon("buttons.reset_defaults.label")}
</Button>
)}
<Button pos="absolute" bottom={10} right={10} onClick={() => onSubmit(form.values)} color="green">
{useTranslateCommon("buttons.save.label")}
</Button>
Expand Down