fix(sync): refresh tunnel profiles after download

This commit is contained in:
t8y2 committed 2026-07-14 11:04:45 +08:00
1 parent 73f11f4265
commit 2666ed1cd2
2 files changed
+37

No files matched your search

@@ -104,6 +104,7 @@ import { APP_THEME_PALETTES, type AppThemeAppearance, type AppThemeMode, type Ap
import { editorSettingsDraftChanged, editorSettingsDraftFromSettings, editorSettingsPatchFromDraft, type EditorSettingsDraft } from "@/lib/settings/editorSettingsDraft"; import { editorSettingsDraftChanged, editorSettingsDraftFromSettings, editorSettingsPatchFromDraft, type EditorSettingsDraft } from "@/lib/settings/editorSettingsDraft";
import { useConnectionStore } from "@/stores/connectionStore"; import { useConnectionStore } from "@/stores/connectionStore";
import { useSavedSqlStore } from "@/stores/savedSqlStore"; import { useSavedSqlStore } from "@/stores/savedSqlStore";
import { useTunnelProfileStore } from "@/stores/tunnelProfileStore";
import { currentLocale, setLocale, type Locale } from "@/i18n"; import { currentLocale, setLocale, type Locale } from "@/i18n";
import { LOCALE_OPTIONS } from "@/lib/app/localeOptions"; import { LOCALE_OPTIONS } from "@/lib/app/localeOptions";
import { DEFAULT_WEB_DAV_AUTO_UPLOAD_INTERVAL_MINUTES, DEFAULT_WEB_DAV_REMOTE_PATH, normalizedWebDavAutoUploadInterval, writeWebDavAutoUploadFields } from "@/lib/webdav/webdavAutoUploadConfig"; import { DEFAULT_WEB_DAV_AUTO_UPLOAD_INTERVAL_MINUTES, DEFAULT_WEB_DAV_REMOTE_PATH, normalizedWebDavAutoUploadInterval, writeWebDavAutoUploadFields } from "@/lib/webdav/webdavAutoUploadConfig";
@@ -116,6 +117,7 @@ const { toast } = useToast();
const settingsStore = useSettingsStore(); const settingsStore = useSettingsStore();
const connectionStore = useConnectionStore(); const connectionStore = useConnectionStore();
const savedSqlStore = useSavedSqlStore(); const savedSqlStore = useSavedSqlStore();
const tunnelProfileStore = useTunnelProfileStore();
const { isDark, themeMode, themePalette, setThemeMode, setThemePalette } = useTheme(); const { isDark, themeMode, themePalette, setThemeMode, setThemePalette } = useTheme();
const appThemePaletteOptions = computed( const appThemePaletteOptions = computed(
@@ -1583,6 +1585,9 @@ async function downloadSnippetSnapshot() {
await settingsStore.updateDesktopSettings(result.desktopSettings); await settingsStore.updateDesktopSettings(result.desktopSettings);
await connectionStore.initFromDisk(); await connectionStore.initFromDisk();
await savedSqlStore.initFromStorage(); await savedSqlStore.initFromStorage();
// Snapshot downloads replace backend-managed tunnel profiles, so refresh
// the already-loaded Pinia store instead of leaving the UI stale.
await tunnelProfileStore.refresh();
let message = t("settings.syncSnippetDownloadSuccess", { bytes: result.summary.bytes, id: result.summary.snippetId }); let message = t("settings.syncSnippetDownloadSuccess", { bytes: result.summary.bytes, id: result.summary.snippetId });
if (result.applySummary.encryptedSecretsPresent && !result.applySummary.secretsApplied) message += ` ${t("settings.syncSecretsSkipped")}`; if (result.applySummary.encryptedSecretsPresent && !result.applySummary.secretsApplied) message += ` ${t("settings.syncSecretsSkipped")}`;
if (result.applySummary.secretsApplied) message += ` ${t("settings.syncSecretsApplied")}`; if (result.applySummary.secretsApplied) message += ` ${t("settings.syncSecretsApplied")}`;
@@ -1719,6 +1724,8 @@ async function downloadWebDavSnapshot() {
await settingsStore.updateDesktopSettings(result.desktopSettings); await settingsStore.updateDesktopSettings(result.desktopSettings);
await connectionStore.initFromDisk(); await connectionStore.initFromDisk();
await savedSqlStore.initFromStorage(); await savedSqlStore.initFromStorage();
// Keep the shared tunnel profile UI consistent with the downloaded snapshot.
await tunnelProfileStore.refresh();
const message = t("settings.syncDownloadSuccess", { const message = t("settings.syncDownloadSuccess", {
bytes: result.summary.bytes, bytes: result.summary.bytes,
path: result.summary.remotePath, path: result.summary.remotePath,
+30
View File
@@ -0,0 +1,30 @@
import { strict as assert } from "node:assert";
import { readFileSync } from "node:fs";
import { test } from "vitest";
function functionBody(source: string, name: string): string {
const signature = `async function ${name}(`;
const signatureIndex = source.indexOf(signature);
assert.notEqual(signatureIndex, -1, `Could not find function ${name}`);
const bodyStart = source.indexOf("{", signatureIndex);
assert.notEqual(bodyStart, -1, `Could not find body for ${name}`);
let depth = 0;
for (let index = bodyStart; index < source.length; index += 1) {
if (source[index] === "{") depth += 1;
if (source[index] === "}") {
depth -= 1;
if (depth === 0) return source.slice(bodyStart + 1, index);
}
}
throw new Error(`Could not parse body for ${name}`);
}
test("sync downloads refresh shared tunnel profiles", () => {
const source = readFileSync("apps/desktop/src/components/editor/EditorSettingsDialog.vue", "utf8");
for (const functionName of ["downloadSnippetSnapshot", "downloadWebDavSnapshot"]) {
const body = functionBody(source, functionName);
assert.match(body, /await tunnelProfileStore\.refresh\(\)/, `${functionName} should refresh downloaded tunnel profiles`);
}
});