Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

fix: save desktop backup settings automatically

tianma-ifbfad318b08b6
diff --git a/apps/web/src/components/settings/DesktopScheduledBackupCard.tsx b/apps/web/src/components/settings/DesktopScheduledBackupCard.tsx
index 0e8fce42..9b26ed04 100644
--- a/apps/web/src/components/settings/DesktopScheduledBackupCard.tsx
+++ b/apps/web/src/components/settings/DesktopScheduledBackupCard.tsx
@@ -25,6 +25,7 @@ export const DesktopScheduledBackupCard = () => {
const [deleteError, setDeleteError] = useState<string | null>(null);
const [saving, setSaving] = useState(false);
const [error, setError] = useState<string | null>(null);
+ const settingsSaving = useRef(false);
const scope = useRef(status?.backupSetId);
const configKey = status ? JSON.stringify(status.config) : "";
useEffect(() => {
@@ -43,7 +44,35 @@ export const DesktopScheduledBackupCard = () => {
const dirty = JSON.stringify(config) !== configKey || Boolean(password);
const passwordNeeded = config.encrypted && status.secureStorageAvailable && (!status.passwordSet || changePassword);
const passwordValid = !passwordNeeded || (password.length > 0 && password === confirmation);
- const patch = (value: Partial<DesktopBackupConfig>) => setConfig({ ...config, ...value });
+ const saveConfig = async (next: DesktopBackupConfig) => {
+ if (settingsSaving.current) return;
+ const needsPassword = next.encrypted && status.secureStorageAvailable && (!status.passwordSet || changePassword);
+ setConfig(next);
+ if (needsPassword && (!password || password !== confirmation)) return;
+ const expected = status.backupSetId;
+ settingsSaving.current = true;
+ setError(null); setSaving(true);
+ try {
+ const saved = await bridge.backup("save", { backupSetId: expected, config: next, ...(needsPassword ? { password } : {}) });
+ if (scope.current === expected) {
+ setConfig(saved.config);
+ setPassword(""); setConfirmation(""); setChangePassword(false);
+ }
+ } catch (failure) {
+ if (scope.current === expected) {
+ setConfig(status.config);
+ setPassword(""); setConfirmation(""); setChangePassword(false);
+ setError(describeDesktopBackupError(t, failure));
+ }
+ } finally {
+ settingsSaving.current = false;
+ if (scope.current === expected) setSaving(false);
+ }
+ };
+ const patch = (value: Partial<DesktopBackupConfig>) => { void saveConfig({ ...config, ...value }); };
+ const savePasswordOnBlur = (event: React.FocusEvent<HTMLDivElement>) => {
+ if (!event.currentTarget.contains(event.relatedTarget) && passwordNeeded && passwordValid && password) void saveConfig(config);
+ };
const attempt = async (action: () => Promise<unknown>) => {
const expected = status.backupSetId;
setError(null); setSaving(true);
@@ -76,7 +105,7 @@ export const DesktopScheduledBackupCard = () => {
{lastBackup ? <p className="text-slate-700">{t("desktopBackup.lastBackupSize", { size: formatBytes(lastBackup.size) })}</p> : null}
{status.task ? <p className="flex items-center gap-2"><Loader2 className="h-3.5 w-3.5 animate-spin" />{t(`desktopBackup.phases.${status.task.phase}`)}{status.task.total > 0 ? ` ${status.task.completed} / ${status.task.total}` : ""}</p> : status.lastCheck ? <p className="text-slate-700">{t(`desktopBackup.checkResults.${status.lastCheck.result}`)}</p> : null}
<p className="text-muted-foreground">{t("desktopBackup.lastCheck", { time: status.lastCheck ? date(status.lastCheck.at) : t("desktopBackup.notChecked") })}</p>
- <p className="text-muted-foreground">{status.config.enabled ? t("desktopBackup.nextDue", { time: status.nextDueAt ? date(status.nextDueAt) : t("desktopBackup.whenReady") }) : t("desktopBackup.autoOff")}</p>
+ <p className={dirty ? "text-amber-700" : "text-muted-foreground"}>{dirty ? t(saving ? "desktopBackup.savingSettings" : "desktopBackup.completePassword") : status.config.enabled ? t("desktopBackup.nextDue", { time: status.nextDueAt ? date(status.nextDueAt) : t("desktopBackup.whenReady") }) : t("desktopBackup.autoOff")}</p>
{error || status.error ? <p className="break-words text-destructive" role="alert">{error ?? describeDesktopBackupError(t, status.error)}</p> : null}
{status.warning ? <p className="text-amber-700">{describeDesktopBackupError(t, status.warning)}</p> : null}
</div>
@@ -95,7 +124,7 @@ export const DesktopScheduledBackupCard = () => {
<span className="text-xs font-medium text-slate-700">{t("desktopBackup.directory")}</span>
<div className="flex min-w-0 items-center gap-2">
<p className="min-w-0 flex-1 break-all rounded-md bg-muted px-2.5 py-1.5 font-mono text-xs text-muted-foreground">{config.directory}/{status.backupSetId}</p>
- <Button type="button" variant="outline" size="sm" className="h-8 text-xs font-normal" onClick={() => void attempt(async () => { const directory = await bridge.backup("choose-directory", { backupSetId: status.backupSetId }); if (directory && scope.current === status.backupSetId) patch({ directory }); })}>{t("desktopBackup.choose")}</Button>
+ <Button type="button" variant="outline" size="sm" className="h-8 text-xs font-normal" onClick={() => void attempt(async () => { const directory = await bridge.backup("choose-directory", { backupSetId: status.backupSetId }); if (directory && scope.current === status.backupSetId) await saveConfig({ ...config, directory }); })}>{t("desktopBackup.choose")}</Button>
</div>
</div>
<div className="grid grid-cols-2 gap-4">
@@ -120,10 +149,10 @@ export const DesktopScheduledBackupCard = () => {
</label>
{config.encrypted && !status.secureStorageAvailable ? <p className="text-xs text-amber-700">{t("desktopBackup.secureUnavailable")}</p> : null}
{config.encrypted && status.passwordSet && !changePassword ? <div className="flex items-center justify-between gap-2 text-xs"><span className="text-muted-foreground">{t("desktopBackup.passwordSet")}</span><Button type="button" variant="ghost" size="sm" className="h-7 text-xs font-normal" onClick={() => setChangePassword(true)}>{t("desktopBackup.changePassword")}</Button></div> : null}
- {passwordNeeded ? <div className="grid gap-2"><Input className="h-8 text-xs" type="password" autoComplete="new-password" aria-label={t("desktopBackup.password")} placeholder={t("desktopBackup.password")} value={password} onChange={(event) => setPassword(event.target.value)} /><Input className="h-8 text-xs" type="password" autoComplete="new-password" aria-label={t("desktopBackup.confirmPassword")} placeholder={t("desktopBackup.confirmPassword")} value={confirmation} onChange={(event) => setConfirmation(event.target.value)} />{confirmation && password !== confirmation ? <p className="text-xs text-destructive" role="alert">{t("desktopBackup.passwordMismatch")}</p> : null}<p className="text-xs text-muted-foreground">{t("desktopBackup.passwordChangeNote")}</p></div> : null}
+ {passwordNeeded ? <div className="grid gap-2" onBlur={savePasswordOnBlur}><Input className="h-8 text-xs" type="password" autoComplete="new-password" aria-label={t("desktopBackup.password")} placeholder={t("desktopBackup.password")} value={password} onChange={(event) => setPassword(event.target.value)} /><Input className="h-8 text-xs" type="password" autoComplete="new-password" aria-label={t("desktopBackup.confirmPassword")} placeholder={t("desktopBackup.confirmPassword")} value={confirmation} onChange={(event) => setConfirmation(event.target.value)} />{confirmation && password !== confirmation ? <p className="text-xs text-destructive" role="alert">{t("desktopBackup.passwordMismatch")}</p> : null}<p className="text-xs text-muted-foreground">{t("desktopBackup.passwordChangeNote")}</p></div> : null}
</div>
</fieldset>
- <Button className="h-8 justify-self-start text-xs font-normal" size="sm" type="button" disabled={busy || saving || !dirty || !passwordValid} onClick={() => void attempt(async () => { await bridge.backup("save", { backupSetId: status.backupSetId, config, ...(passwordNeeded ? { password } : {}) }); if (scope.current === status.backupSetId) { setPassword(""); setConfirmation(""); setChangePassword(false); } })}>{t("common.save")}</Button>
+ {dirty || saving ? <p className="text-xs text-muted-foreground" role="status">{t(saving ? "desktopBackup.savingSettings" : "desktopBackup.completePassword")}</p> : null}
</div>
</details>
<section className="grid gap-2.5 border-t pt-3" aria-label={t("desktopBackup.history", { count: status.history.length })}>
diff --git a/packages/shared/src/i18n/en-US.ts b/packages/shared/src/i18n/en-US.ts
index 418870f5..98eda27d 100644
--- a/packages/shared/src/i18n/en-US.ts
+++ b/packages/shared/src/i18n/en-US.ts
@@ -2072,6 +2072,8 @@ export const enUS = {
lastCheck: "Latest check: {{time}}",
notChecked: "Not checked yet",
autoOff: "Automatic backup is off",
+ savingSettings: "Saving backup settings…",
+ completePassword: "Enter and confirm the backup password. Settings save automatically when you leave the password fields.",
deleteTitle: "Delete this backup?",
deleteDescription: "Permanently delete the local file “{{name}}”. This cannot be undone. Restored notes will remain.",
deleteConfirm: "Delete permanently",
diff --git a/packages/shared/src/i18n/ja.ts b/packages/shared/src/i18n/ja.ts
index bfcd8158..604e0af8 100644
--- a/packages/shared/src/i18n/ja.ts
+++ b/packages/shared/src/i18n/ja.ts
@@ -2061,6 +2061,8 @@ export const ja = {
lastCheck: "最終確認:{{time}}",
notChecked: "未確認",
autoOff: "自動バックアップはオフです",
+ savingSettings: "バックアップ設定を保存中…",
+ completePassword: "バックアップパスワードを入力し、確認してください。パスワード欄から離れると自動保存されます。",
deleteTitle: "このバックアップを削除しますか?",
deleteDescription: "ローカルファイル「{{name}}」を完全に削除します。元に戻せません。復元済みのノートは残ります。",
deleteConfirm: "完全に削除",
diff --git a/packages/shared/src/i18n/pl.ts b/packages/shared/src/i18n/pl.ts
index 8080e5ee..87f5d0dc 100644
--- a/packages/shared/src/i18n/pl.ts
+++ b/packages/shared/src/i18n/pl.ts
@@ -2061,6 +2061,8 @@ export const pl = {
lastCheck: "Ostatnie sprawdzenie: {{time}}",
notChecked: "Jeszcze nie sprawdzono",
autoOff: "Automatyczne kopie są wyłączone",
+ savingSettings: "Zapisywanie ustawień kopii…",
+ completePassword: "Wpisz i potwierdź hasło kopii. Ustawienia zapiszą się automatycznie po opuszczeniu pól hasła.",
deleteTitle: "Usunąć tę kopię?",
deleteDescription: "Trwale usuń lokalny plik „{{name}}”. Tej czynności nie można cofnąć. Przywrócone notatki pozostaną.",
deleteConfirm: "Usuń trwale",
diff --git a/packages/shared/src/i18n/ru.ts b/packages/shared/src/i18n/ru.ts
index f5249a27..15ef96f8 100644
--- a/packages/shared/src/i18n/ru.ts
+++ b/packages/shared/src/i18n/ru.ts
@@ -2072,6 +2072,8 @@ export const ru = {
lastCheck: "Последняя проверка: {{time}}",
notChecked: "Проверок ещё не было",
autoOff: "Автоматическое копирование отключено",
+ savingSettings: "Сохранение настроек копирования…",
+ completePassword: "Введите и подтвердите пароль копии. Настройки сохранятся автоматически при выходе из полей пароля.",
deleteTitle: "Удалить эту резервную копию?",
deleteDescription: "Локальный файл «{{name}}» будет удалён безвозвратно. Восстановленные заметки сохранятся.",
deleteConfirm: "Удалить навсегда",
diff --git a/packages/shared/src/i18n/zh-CN.ts b/packages/shared/src/i18n/zh-CN.ts
index 2c341093..4bce96c7 100644
--- a/packages/shared/src/i18n/zh-CN.ts
+++ b/packages/shared/src/i18n/zh-CN.ts
@@ -2072,6 +2072,8 @@ export const zhCN = {
lastCheck: "最近检查:{{time}}",
notChecked: "尚未检查",
autoOff: "自动备份已关闭",
+ savingSettings: "正在保存备份设置…",
+ completePassword: "请完成并确认备份密码,离开密码输入区域后自动保存。",
deleteTitle: "删除这份备份?",
deleteDescription: "将永久删除本地文件“{{name}}”,无法撤销。已恢复的笔记不受影响。",
deleteConfirm: "永久删除",
diff --git a/tests/browser/desktop-backup-import.browser.tsx b/tests/browser/desktop-backup-import.browser.tsx
index 45e612b2..2ee95442 100644
--- a/tests/browser/desktop-backup-import.browser.tsx
+++ b/tests/browser/desktop-backup-import.browser.tsx
@@ -28,6 +28,7 @@ let encrypted = true;
let holdHandshake = false;
let runError = false;
let deleteError = false;
+const saveError = new URLSearchParams(location.search).has("save-error");
let finish: (() => void) | undefined;
Object.defineProperty(window, "edgeeverDesktop", {
configurable: true,
@@ -41,6 +42,8 @@ Object.defineProperty(window, "edgeeverDesktop", {
status.history.push({ name: option.name.replace(/(?:\.edgeever\.enc|\.zip)$/i, "") + (option.encrypted ? ".edgeever.enc" : ".zip"), directory: status.config.directory, completedAt: at, size: 149755, encrypted: option.encrypted });
status.lastSuccessAt = at; status.lastCheck = { at, result: "success" }; emit();
}
+ if (action === "save" && saveError) throw Object.assign(new Error("Denied"), { code: "backup_directory_unavailable" });
+ if (action === "choose-directory") return "/test/SelectedBackups";
if (action === "save") { status.config = value!.config!; if (value?.password) status.passwordSet = true; emit(); }
if (action === "delete-history") {
if (deleteError) throw Object.assign(new Error("Denied"), { code: "EACCES" });