feat(cloud-sync): add selective backup and restore
This commit is contained in:
1 parent
e432304dbc
commit
a75d343666
23 files changed
+2427
-216
No files matched your search
@@ -0,0 +1,431 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import type { SyncCatalogItem, SyncSelection, SyncSnapshotCatalog } from "@/lib/backend/api";
|
||||
import { transferCategoryForKey, type SettingsTransferCategoryId } from "@/lib/settings/settingsTransfer";
|
||||
|
||||
type BackupSettingsCategoryId = Exclude<SettingsTransferCategoryId, "other"> | "ai";
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean;
|
||||
mode: "upload" | "restore";
|
||||
catalog: SyncSnapshotCatalog | null;
|
||||
defaultIncludeSecrets?: boolean;
|
||||
}>();
|
||||
const { t } = useI18n();
|
||||
|
||||
const emit = defineEmits<{
|
||||
"update:open": [value: boolean];
|
||||
confirm: [selection: SyncSelection];
|
||||
}>();
|
||||
|
||||
const selection = ref<SyncSelection>(emptySelection());
|
||||
const isRestore = computed(() => props.mode === "restore");
|
||||
|
||||
const backupSettingsCategoryOrder: readonly BackupSettingsCategoryId[] = ["appearance", "editor", "formatter", "navigation", "data", "shortcuts", "snippets", "ai"];
|
||||
const backupSettingsCategoryLabelKeys: Record<BackupSettingsCategoryId, string> = {
|
||||
appearance: "settings.appearanceTab",
|
||||
ai: "settings.aiTab",
|
||||
editor: "settings.editorTab",
|
||||
formatter: "settings.sqlFormatterTab",
|
||||
navigation: "settings.navigationTab",
|
||||
data: "settings.dataTab",
|
||||
shortcuts: "settings.shortcutsTab",
|
||||
snippets: "settings.snippetsTab",
|
||||
};
|
||||
const nonSyncableEditorSettingIds = new Set(["updateNotificationsEnabled", "autoDownloadUpdates", "autoUpdateApp", "autoUpdateDrivers", "autoUpdateJdbc", "autoUpdateMcp", "autoUpdatePlugins", "updateDownloadSource", "ignoredUpdateVersion"]);
|
||||
const desktopSettingCategories: Record<string, BackupSettingsCategoryId> = {
|
||||
show_tray_icon: "appearance",
|
||||
icon_theme: "appearance",
|
||||
quit_on_close: "appearance",
|
||||
close_action_prompted: "appearance",
|
||||
sidebar_table_page_size: "navigation",
|
||||
metadata_cache_max_memory_mb: "data",
|
||||
duckdb_worker_process_isolation: "data",
|
||||
duckdb_worker_max_processes: "data",
|
||||
};
|
||||
const editorSettingCategoryOverrides: Partial<Record<string, BackupSettingsCategoryId>> = {
|
||||
aiFontFamily: "ai",
|
||||
aiFontSize: "ai",
|
||||
customThemeColors: "appearance",
|
||||
appLayout: "appearance",
|
||||
tabLayout: "appearance",
|
||||
tabPlacement: "appearance",
|
||||
tabGroupMode: "appearance",
|
||||
tabGroupCustomizations: "appearance",
|
||||
tabSortMode: "appearance",
|
||||
compactTabTitle: "appearance",
|
||||
executeModeDefaultVersion: "editor",
|
||||
globalConnectTimeoutSecs: "editor",
|
||||
connectTimeoutInheritConnectionIds: "editor",
|
||||
globalQueryTimeoutSecs: "editor",
|
||||
queryTimeoutInheritConnectionIds: "editor",
|
||||
timeoutInheritanceMigrationVersion: "editor",
|
||||
blockDangerousRedisCommands: "editor",
|
||||
tableDdlWordWrap: "editor",
|
||||
refreshDdlOnOpen: "editor",
|
||||
excludeDdlStorage: "editor",
|
||||
sqlSemanticDiagnosticsEnabled: "editor",
|
||||
infiniteScrollMaxRows: "data",
|
||||
tableFontSize: "data",
|
||||
mongoViewMode: "data",
|
||||
dataGridMultiRowTranspose: "data",
|
||||
dataGridHideNullColumns: "data",
|
||||
dataGridBooleanDisplayMode: "data",
|
||||
numericColumnRightAlign: "data",
|
||||
structureEditorDensity: "data",
|
||||
tableInfoActiveTab: "data",
|
||||
tableInfoDrawerPinned: "data",
|
||||
tableInfoDrawerWidth: "data",
|
||||
cellDetailDrawerWidth: "data",
|
||||
cellDetailPanelLayout: "data",
|
||||
cellDetailJsonFormatted: "data",
|
||||
cellDetailMetadataCollapsed: "data",
|
||||
localFilterPopoverWidth: "data",
|
||||
dataGridRenderMode: "data",
|
||||
dataGridSearchMode: "data",
|
||||
dataGridRowNumberMode: "data",
|
||||
dataGridCopyExtractor: "data",
|
||||
dataGridExtractorOptions: "data",
|
||||
dataGridExtractorOptionsMigrationVersion: "data",
|
||||
resultRunDisplayMode: "data",
|
||||
dataGridTextFilterPanelHeight: "data",
|
||||
columnWidthDensity: "data",
|
||||
dataGridColumnWidthMode: "data",
|
||||
sidebarConnectionSortMode: "navigation",
|
||||
sidebarTableSearchLocal: "navigation",
|
||||
sidebarGlobalSearchLocal: "navigation",
|
||||
sidebarBrowseObjectsOnDatabaseActivationMigrationVersion: "navigation",
|
||||
rememberedConnectionDatabases: "navigation",
|
||||
sidebarShowConnectionNotes: "navigation",
|
||||
customColumnFormatters: "data",
|
||||
columnFormatters: "data",
|
||||
pluginShortcuts: "shortcuts",
|
||||
objectBrowserShowCheckbox: "data",
|
||||
objectBrowserViewMode: "data",
|
||||
};
|
||||
|
||||
function editorSettingCategory(id: string): BackupSettingsCategoryId {
|
||||
const transferCategory = transferCategoryForKey(id);
|
||||
if (transferCategory === "other") return "editor";
|
||||
return editorSettingCategoryOverrides[id] ?? transferCategory ?? "editor";
|
||||
}
|
||||
|
||||
function selectableDesktopSettings(catalog: SyncSnapshotCatalog): SyncCatalogItem[] {
|
||||
return catalog.desktopSettings.filter((item) => Object.prototype.hasOwnProperty.call(desktopSettingCategories, item.id));
|
||||
}
|
||||
|
||||
function selectableEditorSettings(catalog: SyncSnapshotCatalog): SyncCatalogItem[] {
|
||||
return catalog.editorSettings.filter((item) => !nonSyncableEditorSettingIds.has(item.id));
|
||||
}
|
||||
|
||||
function selectedSettings(savedIds: string[] | undefined, items: SyncCatalogItem[]): string[] {
|
||||
if (savedIds === undefined) return items.map((item) => item.id);
|
||||
const saved = new Set(savedIds);
|
||||
return items.filter((item) => saved.has(item.id)).map((item) => item.id);
|
||||
}
|
||||
|
||||
const backupSettingsCategories = computed(() => {
|
||||
const catalog = props.catalog;
|
||||
if (!catalog) return [];
|
||||
const groups = new Map<BackupSettingsCategoryId, { desktop: SyncCatalogItem[]; editor: SyncCatalogItem[] }>();
|
||||
for (const category of backupSettingsCategoryOrder) groups.set(category, { desktop: [], editor: [] });
|
||||
for (const item of selectableDesktopSettings(catalog)) groups.get(desktopSettingCategories[item.id])?.desktop.push(item);
|
||||
for (const item of selectableEditorSettings(catalog)) groups.get(editorSettingCategory(item.id))?.editor.push(item);
|
||||
return backupSettingsCategoryOrder.flatMap((category) => {
|
||||
const group = groups.get(category)!;
|
||||
const desktopSelected = group.desktop.filter((item) => selection.value.desktopSettings?.includes(item.id)).length;
|
||||
const editorSelected = group.editor.filter((item) => selection.value.editorSettings?.includes(item.id)).length;
|
||||
const total = group.desktop.length + group.editor.length;
|
||||
if (!total) return [];
|
||||
return [{ id: category, labelKey: backupSettingsCategoryLabelKeys[category], desktop: group.desktop, editor: group.editor, total, selected: desktopSelected + editorSelected }];
|
||||
});
|
||||
});
|
||||
|
||||
function emptySelection(): SyncSelection {
|
||||
return {
|
||||
connections: [],
|
||||
connectionSecrets: [],
|
||||
tunnelProfiles: [],
|
||||
tunnelSecrets: [],
|
||||
savedSqlFolders: [],
|
||||
savedSqlFiles: [],
|
||||
desktopSettings: [],
|
||||
editorSettings: [],
|
||||
aiConfigs: [],
|
||||
pluginUiStorage: [],
|
||||
sidebarLayout: false,
|
||||
pinnedTreeNodeIds: false,
|
||||
includeSecrets: false,
|
||||
syncCredentials: false,
|
||||
};
|
||||
}
|
||||
|
||||
function resetFromCatalog() {
|
||||
const catalog = props.catalog;
|
||||
if (!catalog) return;
|
||||
const saved = catalog.selection;
|
||||
const desktopSettings = selectableDesktopSettings(catalog);
|
||||
const editorSettings = selectableEditorSettings(catalog);
|
||||
selection.value = {
|
||||
...emptySelection(),
|
||||
connections: saved?.connections ?? catalog.connections.map((item) => item.id),
|
||||
connectionSecrets: saved?.connectionSecrets ?? (catalog.hasEncryptedSecrets ? catalog.connectionSecrets : []),
|
||||
tunnelProfiles: saved?.tunnelProfiles ?? catalog.tunnelProfiles.map((item) => item.id),
|
||||
tunnelSecrets: saved?.tunnelSecrets ?? (catalog.hasEncryptedSecrets ? catalog.tunnelSecrets : []),
|
||||
savedSqlFolders: saved?.savedSqlFolders ?? catalog.savedSqlFolders.map((item) => item.id),
|
||||
savedSqlFiles: saved?.savedSqlFiles ?? catalog.savedSqlFiles.map((item) => item.id),
|
||||
desktopSettings: selectedSettings(saved?.desktopSettings, desktopSettings),
|
||||
editorSettings: selectedSettings(saved?.editorSettings, editorSettings),
|
||||
aiConfigs: saved?.aiConfigs ?? (catalog.aiConfigsLocked ? undefined : catalog.aiConfigs.map((item) => item.id)),
|
||||
pluginUiStorage: saved?.pluginUiStorage ?? (catalog.pluginUiStorageLocked ? undefined : catalog.pluginUiStorage),
|
||||
sidebarLayout: saved?.sidebarLayout ?? catalog.hasSidebarLayout,
|
||||
pinnedTreeNodeIds: saved?.pinnedTreeNodeIds ?? catalog.hasPinnedTreeNodeIds,
|
||||
includeSecrets: saved?.includeSecrets ?? (isRestore.value ? catalog.hasEncryptedSecrets : !!props.defaultIncludeSecrets),
|
||||
syncCredentials: saved?.syncCredentials ?? (isRestore.value ? catalog.hasEncryptedSecrets : !!props.defaultIncludeSecrets),
|
||||
};
|
||||
if (selection.value.includeSecrets && !saved) onSecretsChanged();
|
||||
}
|
||||
|
||||
watch(
|
||||
() => [props.open, props.catalog] as const,
|
||||
([open]) => {
|
||||
if (open) resetFromCatalog();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
function ids(key: "connections" | "connectionSecrets" | "tunnelProfiles" | "tunnelSecrets" | "savedSqlFolders" | "savedSqlFiles" | "desktopSettings" | "editorSettings" | "aiConfigs") {
|
||||
return selection.value[key] ?? [];
|
||||
}
|
||||
|
||||
function toggleId(key: "connections" | "connectionSecrets" | "tunnelProfiles" | "tunnelSecrets" | "savedSqlFolders" | "savedSqlFiles" | "desktopSettings" | "editorSettings" | "aiConfigs", id: string) {
|
||||
const current = ids(key);
|
||||
selection.value[key] = current.includes(id) ? current.filter((item) => item !== id) : [...current, id];
|
||||
}
|
||||
|
||||
function toggleAll(key: "connections" | "tunnelProfiles" | "savedSqlFolders" | "savedSqlFiles" | "desktopSettings" | "editorSettings" | "aiConfigs", items: SyncCatalogItem[]) {
|
||||
const current = ids(key);
|
||||
selection.value[key] = current.length === items.length ? [] : items.map((item) => item.id);
|
||||
}
|
||||
|
||||
function toggleSettingsCategory(category: BackupSettingsCategoryId) {
|
||||
const catalog = props.catalog;
|
||||
const group = backupSettingsCategories.value.find((item) => item.id === category);
|
||||
if (!catalog || !group) return;
|
||||
const include = group.selected !== group.total;
|
||||
const desktopIds = new Set(selectedSettings(selection.value.desktopSettings, selectableDesktopSettings(catalog)));
|
||||
const editorIds = new Set(selectedSettings(selection.value.editorSettings, selectableEditorSettings(catalog)));
|
||||
for (const item of group.desktop) {
|
||||
if (include) desktopIds.add(item.id);
|
||||
else desktopIds.delete(item.id);
|
||||
}
|
||||
for (const item of group.editor) {
|
||||
if (include) editorIds.add(item.id);
|
||||
else editorIds.delete(item.id);
|
||||
}
|
||||
selection.value.desktopSettings = [...desktopIds];
|
||||
selection.value.editorSettings = [...editorIds];
|
||||
}
|
||||
|
||||
function togglePluginItem(pluginId: string, key: string) {
|
||||
const current = selection.value.pluginUiStorage ?? [];
|
||||
const exists = current.some((item) => item.pluginId === pluginId && item.key === key);
|
||||
selection.value.pluginUiStorage = exists ? current.filter((item) => item.pluginId !== pluginId || item.key !== key) : [...current, props.catalog?.pluginUiStorage.find((item) => item.pluginId === pluginId && item.key === key)!];
|
||||
}
|
||||
|
||||
function togglePluginAll() {
|
||||
if (props.catalog?.pluginUiStorageLocked) {
|
||||
selection.value.pluginUiStorage = selection.value.pluginUiStorage === undefined ? [] : undefined;
|
||||
return;
|
||||
}
|
||||
const all = props.catalog?.pluginUiStorage ?? [];
|
||||
selection.value.pluginUiStorage = selection.value.pluginUiStorage?.length === all.length ? [] : [...all];
|
||||
}
|
||||
|
||||
function toggleAllAiConfigs() {
|
||||
if (props.catalog?.aiConfigsLocked) {
|
||||
selection.value.aiConfigs = selection.value.aiConfigs === undefined ? [] : undefined;
|
||||
return;
|
||||
}
|
||||
toggleAll("aiConfigs", props.catalog?.aiConfigs ?? []);
|
||||
}
|
||||
|
||||
function onSecretsChanged() {
|
||||
if (!selection.value.includeSecrets || !props.catalog) return;
|
||||
if (!selection.value.connectionSecrets?.length) selection.value.connectionSecrets = [...props.catalog.connectionSecrets];
|
||||
if (!selection.value.tunnelSecrets?.length) selection.value.tunnelSecrets = [...props.catalog.tunnelSecrets];
|
||||
if (!selection.value.aiConfigs?.length && props.catalog.aiConfigs.length) selection.value.aiConfigs = props.catalog.aiConfigs.map((item) => item.id);
|
||||
if (!selection.value.pluginUiStorage?.length && !props.catalog.pluginUiStorageLocked) selection.value.pluginUiStorage = [...props.catalog.pluginUiStorage];
|
||||
selection.value.syncCredentials = true;
|
||||
}
|
||||
|
||||
function checked(key: "connections" | "connectionSecrets" | "tunnelProfiles" | "tunnelSecrets" | "savedSqlFolders" | "savedSqlFiles" | "desktopSettings" | "editorSettings" | "aiConfigs", id: string) {
|
||||
return ids(key).includes(id);
|
||||
}
|
||||
|
||||
function confirmSelection() {
|
||||
if (props.catalog) {
|
||||
selection.value.desktopSettings = selectedSettings(selection.value.desktopSettings, selectableDesktopSettings(props.catalog));
|
||||
selection.value.editorSettings = selectedSettings(selection.value.editorSettings, selectableEditorSettings(props.catalog));
|
||||
}
|
||||
emit("confirm", structuredClone(selection.value));
|
||||
emit("update:open", false);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog :open="open" @update:open="emit('update:open', $event)">
|
||||
<DialogContent class="flex max-h-[min(88vh,calc(var(--dbx-viewport-height)-4rem))] flex-col gap-0 overflow-hidden border border-border !bg-background-solid p-0 text-foreground shadow-2xl !backdrop-blur-none sm:max-w-[760px]">
|
||||
<DialogHeader class="shrink-0 border-b px-5 py-4">
|
||||
<DialogTitle>{{ isRestore ? t("settings.syncSelectionRestoreTitle") : t("settings.syncSelectionUploadTitle") }}</DialogTitle>
|
||||
<DialogDescription>
|
||||
{{ isRestore ? t("settings.syncSelectionRestoreNote") : t("settings.syncSelectionBackupNote") }}
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div v-if="catalog" class="min-h-0 flex-1 space-y-2 overflow-y-auto px-5 py-4">
|
||||
<details open class="border-b pb-2">
|
||||
<summary class="flex cursor-pointer list-none items-center gap-2 py-2 text-sm font-medium">
|
||||
<input :checked="selection.connections?.length === catalog.connections.length" type="checkbox" class="size-4 accent-primary" @click.stop.prevent="toggleAll('connections', catalog.connections)" />
|
||||
<span>{{ t("settings.syncSelectionConnections") }}</span>
|
||||
<span class="ml-auto text-xs text-muted-foreground">{{ selection.connections?.length ?? 0 }}/{{ catalog.connections.length }}</span>
|
||||
</summary>
|
||||
<div class="ml-6 space-y-1 pb-2">
|
||||
<div v-for="item in catalog.connections" :key="item.id" class="py-1">
|
||||
<label class="flex min-h-7 items-center gap-2 text-sm">
|
||||
<input :checked="checked('connections', item.id)" type="checkbox" class="size-4 accent-primary" @change="toggleId('connections', item.id)" />
|
||||
<span class="min-w-0 truncate">{{ item.label || item.id }}</span>
|
||||
</label>
|
||||
<label v-if="catalog.connectionSecrets.includes(item.id)" class="ml-6 flex min-h-7 items-center gap-2 text-xs text-muted-foreground">
|
||||
<input :checked="checked('connectionSecrets', item.id)" :disabled="!selection.includeSecrets || !selection.connections?.includes(item.id)" type="checkbox" class="size-3.5 accent-primary" @change="toggleId('connectionSecrets', item.id)" />
|
||||
<span>{{ t("settings.syncSelectionConnectionSecrets") }}</span>
|
||||
</label>
|
||||
</div>
|
||||
<p v-if="!catalog.connections.length" class="py-1 text-xs text-muted-foreground">{{ t("settings.syncSelectionNoConnections") }}</p>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<details open class="border-b pb-2">
|
||||
<summary class="flex cursor-pointer list-none items-center gap-2 py-2 text-sm font-medium">
|
||||
<input :checked="selection.tunnelProfiles?.length === catalog.tunnelProfiles.length" type="checkbox" class="size-4 accent-primary" @click.stop.prevent="toggleAll('tunnelProfiles', catalog.tunnelProfiles)" />
|
||||
<span>{{ t("settings.syncSelectionTunnels") }}</span>
|
||||
<span class="ml-auto text-xs text-muted-foreground">{{ selection.tunnelProfiles?.length ?? 0 }}/{{ catalog.tunnelProfiles.length }}</span>
|
||||
</summary>
|
||||
<div class="ml-6 space-y-1 pb-2">
|
||||
<div v-for="item in catalog.tunnelProfiles" :key="item.id" class="py-1">
|
||||
<label class="flex min-h-7 items-center gap-2 text-sm">
|
||||
<input :checked="checked('tunnelProfiles', item.id)" type="checkbox" class="size-4 accent-primary" @change="toggleId('tunnelProfiles', item.id)" />
|
||||
<span class="min-w-0 truncate">{{ item.label || item.id }}</span>
|
||||
</label>
|
||||
<label v-if="catalog.tunnelSecrets.includes(item.id)" class="ml-6 flex min-h-7 items-center gap-2 text-xs text-muted-foreground">
|
||||
<input :checked="checked('tunnelSecrets', item.id)" :disabled="!selection.includeSecrets || !selection.tunnelProfiles?.includes(item.id)" type="checkbox" class="size-3.5 accent-primary" @change="toggleId('tunnelSecrets', item.id)" />
|
||||
<span>{{ t("settings.syncSelectionTunnelSecrets") }}</span>
|
||||
</label>
|
||||
</div>
|
||||
<p v-if="!catalog.tunnelProfiles.length" class="py-1 text-xs text-muted-foreground">{{ t("settings.syncSelectionNoTunnels") }}</p>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<details open class="border-b pb-2">
|
||||
<summary class="flex cursor-pointer list-none items-center gap-2 py-2 text-sm font-medium">{{ t("settings.syncSelectionSavedSql") }}</summary>
|
||||
<div class="ml-6 space-y-2 pb-2">
|
||||
<div>
|
||||
<button type="button" class="mb-1 text-xs font-medium text-muted-foreground hover:text-foreground" @click="toggleAll('savedSqlFolders', catalog.savedSqlFolders)">
|
||||
{{ t("settings.syncSelectionFolders") }} ({{ selection.savedSqlFolders?.length ?? 0 }}/{{ catalog.savedSqlFolders.length }})
|
||||
</button>
|
||||
<label v-for="item in catalog.savedSqlFolders" :key="item.id" class="flex min-h-7 items-center gap-2 pl-1 text-sm">
|
||||
<input :checked="checked('savedSqlFolders', item.id)" type="checkbox" class="size-4 accent-primary" @change="toggleId('savedSqlFolders', item.id)" />
|
||||
<span class="min-w-0 truncate">{{ item.label || item.id }}</span>
|
||||
</label>
|
||||
</div>
|
||||
<div>
|
||||
<button type="button" class="mb-1 text-xs font-medium text-muted-foreground hover:text-foreground" @click="toggleAll('savedSqlFiles', catalog.savedSqlFiles)">{{ t("settings.syncSelectionFiles") }} ({{ selection.savedSqlFiles?.length ?? 0 }}/{{ catalog.savedSqlFiles.length }})</button>
|
||||
<label v-for="item in catalog.savedSqlFiles" :key="item.id" class="flex min-h-7 items-center gap-2 pl-1 text-sm">
|
||||
<input :checked="checked('savedSqlFiles', item.id)" type="checkbox" class="size-4 accent-primary" @change="toggleId('savedSqlFiles', item.id)" />
|
||||
<span class="min-w-0 truncate">{{ item.label || item.id }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<details open class="border-b pb-2">
|
||||
<summary class="flex cursor-pointer list-none items-center gap-2 py-2 text-sm font-medium">{{ t("settings.syncSelectionPersonalSettings") }}</summary>
|
||||
<div class="ml-6 space-y-1 py-2">
|
||||
<label v-for="category in backupSettingsCategories" :key="category.id" class="flex min-h-7 items-center gap-2 text-sm">
|
||||
<input :checked="category.total > 0 && category.selected === category.total" type="checkbox" class="size-4 accent-primary" @change="toggleSettingsCategory(category.id)" />
|
||||
<span>{{ t(category.labelKey) }}</span>
|
||||
<span class="ml-auto text-xs text-muted-foreground">{{ category.selected }}/{{ category.total }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<details open class="border-b pb-2">
|
||||
<summary class="flex cursor-pointer list-none items-center gap-2 py-2 text-sm font-medium">
|
||||
<input v-model="selection.includeSecrets" type="checkbox" class="size-4 accent-primary" @click.stop @change="onSecretsChanged" />
|
||||
<span>{{ t("settings.syncSelectionEncrypted") }}</span>
|
||||
</summary>
|
||||
<div class="ml-6 space-y-2 pb-2">
|
||||
<label class="flex min-h-7 items-center gap-2 text-sm">
|
||||
<input v-model="selection.syncCredentials" :disabled="!selection.includeSecrets" type="checkbox" class="size-4 accent-primary" />
|
||||
<span>{{ t("settings.syncSelectionSyncCredentials") }}</span>
|
||||
</label>
|
||||
<div>
|
||||
<label v-if="catalog.aiConfigsLocked" class="flex min-h-7 items-center gap-2 text-sm">
|
||||
<input :checked="selection.aiConfigs === undefined" :disabled="!selection.includeSecrets" type="checkbox" class="size-4 accent-primary" @change="toggleAllAiConfigs" />
|
||||
<span>{{ t("settings.syncSelectionAiLocked") }}</span>
|
||||
</label>
|
||||
<template v-else>
|
||||
<button type="button" class="mb-1 text-xs font-medium text-muted-foreground hover:text-foreground" :disabled="!selection.includeSecrets" @click="toggleAllAiConfigs">
|
||||
{{ t("settings.syncSelectionAiConfigs") }} ({{ selection.aiConfigs?.length ?? 0 }}/{{ catalog.aiConfigs.length }})
|
||||
</button>
|
||||
<label v-for="item in catalog.aiConfigs" :key="item.id" class="flex min-h-7 items-center gap-2 text-sm">
|
||||
<input :checked="checked('aiConfigs', item.id)" :disabled="!selection.includeSecrets" type="checkbox" class="size-4 accent-primary" @change="toggleId('aiConfigs', item.id)" />
|
||||
<span class="min-w-0 truncate">{{ item.label || item.id }}</span>
|
||||
</label>
|
||||
</template>
|
||||
</div>
|
||||
<div>
|
||||
<label v-if="catalog.pluginUiStorageLocked" class="flex min-h-7 items-center gap-2 text-sm">
|
||||
<input :checked="selection.pluginUiStorage === undefined" :disabled="!selection.includeSecrets" type="checkbox" class="size-4 accent-primary" @change="togglePluginAll" />
|
||||
<span>{{ t("settings.syncSelectionPluginLocked") }}</span>
|
||||
</label>
|
||||
<template v-else>
|
||||
<button type="button" class="mb-1 text-xs font-medium text-muted-foreground hover:text-foreground" :disabled="!selection.includeSecrets" @click="togglePluginAll">
|
||||
{{ t("settings.syncSelectionPluginData") }} ({{ selection.pluginUiStorage?.length ?? 0 }}/{{ catalog.pluginUiStorage.length }})
|
||||
</button>
|
||||
<label v-for="item in catalog.pluginUiStorage" :key="item.pluginId + '/' + item.key" class="flex min-h-7 items-center gap-2 text-sm">
|
||||
<input :checked="selection.pluginUiStorage?.some((entry) => entry.pluginId === item.pluginId && entry.key === item.key)" :disabled="!selection.includeSecrets" type="checkbox" class="size-4 accent-primary" @change="togglePluginItem(item.pluginId, item.key)" />
|
||||
<span class="min-w-0 truncate">{{ item.pluginName || item.pluginId }} / {{ item.key }}</span>
|
||||
</label>
|
||||
<p v-if="!catalog.pluginUiStorage.length" class="text-xs text-muted-foreground">{{ t("settings.syncSelectionNoPluginData") }}</p>
|
||||
</template>
|
||||
</div>
|
||||
<p v-if="!catalog.hasEncryptedSecrets && isRestore" class="text-xs text-muted-foreground">{{ t("settings.syncSelectionNoEncrypted") }}</p>
|
||||
</div>
|
||||
</details>
|
||||
|
||||
<details open class="pb-1">
|
||||
<summary class="flex cursor-pointer list-none items-center gap-2 py-2 text-sm font-medium">{{ t("settings.syncSelectionWorkspace") }}</summary>
|
||||
<div class="ml-6 space-y-1 pb-2">
|
||||
<label class="flex min-h-7 items-center gap-2 text-sm">
|
||||
<input v-model="selection.sidebarLayout" :disabled="!catalog.hasSidebarLayout" type="checkbox" class="size-4 accent-primary" />
|
||||
<span>{{ t("settings.syncSelectionSidebar") }}</span>
|
||||
</label>
|
||||
<label class="flex min-h-7 items-center gap-2 text-sm">
|
||||
<input v-model="selection.pinnedTreeNodeIds" :disabled="!catalog.hasPinnedTreeNodeIds" type="checkbox" class="size-4 accent-primary" />
|
||||
<span>{{ t("settings.syncSelectionPinned") }}</span>
|
||||
</label>
|
||||
</div>
|
||||
</details>
|
||||
</div>
|
||||
|
||||
<DialogFooter class="mx-0 mb-0 shrink-0 border-t px-5 pb-4 pt-3">
|
||||
<Button variant="outline" @click="emit('update:open', false)">{{ t("settings.syncSelectionCancel") }}</Button>
|
||||
<Button :disabled="!catalog" @click="confirmSelection">{{ isRestore ? t("settings.syncSelectionRestoreAction") : t("settings.syncSelectionUploadAction") }}</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
@@ -124,6 +124,7 @@ import ThemeCustomizerDialog from "./ThemeCustomizerDialog.vue";
|
||||
import DataGridTypeColorSchemeDialog from "@/components/grid/DataGridTypeColorSchemeDialog.vue";
|
||||
import { DATA_GRID_TYPE_COLOR_SCHEME_AUTO_ID, cloneDataGridTypeColorSchemes, type DataGridTypeColorScheme } from "@/lib/dataGrid/dataGridTypeColorScheme";
|
||||
import TunnelProfileManager from "@/components/connection/TunnelProfileManager.vue";
|
||||
import CloudSyncSelectionDialog from "@/components/editor/CloudSyncSelectionDialog.vue";
|
||||
import DangerConfirmDialog from "./DangerConfirmDialog.vue";
|
||||
import { isTauriRuntime } from "@/lib/backend/tauriRuntime";
|
||||
import { useTheme } from "@/composables/useTheme";
|
||||
@@ -149,6 +150,7 @@ import {
|
||||
forgetWebdavSavedPassword,
|
||||
getAppSupportInfo,
|
||||
checkBackgroundImage,
|
||||
cloudSyncLocalCatalog,
|
||||
clearBackgroundImage,
|
||||
saveBackgroundImage,
|
||||
loadMaxAgentTurns,
|
||||
@@ -163,12 +165,14 @@ import {
|
||||
saveSnippetSyncId,
|
||||
retrySnippetLegacyCleanup,
|
||||
snippetSyncDownload,
|
||||
snippetSyncInspect,
|
||||
snippetSyncSettings,
|
||||
snippetSyncTest,
|
||||
snippetSyncUpload,
|
||||
snippetTokenStatus,
|
||||
webdavPasswordStatus,
|
||||
webdavSyncDownload,
|
||||
webdavSyncInspect,
|
||||
webdavSyncSecretsStatus,
|
||||
webdavSyncTest,
|
||||
webdavSyncUpload,
|
||||
@@ -181,6 +185,8 @@ import {
|
||||
type McpServerStatus,
|
||||
type SnippetProvider,
|
||||
type SnippetSyncConfig,
|
||||
type SyncSelection,
|
||||
type SyncSnapshotCatalog,
|
||||
type WebDavConfig,
|
||||
} from "@/lib/backend/api";
|
||||
import { eventToModifierOnlyShortcut, eventToShortcut } from "@/lib/editor/keyboardShortcuts";
|
||||
@@ -295,7 +301,7 @@ import {
|
||||
type ToolbarVisibilityItem,
|
||||
} from "@/lib/settings/settingsSearch";
|
||||
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, writeWebDavBackupSelection } from "@/lib/webdav/webdavAutoUploadConfig";
|
||||
import { apiUrl, webPath } from "@/lib/common/webPath";
|
||||
import { DEFAULT_DATA_GRID_FONT_FAMILY, DEFAULT_UI_FONT_FAMILY, normalizeCustomFontFamilyInput, readableFontFamily, SYSTEM_UI_FONT_FAMILY } from "@/lib/app/appFonts";
|
||||
import { buildFontFamilyOptions, displayFontFamily, isPresetFontFamily, loadSystemFontNames } from "@/lib/app/fontFamilyOptions";
|
||||
@@ -4215,6 +4221,9 @@ const webdavBusy = ref<"" | "test" | "upload" | "download">("");
|
||||
const webdavMessage = ref("");
|
||||
const webdavError = ref(false);
|
||||
const syncMethodTab = ref<"webdav" | "snippet">("webdav");
|
||||
const syncSelectionOpen = ref(false);
|
||||
const syncSelectionMode = ref<"upload" | "restore">("upload");
|
||||
const syncSelectionCatalog = ref<SyncSnapshotCatalog | null>(null);
|
||||
|
||||
const snippetProvider = ref<SnippetProvider>((localStorage.getItem("dbx-snippet-provider") as SnippetProvider) || "github");
|
||||
const snippetInstanceUrl = ref(localStorage.getItem("dbx-gitlab-instance-url") || "https://gitlab.com");
|
||||
@@ -4236,13 +4245,13 @@ const legacySnippetId = ref("");
|
||||
const pendingLegacyCleanupId = ref("");
|
||||
const snippetSyncSettingsLoading = ref(true);
|
||||
|
||||
const webdavReady = computed(() => !!webdavEndpoint.value.trim() && !webdavBusy.value && (!webdavSyncSecrets.value || !!webdavSecretsPassphrase.value.trim() || webdavHasSavedSecretsPassphrase.value));
|
||||
const webdavReady = computed(() => !!webdavEndpoint.value.trim() && !webdavBusy.value);
|
||||
const snippetReady = computed(() => !snippetSyncSettingsLoading.value && !snippetBusy.value && (snippetProvider.value !== "gitlab" || (!snippetInstanceError.value && snippetInstanceUrl.value === activeSnippetInstanceUrl.value)) && (!!snippetToken.value.trim() || snippetHasSavedToken.value));
|
||||
const snippetUploadReady = computed(() => snippetReady.value && !!snippetPassphrase.value.trim() && (!snippetIncludeSecrets.value || !!snippetSecretsPassphrase.value.trim()));
|
||||
const snippetUploadReady = computed(() => snippetReady.value && !!snippetPassphrase.value.trim());
|
||||
// Legacy plaintext snippets have no outer encryption password. Let the
|
||||
// backend require one only after it detects an encrypted envelope so those
|
||||
// snapshots remain recoverable for migration.
|
||||
const snippetDownloadReady = computed(() => snippetReady.value && (!snippetRestoreSecrets.value || !!snippetSecretsPassphrase.value.trim()));
|
||||
const snippetDownloadReady = computed(() => snippetReady.value);
|
||||
|
||||
function currentSnippetConfig(replaceLegacySnippet = false): SnippetSyncConfig {
|
||||
return {
|
||||
@@ -4373,13 +4382,10 @@ async function uploadSnippetSnapshot() {
|
||||
return;
|
||||
}
|
||||
await runSnippetAction("upload", async () => {
|
||||
const summary = await snippetSyncUpload(currentSnippetConfig(), settingsStore.editorSettings, snippetPassphrase.value, snippetIncludeSecrets.value, snippetIncludeSecrets.value ? snippetSecretsPassphrase.value : undefined);
|
||||
snippetId.value = summary.snippetId;
|
||||
await persistSnippetSyncId();
|
||||
return t("settings.syncSnippetUploadSuccess", {
|
||||
bytes: summary.bytes,
|
||||
id: summary.snippetId,
|
||||
});
|
||||
syncSelectionCatalog.value = await cloudSyncLocalCatalog(settingsStore.editorSettings);
|
||||
syncSelectionMode.value = "upload";
|
||||
syncSelectionOpen.value = true;
|
||||
return "";
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4420,24 +4426,12 @@ async function retryLegacySnippetCleanup() {
|
||||
}
|
||||
|
||||
async function downloadSnippetSnapshot() {
|
||||
if (!snippetId.value.trim() || !window.confirm(t("settings.syncDownloadConfirm"))) return;
|
||||
if (!snippetId.value.trim()) return;
|
||||
await runSnippetAction("download", async () => {
|
||||
const result = await snippetSyncDownload(currentSnippetConfig(), snippetPassphrase.value, snippetRestoreSecrets.value, snippetRestoreSecrets.value ? snippetSecretsPassphrase.value : undefined);
|
||||
if (result.editorSettings && typeof result.editorSettings === "object") settingsStore.updateEditorSettings(result.editorSettings as any);
|
||||
await settingsStore.updateDesktopSettings(result.desktopSettings);
|
||||
await connectionStore.initFromDisk();
|
||||
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();
|
||||
await settingsStore.reloadAiConfigs();
|
||||
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.secretsApplied) message += ` ${t("settings.syncSecretsApplied")}`;
|
||||
return message;
|
||||
syncSelectionCatalog.value = await snippetSyncInspect(currentSnippetConfig(), snippetPassphrase.value || undefined, snippetSecretsPassphrase.value || undefined);
|
||||
syncSelectionMode.value = "restore";
|
||||
syncSelectionOpen.value = true;
|
||||
return "";
|
||||
});
|
||||
}
|
||||
|
||||
@@ -4555,37 +4549,72 @@ async function testWebDav() {
|
||||
|
||||
async function uploadWebDavSnapshot() {
|
||||
await runWebDavAction("upload", async () => {
|
||||
const summary = await webdavSyncUpload(currentWebDavConfig(), settingsStore.editorSettings, webdavSyncSecrets.value ? webdavSecretsPassphrase.value : undefined, webdavSyncSecrets.value);
|
||||
return t("settings.syncUploadSuccess", {
|
||||
bytes: summary.bytes,
|
||||
path: summary.remotePath,
|
||||
});
|
||||
syncSelectionCatalog.value = await cloudSyncLocalCatalog(settingsStore.editorSettings);
|
||||
syncSelectionMode.value = "upload";
|
||||
syncSelectionOpen.value = true;
|
||||
return "";
|
||||
});
|
||||
}
|
||||
|
||||
async function downloadWebDavSnapshot() {
|
||||
if (!window.confirm(t("settings.syncDownloadConfirm"))) return;
|
||||
await runWebDavAction("download", async () => {
|
||||
const result = await webdavSyncDownload(currentWebDavConfig(), webdavSyncSecrets.value ? webdavSecretsPassphrase.value : undefined, webdavSyncSecrets.value);
|
||||
if (result.editorSettings && typeof result.editorSettings === "object") {
|
||||
settingsStore.updateEditorSettings(result.editorSettings as any);
|
||||
syncSelectionCatalog.value = await webdavSyncInspect(currentWebDavConfig(), webdavSecretsPassphrase.value || undefined);
|
||||
syncSelectionMode.value = "restore";
|
||||
syncSelectionOpen.value = true;
|
||||
return "";
|
||||
});
|
||||
}
|
||||
|
||||
async function confirmSyncSelection(selection: SyncSelection) {
|
||||
if (syncMethodTab.value === "snippet") {
|
||||
if (syncSelectionMode.value === "upload") {
|
||||
snippetIncludeSecrets.value = selection.includeSecrets;
|
||||
await runSnippetAction("upload", async () => {
|
||||
const summary = await snippetSyncUpload(currentSnippetConfig(), settingsStore.editorSettings, snippetPassphrase.value, selection.includeSecrets, selection.includeSecrets ? snippetSecretsPassphrase.value : undefined, selection);
|
||||
snippetId.value = summary.snippetId;
|
||||
await persistSnippetSyncId();
|
||||
return t("settings.syncSnippetUploadSuccess", { bytes: summary.bytes, id: summary.snippetId });
|
||||
});
|
||||
return;
|
||||
}
|
||||
snippetRestoreSecrets.value = selection.includeSecrets;
|
||||
await runSnippetAction("download", async () => {
|
||||
const result = await snippetSyncDownload(currentSnippetConfig(), snippetPassphrase.value, selection.includeSecrets, selection.includeSecrets ? snippetSecretsPassphrase.value : undefined, 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();
|
||||
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.secretsApplied) message += ` ${t("settings.syncSecretsApplied")}`;
|
||||
return message;
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
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);
|
||||
writeWebDavBackupSelection(selection);
|
||||
return t("settings.syncUploadSuccess", { bytes: summary.bytes, path: summary.remotePath });
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await runWebDavAction("download", async () => {
|
||||
const result = await webdavSyncDownload(currentWebDavConfig(), 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();
|
||||
// Keep the shared tunnel profile UI consistent with the downloaded snapshot.
|
||||
await tunnelProfileStore.refresh();
|
||||
await settingsStore.reloadAiConfigs();
|
||||
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")}`;
|
||||
}
|
||||
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")}`;
|
||||
return message;
|
||||
});
|
||||
}
|
||||
@@ -9277,6 +9306,7 @@ LIMIT 100;</pre
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<CloudSyncSelectionDialog v-model:open="syncSelectionOpen" :mode="syncSelectionMode" :catalog="syncSelectionCatalog" :default-include-secrets="syncMethodTab === 'snippet' ? snippetIncludeSecrets : webdavSyncSecrets" @confirm="confirmSyncSelection" />
|
||||
</section>
|
||||
|
||||
<!-- AI Settings Tab -->
|
||||
|
||||
Reference in new issue
Block a user