Storage (desktop): - The webview can no longer name a path. Five commands that read, wrote, listed and deleted any path the frontend sent are replaced by name-only commands (backups, logs) that resolve under the app data folder, and by export/import commands that open the native dialog from Rust, so the only file touched is the one the user picked (json/jsonl/txt/csv/md, 20 MB). The fs and shell plugins are removed (Rust, npm, capabilities). - The settings "mirror" file is gone: it was written next to the data folder (a missing path separator) and never read back. On first start the file becomes a restorable backup — never applied on its own — and the stray log folder is merged into the right one. - Automatic backups on desktop: after library changes (quiet 30 s, at most every 10 min, skipped when unchanged or empty), newest ten kept, plus one before every restore. Settings lists them with Restore. - One tray icon, built in code with the app icon (the config entry that could add a second, iconless one is removed). Backup & restore (every platform): - Format 2 files carry each section's store version; imports run the stores' own migrations (now exported functions), then a whitelist sanitizer: known fields and values only, editor limits, safe unique ids. - Reads every earlier export: v0.15-v0.38 envelopes (log exports were labelled "history"), pre-v0.15 bare arrays, the old desktop data file. - Restore dialog: new / already here / different per item, merge (keep the newer one, or both) or replace, section and item selection, one step, Undo. Newer-version sections are shown, not restored. - Settings: Back up (choose sections) / Restore / drop a file. Consent and panel state are never exported or overwritten. - History export as CSV (spreadsheet-safe) or JSON; logs export as "logs"; dated file names; no more 250 ms timer guessing that a picker was cancelled. Library: - Templates save every editor field; presets save store link types and the other per-game fields; profiles save donate, community links and the custom graphics preset. Edit forms can update from the current editor, start fresh each time they open, and save on Enter. Toasts translated. Dev: Vite no longer watches src-tauri (cargo's locked .dll crashed `tauri dev` on Windows). Verified in `tauri dev` on Windows under a test identifier: legacy file recovered, old logs merged, auto backup, restore from the legacy backup with a backup before it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
3.2 KiB
TypeScript
95 lines
3.2 KiB
TypeScript
import { useId, useState, type FormEvent } from "react";
|
|
import { useTranslation } from "react-i18next";
|
|
import { toast } from "sonner";
|
|
import { Modal } from "@components/ui/Modal";
|
|
import { Button } from "@components/ui/Button";
|
|
import { Input } from "@components/ui/Input";
|
|
import { Checkbox } from "@components/ui/Checkbox";
|
|
import { editorDataOf, useEditorStore } from "@store/editor-store";
|
|
import { useTemplateStore, type EditorTemplate } from "@store/template-store";
|
|
import { FIELD_LIMITS } from "@config/field-limits";
|
|
|
|
interface TemplateSaveFormProps {
|
|
open: boolean;
|
|
onClose: () => void;
|
|
editTemplate?: EditorTemplate;
|
|
}
|
|
|
|
/**
|
|
* Save the whole editor form as a template (every field — templates saved
|
|
* before v1.0.0 kept only part of it), or rename / refresh one. Mounted only
|
|
* while open, so it always starts from the template as it is now.
|
|
*/
|
|
export function TemplateSaveForm(props: TemplateSaveFormProps) {
|
|
return props.open ? <TemplateSaveFormBody {...props} /> : null;
|
|
}
|
|
|
|
function TemplateSaveFormBody({ onClose, editTemplate }: TemplateSaveFormProps) {
|
|
const { t } = useTranslation("ui");
|
|
const formId = useId();
|
|
const addTemplate = useTemplateStore((s) => s.addTemplate);
|
|
const updateTemplate = useTemplateStore((s) => s.updateTemplate);
|
|
const [name, setName] = useState(editTemplate?.name ?? "");
|
|
const [fromEditor, setFromEditor] = useState(false);
|
|
|
|
const save = (e: FormEvent) => {
|
|
e.preventDefault();
|
|
const snapshot = structuredClone(editorDataOf(useEditorStore.getState()));
|
|
const finalName = name.trim() || snapshot.gameName.trim() || t("templates.unnamed");
|
|
if (editTemplate) {
|
|
updateTemplate(editTemplate.id, {
|
|
name: finalName,
|
|
snapshot: fromEditor ? snapshot : undefined,
|
|
});
|
|
toast.success(t("templates.updated", { name: finalName }));
|
|
} else {
|
|
addTemplate(finalName, snapshot);
|
|
toast.success(t("templates.savedAs", { name: finalName }));
|
|
}
|
|
onClose();
|
|
};
|
|
|
|
return (
|
|
<Modal
|
|
open
|
|
onClose={onClose}
|
|
title={editTemplate ? t("templates.editTemplate") : t("templates.saveAsTemplate")}
|
|
footer={
|
|
<>
|
|
<Button variant="ghost" onClick={onClose}>
|
|
{t("common.cancel")}
|
|
</Button>
|
|
<Button type="submit" form={formId}>
|
|
{t("common.save")}
|
|
</Button>
|
|
</>
|
|
}
|
|
>
|
|
<form id={formId} onSubmit={save} className="flex flex-col gap-3">
|
|
<Input
|
|
label={t("templates.templateName")}
|
|
maxLength={FIELD_LIMITS.SHORT_NAME}
|
|
placeholder={t("templates.templateNamePlaceholder")}
|
|
value={name}
|
|
onChange={(e) => setName(e.target.value)}
|
|
autoFocus
|
|
/>
|
|
{editTemplate ? (
|
|
<Checkbox
|
|
checked={fromEditor}
|
|
onChange={setFromEditor}
|
|
label={
|
|
<span className="flex flex-col gap-0.5">
|
|
<span className="text-text-primary text-sm">{t("templates.updateFromEditor")}</span>
|
|
<span className="text-text-muted text-xs">{t("templates.saveHint")}</span>
|
|
</span>
|
|
}
|
|
/>
|
|
) : (
|
|
<p className="text-text-muted text-xs">{t("templates.saveHint")}</p>
|
|
)}
|
|
</form>
|
|
</Modal>
|
|
);
|
|
}
|