Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat(settings): show the last successful WebDAV sync time

_Mr丶s ゛😁®6fd96a5e50d5
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue
index bc57c04e61..bcb2a0fd1f 100644
--- a/apps/desktop/src/App.vue
+++ b/apps/desktop/src/App.vue
@@ -73,7 +73,7 @@ import { disposeAllSqlServerActivityTraces } from "@/lib/sqlserver/sqlServerActi
import { useVisibilityChange } from "@/composables/useVisibilityChange";
import { useExternalSqlFileChanges } from "@/composables/useExternalSqlFileChanges";
import { useWebDavAutoUpload } from "@/composables/useWebDavAutoUpload";
-import { readSyncMethod, readWebDavAutoUploadConfig, readWebDavBackupSelection } from "@/lib/webdav/webdavAutoUploadConfig";
+import { readSyncMethod, readWebDavAutoUploadConfig, readWebDavBackupSelection, recordWebDavSyncSuccess } from "@/lib/webdav/webdavAutoUploadConfig";
import { useScheduledDatabaseBackups } from "@/composables/useScheduledDatabaseBackups";
import { shouldDrawDesktopWindowFrame, shouldDrawLinuxFloatingFrame, useWindowControls } from "@/composables/useWindowControls";
import { createOpenTabsRestorationBarrier, initializeDesktopOpenTabs, initializeOpenTabs, type OpenTabsRestorationBarrier } from "@/lib/app/openTabsStartup";
@@ -1298,6 +1298,7 @@ async function openImmediateSync() {
const selection = readWebDavBackupSelection();
const includeSecrets = Boolean((selection?.includeSecrets ?? secretsStatus.enabled) && secretsStatus.enabled && secretsStatus.hasSavedPassphrase);
const summary = await api.webdavSyncUpload(webDavConfig, settingsStore.editorSettings, undefined, includeSecrets, selection);
+ recordWebDavSyncSuccess(webDavConfig);
toast(t("settings.syncUploadSuccess", { bytes: summary.bytes, path: summary.remotePath }), 3000);
} catch (error: any) {
toast(error?.message || String(error), 5000);
diff --git a/apps/desktop/src/components/editor/EditorSettingsDialog.vue b/apps/desktop/src/components/editor/EditorSettingsDialog.vue
index 0b1fae0f2f..f3a16d8061 100644
--- a/apps/desktop/src/components/editor/EditorSettingsDialog.vue
+++ b/apps/desktop/src/components/editor/EditorSettingsDialog.vue
@@ -367,7 +367,11 @@ import {
MAX_WEB_DAV_AUTO_UPLOAD_INTERVAL_MINUTES,
formatWebDavAutoUploadInterval,
normalizedWebDavAutoUploadInterval,
+ readWebDavLastSuccessfulSync,
+ recordWebDavSyncSuccess,
readSyncMethod,
+ WEB_DAV_LAST_SUCCESSFUL_SYNC_STORAGE_KEY,
+ WEB_DAV_SYNC_SUCCESS_EVENT,
writeWebDavAutoUploadFields,
writeWebDavBackupSelection,
writeSyncMethod,
@@ -4684,6 +4688,11 @@ const webdavAutoUploadIntervalHint = computed(() => {
const webdavBusy = ref<"" | "test" | "upload" | "download">("");
const webdavMessage = ref("");
const webdavError = ref(false);
+const webdavLastSuccessfulSyncAt = ref<string | null>(null);
+const webdavLastSuccessfulSyncText = computed(() => {
+ if (!webdavLastSuccessfulSyncAt.value) return t("settings.syncNeverSuccessful");
+ return new Date(webdavLastSuccessfulSyncAt.value).toLocaleString(locale.value);
+});
const localBackupSecretsPassphrase = ref("");
const localBackupBusy = ref<"" | "export" | "import">("");
const localBackupMessage = ref("");
@@ -4919,6 +4928,14 @@ function currentWebDavConfig(): WebDavConfig {
};
}
+function refreshWebDavLastSuccessfulSync() {
+ webdavLastSuccessfulSyncAt.value = readWebDavLastSuccessfulSync(currentWebDavConfig());
+}
+
+function onWebDavSyncStatusStorage(event: StorageEvent) {
+ if (event.key === null || event.key === WEB_DAV_LAST_SUCCESSFUL_SYNC_STORAGE_KEY) refreshWebDavLastSuccessfulSync();
+}
+
function currentWebDavAccountConfig(): WebDavConfig {
const config = currentWebDavConfig();
return { ...config, password: undefined };
@@ -5182,7 +5199,9 @@ async function confirmSyncSelection(selection: SyncSelection) {
webdavSyncSecrets.value = selection.includeSecrets;
if (syncSelectionMode.value === "upload") {
await runWebDavAction("upload", async () => {
- const summary = await webdavSyncUpload(currentWebDavConfig(), settingsStore.editorSettings, selection.includeSecrets ? webdavSecretsPassphrase.value || undefined : undefined, selection.includeSecrets, selection);
+ const config = currentWebDavConfig();
+ const summary = await webdavSyncUpload(config, settingsStore.editorSettings, selection.includeSecrets ? webdavSecretsPassphrase.value || undefined : undefined, selection.includeSecrets, selection);
+ recordWebDavSyncSuccess(config);
writeWebDavBackupSelection(selection);
return t("settings.syncUploadSuccess", { bytes: summary.bytes, path: summary.remotePath });
});
@@ -5190,13 +5209,15 @@ async function confirmSyncSelection(selection: SyncSelection) {
}
await runWebDavAction("download", async () => {
- const result = await webdavSyncDownload(currentWebDavConfig(), selection.includeSecrets ? webdavSecretsPassphrase.value || undefined : undefined, selection.includeSecrets, selection);
+ const config = currentWebDavConfig();
+ const result = await webdavSyncDownload(config, selection.includeSecrets ? webdavSecretsPassphrase.value || undefined : undefined, selection.includeSecrets, selection);
if (result.editorSettings && typeof result.editorSettings === "object") settingsStore.updateEditorSettings(result.editorSettings as any);
await settingsStore.updateDesktopSettings(result.desktopSettings);
await connectionStore.initFromDisk();
await savedSqlStore.initFromStorage();
await tunnelProfileStore.refresh();
await settingsStore.reloadAiConfigs();
+ recordWebDavSyncSuccess(config);
const message = t("settings.syncDownloadSuccess", { bytes: result.summary.bytes, path: result.summary.remotePath });
if (result.applySummary.encryptedSecretsPresent && !result.applySummary.secretsApplied) return `${message} ${t("settings.syncSecretsSkipped")}`;
if (result.applySummary.secretsApplied) return `${message} ${t("settings.syncSecretsApplied")}`;
@@ -5337,6 +5358,7 @@ watch(
watch([webdavEndpoint, webdavUsername], () => {
void refreshWebDavPasswordStatus();
});
+watch([webdavEndpoint, webdavUsername, webdavRemotePath], refreshWebDavLastSuccessfulSync);
watch(webdavRememberPassword, (val) => {
localStorage.setItem("dbx-webdav-remember-password", String(val));
});
@@ -5411,6 +5433,9 @@ onMounted(() => {
// 留着,回到 DBX 时再把焦点还给录入按钮;同时把「窗口不在前台」这件事显示出来。
window.addEventListener("focus", onShortcutRecordingWindowFocus);
window.addEventListener("blur", onShortcutRecordingWindowBlur);
+ window.addEventListener(WEB_DAV_SYNC_SUCCESS_EVENT, refreshWebDavLastSuccessfulSync);
+ window.addEventListener("storage", onWebDavSyncStatusStorage);
+ refreshWebDavLastSuccessfulSync();
void refreshWebDavPasswordStatus();
if (!isWeb) void refreshCcSwitchPluginAvailability();
checkLayoutDescTruncation();
@@ -5425,6 +5450,8 @@ onUnmounted(() => {
window.removeEventListener("compositionstart", modifierDoubleTapRecorder.cancel, true);
window.removeEventListener("focus", onShortcutRecordingWindowFocus);
window.removeEventListener("blur", onShortcutRecordingWindowBlur);
+ window.removeEventListener(WEB_DAV_SYNC_SUCCESS_EVENT, refreshWebDavLastSuccessfulSync);
+ window.removeEventListener("storage", onWebDavSyncStatusStorage);
modifierDoubleTapRecorder.reset();
clearThemePaletteOptionPreview();
clearUiFontOptionPreview();
@@ -10260,6 +10287,9 @@ LIMIT 100;</pre>
</div>
</div>
+ <p class="text-xs text-muted-foreground" aria-live="polite">
+ {{ t("settings.syncLastSuccessful", { time: webdavLastSuccessfulSyncText }) }}
+ </p>
<div v-if="webdavMessage" class="text-xs" :class="webdavError ? 'text-destructive' : 'text-green-600 dark:text-green-400'">
{{ webdavMessage }}
</div>
diff --git a/apps/desktop/src/composables/useWebDavAutoUpload.ts b/apps/desktop/src/composables/useWebDavAutoUpload.ts
index 2194c72e25..7139cb503d 100644
--- a/apps/desktop/src/composables/useWebDavAutoUpload.ts
+++ b/apps/desktop/src/composables/useWebDavAutoUpload.ts
@@ -2,7 +2,7 @@ import { onMounted, onUnmounted } from "vue";
import { useSettingsStore } from "@/stores/settingsStore";
import { appendDebugLog } from "@/lib/backend/debugLog";
import { webdavSyncSecretsStatus, webdavSyncUpload } from "@/lib/backend/api";
-import { readWebDavAutoUploadConfig, readWebDavBackupSelection, WEB_DAV_AUTO_UPLOAD_STORAGE_KEYS } from "@/lib/webdav/webdavAutoUploadConfig";
+import { readWebDavAutoUploadConfig, readWebDavBackupSelection, recordWebDavSyncSuccess, WEB_DAV_AUTO_UPLOAD_STORAGE_KEYS } from "@/lib/webdav/webdavAutoUploadConfig";
export function useWebDavAutoUpload() {
const settingsStore = useSettingsStore();
@@ -59,6 +59,7 @@ export function useWebDavAutoUpload() {
const selection = readWebDavBackupSelection();
const includeSecrets = (selection?.includeSecrets ?? secretsStatus.enabled) && secretsStatus.enabled && secretsStatus.hasSavedPassphrase;
const summary = await webdavSyncUpload(config.webDavConfig, settingsStore.editorSettings, undefined, includeSecrets, selection);
+ recordWebDavSyncSuccess(config.webDavConfig);
appendDebugLog("info", "[DBX][webdav:auto-upload:success]", {
bytes: summary.bytes,
remotePath: summary.remotePath,
diff --git a/apps/desktop/src/i18n/locales/az.ts b/apps/desktop/src/i18n/locales/az.ts
index fdc0250d3f..4fbe638bc4 100644
--- a/apps/desktop/src/i18n/locales/az.ts
+++ b/apps/desktop/src/i18n/locales/az.ts
@@ -7798,6 +7798,8 @@ export default withEnglishFallback({
syncDownload: "Endir",
syncTestSuccess: "WebDAV hədəfi əlçatandır.",
syncUploadSuccess: "{path} yoluna {bytes} bayt yükləndi.",
+ syncLastSuccessful: "Son uğurlu sinxronizasiya: {time}",
+ syncNeverSuccessful: "Hələ uğurlu sinxronizasiya yoxdur",
syncAutoUpload: "Anlıq nüsxələri avtomatik yüklə",
syncAutoUploadInterval: "Hər",
syncAutoUploadMinutes: "dəqiqə",
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index 1afe7c61c5..77c8f93955 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -8943,6 +8943,8 @@ export default {
syncDownload: "Download",
syncTestSuccess: "WebDAV target is reachable.",
syncUploadSuccess: "Uploaded {bytes} bytes to {path}.",
+ syncLastSuccessful: "Last successful sync: {time}",
+ syncNeverSuccessful: "No successful sync yet",
syncAutoUpload: "Automatically upload snapshots",
syncAutoUploadInterval: "Every",
syncAutoUploadMinutes: "minutes",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index 1285c65616..9075b6800e 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -8180,6 +8180,8 @@ export default withEnglishFallback({
syncDownload: "Descargar",
syncTestSuccess: "El destino WebDAV está disponible.",
syncUploadSuccess: "Se subieron {bytes} bytes a {path}.",
+ syncLastSuccessful: "Última sincronización correcta: {time}",
+ syncNeverSuccessful: "Aún no hay sincronizaciones correctas",
syncAutoUpload: "Subir instantáneas automáticamente",
syncAutoUploadInterval: "Cada",
syncAutoUploadMinutes: "minutos",
diff --git a/apps/desktop/src/i18n/locales/id.ts b/apps/desktop/src/i18n/locales/id.ts
index d474c913c2..7d108af8b1 100644
--- a/apps/desktop/src/i18n/locales/id.ts
+++ b/apps/desktop/src/i18n/locales/id.ts
@@ -8603,6 +8603,8 @@ export default withEnglishFallback({
syncDownload: "Unduh",
syncTestSuccess: "Target WebDAV dapat dijangkau.",
syncUploadSuccess: "{bytes} byte berhasil diunggah ke {path}.",
+ syncLastSuccessful: "Sinkronisasi terakhir berhasil: {time}",
+ syncNeverSuccessful: "Belum ada sinkronisasi yang berhasil",
syncAutoUpload: "Unggah snapshot secara otomatis",
syncAutoUploadInterval: "Setiap",
syncAutoUploadMinutes: "menit",
diff --git a/apps/desktop/src/i18n/locales/it.ts b/apps/desktop/src/i18n/locales/it.ts
index 8a17a3eb88..b242acf9d0 100644
--- a/apps/desktop/src/i18n/locales/it.ts
+++ b/apps/desktop/src/i18n/locales/it.ts
@@ -7958,6 +7958,8 @@ export default withEnglishFallback({
syncDownload: "Scarica",
syncTestSuccess: "La destinazione WebDAV è raggiungibile.",
syncUploadSuccess: "Caricati {bytes} byte su {path}.",
+ syncLastSuccessful: "Ultima sincronizzazione riuscita: {time}",
+ syncNeverSuccessful: "Nessuna sincronizzazione riuscita",
syncAutoUpload: "Carica automaticamente gli snapshot",
syncAutoUploadInterval: "Ogni",
syncAutoUploadMinutes: "minuti",
diff --git a/apps/desktop/src/i18n/locales/ja.ts b/apps/desktop/src/i18n/locales/ja.ts
index 67298286ca..fc0e78cabd 100644
--- a/apps/desktop/src/i18n/locales/ja.ts
+++ b/apps/desktop/src/i18n/locales/ja.ts
@@ -7970,6 +7970,8 @@ export default withEnglishFallback({
syncDownload: "ダウンロード",
syncTestSuccess: "WebDAVターゲットに到達可能です。",
syncUploadSuccess: "{bytes}バイトを{path}にアップロードしました。",
+ syncLastSuccessful: "最終同期成功日時: {time}",
+ syncNeverSuccessful: "同期の成功記録はありません",
syncAutoUpload: "スナップショットを自動アップロード",
syncAutoUploadInterval: "間隔",
syncAutoUploadMinutes: "分",
diff --git a/apps/desktop/src/i18n/locales/ko.ts b/apps/desktop/src/i18n/locales/ko.ts
index 1a39d93395..700cbad9f0 100644
--- a/apps/desktop/src/i18n/locales/ko.ts
+++ b/apps/desktop/src/i18n/locales/ko.ts
@@ -7825,6 +7825,8 @@ export default withEnglishFallback({
syncDownload: "다운로드",
syncTestSuccess: "WebDAV 대상에 연결할 수 있습니다.",
syncUploadSuccess: "{path}에 {bytes}바이트를 업로드했습니다.",
+ syncLastSuccessful: "마지막 동기화 성공: {time}",
+ syncNeverSuccessful: "성공한 동기화 기록이 없습니다",
syncAutoUpload: "자동으로 스냅샷 업로드",
syncAutoUploadInterval: "매",
syncAutoUploadMinutes: "분",
diff --git a/apps/desktop/src/i18n/locales/pt-BR.ts b/apps/desktop/src/i18n/locales/pt-BR.ts
index ecc3ac8675..60ac138770 100644
--- a/apps/desktop/src/i18n/locales/pt-BR.ts
+++ b/apps/desktop/src/i18n/locales/pt-BR.ts
@@ -7957,6 +7957,8 @@ export default withEnglishFallback({
syncDownload: "Baixar",
syncTestSuccess: "O destino WebDAV está acessível.",
syncUploadSuccess: "Enviados {bytes} bytes para {path}.",
+ syncLastSuccessful: "Última sincronização bem-sucedida: {time}",
+ syncNeverSuccessful: "Ainda não houve uma sincronização bem-sucedida",
syncAutoUpload: "Enviar snapshots automaticamente",
syncAutoUploadInterval: "A cada",
syncAutoUploadMinutes: "minutos",
diff --git a/apps/desktop/src/i18n/locales/ru.ts b/apps/desktop/src/i18n/locales/ru.ts
index a92ae6dcc5..44c499e00a 100644
--- a/apps/desktop/src/i18n/locales/ru.ts
+++ b/apps/desktop/src/i18n/locales/ru.ts
@@ -9283,6 +9283,8 @@ export default withEnglishFallback({
syncDownload: "Скачать",
syncTestSuccess: "Цель WebDAV доступна.",
syncUploadSuccess: "Загружено {bytes} байт в {path}.",
+ syncLastSuccessful: "Последняя успешная синхронизация: {time}",
+ syncNeverSuccessful: "Успешных синхронизаций пока не было",
syncAutoUpload: "Автоматически загружать снимки",
syncAutoUploadInterval: "Каждые",
syncAutoUploadMinutes: "мин.",
diff --git a/apps/desktop/src/i18n/locales/tr.ts b/apps/desktop/src/i18n/locales/tr.ts
index 8a89d38626..528b459080 100644
--- a/apps/desktop/src/i18n/locales/tr.ts
+++ b/apps/desktop/src/i18n/locales/tr.ts
@@ -7696,6 +7696,8 @@ export default withEnglishFallback({
syncDownload: "İndir",
syncTestSuccess: "WebDAV hedefine erişilebiliyor.",
syncUploadSuccess: "{path} konumuna {bytes} bayt yüklendi.",
+ syncLastSuccessful: "Son başarılı eşitleme: {time}",
+ syncNeverSuccessful: "Henüz başarılı eşitleme yok",
syncAutoUpload: "Anlık görüntüleri otomatik yükle",
syncAutoUploadInterval: "Her",
syncAutoUploadMinutes: "dakika",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index 178ee48565..8b1bf612cd 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -8925,6 +8925,8 @@ export default withEnglishFallback({
syncDownload: "下载",
syncTestSuccess: "WebDAV 目标可访问。",
syncUploadSuccess: "已上传 {bytes} 字节到 {path}。",
+ syncLastSuccessful: "最近一次成功同步:{time}",
+ syncNeverSuccessful: "暂无成功同步记录",
syncAutoUpload: "自动上传快照",
syncAutoUploadInterval: "每",
syncAutoUploadMinutes: "分钟",
diff --git a/apps/desktop/src/i18n/locales/zh-TW.ts b/apps/desktop/src/i18n/locales/zh-TW.ts
index b3db92d600..4733ed9042 100644
--- a/apps/desktop/src/i18n/locales/zh-TW.ts
+++ b/apps/desktop/src/i18n/locales/zh-TW.ts
@@ -7302,6 +7302,8 @@ export default withEnglishFallback({
syncDownload: "下載",
syncTestSuccess: "WebDAV 目標可存取。",
syncUploadSuccess: "已上傳 {bytes} 位元組到 {path}。",
+ syncLastSuccessful: "最近一次成功同步:{time}",
+ syncNeverSuccessful: "尚無成功同步記錄",
syncAutoUpload: "自動上傳快照",
syncAutoUploadInterval: "每",
syncAutoUploadMinutes: "分鐘",
diff --git a/apps/desktop/src/lib/webdav/webdavAutoUploadConfig.spec.ts b/apps/desktop/src/lib/webdav/webdavAutoUploadConfig.spec.ts
index 008c6eb972..71414ff05b 100644
--- a/apps/desktop/src/lib/webdav/webdavAutoUploadConfig.spec.ts
+++ b/apps/desktop/src/lib/webdav/webdavAutoUploadConfig.spec.ts
@@ -1,5 +1,5 @@
-import { describe, expect, it } from "vitest";
-import { DEFAULT_WEB_DAV_AUTO_UPLOAD_INTERVAL_MINUTES, MAX_WEB_DAV_AUTO_UPLOAD_INTERVAL_MINUTES, formatWebDavAutoUploadInterval, normalizedWebDavAutoUploadInterval } from "./webdavAutoUploadConfig";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import { DEFAULT_WEB_DAV_AUTO_UPLOAD_INTERVAL_MINUTES, MAX_WEB_DAV_AUTO_UPLOAD_INTERVAL_MINUTES, WEB_DAV_LAST_SUCCESSFUL_SYNC_STORAGE_KEY, formatWebDavAutoUploadInterval, normalizedWebDavAutoUploadInterval, readWebDavLastSuccessfulSync, recordWebDavSyncSuccess } from "./webdavAutoUploadConfig";
const zhCnUnits = { minute: "分钟", hour: "小时", day: "天" };
@@ -23,3 +23,33 @@ describe("WebDAV auto-upload interval", () => {
expect(formatWebDavAutoUploadInterval(minutes, "zh-CN", zhCnUnits)).toEqual({ interval, approximate });
});
});
+
+describe("WebDAV last successful sync", () => {
+ const target = { endpoint: "https://example.com/dav", username: " user ", remotePath: " DBX/sync/snapshot.json " };
+ const values = new Map<string, string>();
+
+ beforeEach(() => {
+ values.clear();
+ vi.stubGlobal("localStorage", {
+ getItem: (key: string) => values.get(key) ?? null,
+ setItem: (key: string, value: string) => values.set(key, String(value)),
+ clear: () => values.clear(),
+ });
+ });
+
+ afterEach(() => vi.unstubAllGlobals());
+
+ it("shows the last success only for the matching WebDAV target", () => {
+ const completedAt = "2026-10-13T09:30:00.000Z";
+ recordWebDavSyncSuccess(target, completedAt);
+
+ expect(readWebDavLastSuccessfulSync({ ...target, username: "user", remotePath: "DBX/sync/snapshot.json" })).toBe(completedAt);
+ expect(readWebDavLastSuccessfulSync({ ...target, remotePath: "DBX/other/snapshot.json" })).toBeNull();
+ });
+
+ it("ignores malformed saved status", () => {
+ values.set(WEB_DAV_LAST_SUCCESSFUL_SYNC_STORAGE_KEY, "not-json");
+
+ expect(readWebDavLastSuccessfulSync(target)).toBeNull();
+ });
+});
diff --git a/apps/desktop/src/lib/webdav/webdavAutoUploadConfig.ts b/apps/desktop/src/lib/webdav/webdavAutoUploadConfig.ts
index 511fc1a45c..9b71316383 100644
--- a/apps/desktop/src/lib/webdav/webdavAutoUploadConfig.ts
+++ b/apps/desktop/src/lib/webdav/webdavAutoUploadConfig.ts
@@ -2,6 +2,8 @@ import type { SyncSelection, WebDavConfig } from "@/lib/backend/api";
import { safeLocalStorageGet, safeLocalStorageSet } from "@/lib/backend/safeStorage";
export const WEB_DAV_BACKUP_SELECTION_STORAGE_KEY = "dbx-webdav-backup-selection";
+export const WEB_DAV_LAST_SUCCESSFUL_SYNC_STORAGE_KEY = "dbx-webdav-last-successful-sync";
+export const WEB_DAV_SYNC_SUCCESS_EVENT = "dbx:webdav-sync-succeeded";
export const SYNC_METHOD_STORAGE_KEY = "dbx-sync-method";
export const WEB_DAV_AUTO_UPLOAD_STORAGE_KEYS = ["dbx-webdav-endpoint", "dbx-webdav-username", "dbx-webdav-user-agent", "dbx-webdav-remote-path", "dbx-webdav-auto-upload-enabled", "dbx-webdav-auto-upload-interval-minutes", WEB_DAV_BACKUP_SELECTION_STORAGE_KEY] as const;
@@ -26,6 +28,40 @@ export interface WebDavAutoUploadConfig {
webDavConfig: WebDavConfig | null;
}
+interface StoredWebDavSyncSuccess {
+ target: string;
+ completedAt: string;
+}
+
+function webDavSyncTarget(config: WebDavConfig): string {
+ return JSON.stringify({
+ endpoint: config.endpoint.trim(),
+ username: config.username?.trim() || "",
+ remotePath: config.remotePath?.trim() || DEFAULT_WEB_DAV_REMOTE_PATH,
+ });
+}
+
+export function readWebDavLastSuccessfulSync(config: WebDavConfig): string | null {
+ const serialized = safeLocalStorageGet(WEB_DAV_LAST_SUCCESSFUL_SYNC_STORAGE_KEY);
+ if (!serialized) return null;
+
+ try {
+ const stored = JSON.parse(serialized) as Partial<StoredWebDavSyncSuccess>;
+ if (stored.target !== webDavSyncTarget(config) || typeof stored.completedAt !== "string") return null;
+ return Number.isFinite(Date.parse(stored.completedAt)) ? stored.completedAt : null;
+ } catch {
+ return null;
+ }
+}
+
+export function recordWebDavSyncSuccess(config: WebDavConfig, completedAt = new Date().toISOString()): string {
+ const timestamp = new Date(completedAt).toISOString();
+ const stored: StoredWebDavSyncSuccess = { target: webDavSyncTarget(config), completedAt: timestamp };
+ safeLocalStorageSet(WEB_DAV_LAST_SUCCESSFUL_SYNC_STORAGE_KEY, JSON.stringify(stored));
+ if (typeof window !== "undefined") window.dispatchEvent(new Event(WEB_DAV_SYNC_SUCCESS_EVENT));
+ return timestamp;
+}
+
export function normalizedWebDavAutoUploadInterval(value: unknown): number {
const numberValue = Number(value);
if (!Number.isFinite(numberValue)) return DEFAULT_WEB_DAV_AUTO_UPLOAD_INTERVAL_MINUTES;