mirror of
https://gitlab.com/ArkHost/HelixNotes.git
synced 2026-11-23 19:04:56 +01:00
WebDAV sync: make config per-vault so switching vaults no longer cross-contaminates remotes; migrate existing global config to the active vault
This commit is contained in:
1 parent
a43bf05bf0
commit
2469a971ca
2 files changed
+43
-17
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { showSettings, theme, appConfig, updateAvailable as globalUpdateAvailable, updateObj as globalUpdateObj, installType, settingsTab, vaultReady, androidApkUrl, checkForUpdateMobile, notebookSortMode, isManagedInstall, customThemes } from '$lib/stores/app';
|
import { showSettings, theme, appConfig, activeVaultConfig, updateAvailable as globalUpdateAvailable, updateObj as globalUpdateObj, installType, settingsTab, vaultReady, androidApkUrl, checkForUpdateMobile, notebookSortMode, isManagedInstall, customThemes } from '$lib/stores/app';
|
||||||
import { setTheme, setAccentColor, setFontSize, setFontFamily, setLineHeight, setUiScale, setContentWidth, setGeneralSettings, importObsidian, createBackup, listBackups, restoreBackup, deleteBackup, setBackupSettings, setAiSettings, testAiConnection, setSyncSettings, testSyncConnection, syncNow, saveCustomTheme, deleteCustomTheme, exportCustomTheme, importCustomThemes } from '$lib/api';
|
import { setTheme, setAccentColor, setFontSize, setFontFamily, setLineHeight, setUiScale, setContentWidth, setGeneralSettings, importObsidian, createBackup, listBackups, restoreBackup, deleteBackup, setBackupSettings, setAiSettings, testAiConnection, setSyncSettings, testSyncConnection, syncNow, saveCustomTheme, deleteCustomTheme, exportCustomTheme, importCustomThemes } from '$lib/api';
|
||||||
import { darkThemes, isMobile, isAndroid } from '$lib/platform';
|
import { darkThemes, isMobile, isAndroid } from '$lib/platform';
|
||||||
import { open as openDialog, save as saveDialog } from '@tauri-apps/plugin-dialog';
|
import { open as openDialog, save as saveDialog } from '@tauri-apps/plugin-dialog';
|
||||||
@@ -302,25 +302,45 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ── WebDAV sync ──
|
// ── WebDAV sync ──
|
||||||
let syncProvider = $state<string | null>($appConfig?.sync_provider ?? null);
|
let syncProvider = $state<string | null>(activeVaultConfig($appConfig)?.sync_provider ?? null);
|
||||||
let syncUrl = $state($appConfig?.webdav_url ?? '');
|
let syncUrl = $state(activeVaultConfig($appConfig)?.webdav_url ?? '');
|
||||||
let syncUsername = $state($appConfig?.webdav_username ?? '');
|
let syncUsername = $state(activeVaultConfig($appConfig)?.webdav_username ?? '');
|
||||||
let syncPassword = $state($appConfig?.webdav_password ?? '');
|
let syncPassword = $state(activeVaultConfig($appConfig)?.webdav_password ?? '');
|
||||||
let syncShowPassword = $state(false);
|
let syncShowPassword = $state(false);
|
||||||
let syncTestLoading = $state(false);
|
let syncTestLoading = $state(false);
|
||||||
let syncTestMessage = $state<{ type: 'success' | 'error'; text: string } | null>(null);
|
let syncTestMessage = $state<{ type: 'success' | 'error'; text: string } | null>(null);
|
||||||
let syncRunning = $state(false);
|
let syncRunning = $state(false);
|
||||||
let syncMessage = $state<{ type: 'success' | 'error'; text: string } | null>(null);
|
let syncMessage = $state<{ type: 'success' | 'error'; text: string } | null>(null);
|
||||||
let syncOnOpen = $state($appConfig?.sync_on_open ?? false);
|
let syncOnOpen = $state(activeVaultConfig($appConfig)?.sync_on_open ?? false);
|
||||||
let syncOnChange = $state($appConfig?.sync_on_change ?? false);
|
let syncOnChange = $state(activeVaultConfig($appConfig)?.sync_on_change ?? false);
|
||||||
let syncIntervalMinutes = $state($appConfig?.sync_interval_minutes ?? 0);
|
let syncIntervalMinutes = $state(activeVaultConfig($appConfig)?.sync_interval_minutes ?? 0);
|
||||||
|
|
||||||
|
// Re-seed the sync form when the active vault changes, so Settings reflects the current vault.
|
||||||
|
let lastSyncVault: string | null = null;
|
||||||
|
$effect(() => {
|
||||||
|
const path = $appConfig?.active_vault ?? null;
|
||||||
|
if (path === lastSyncVault) return;
|
||||||
|
lastSyncVault = path;
|
||||||
|
const vc = activeVaultConfig($appConfig);
|
||||||
|
syncProvider = vc?.sync_provider ?? null;
|
||||||
|
syncUrl = vc?.webdav_url ?? '';
|
||||||
|
syncUsername = vc?.webdav_username ?? '';
|
||||||
|
syncPassword = vc?.webdav_password ?? '';
|
||||||
|
syncOnOpen = vc?.sync_on_open ?? false;
|
||||||
|
syncOnChange = vc?.sync_on_change ?? false;
|
||||||
|
syncIntervalMinutes = vc?.sync_interval_minutes ?? 0;
|
||||||
|
});
|
||||||
|
|
||||||
async function saveSyncSettings() {
|
async function saveSyncSettings() {
|
||||||
await setSyncSettings(syncProvider, syncUrl || null, syncUsername || null, syncPassword || null, syncOnOpen, syncOnChange, syncIntervalMinutes);
|
await setSyncSettings(syncProvider, syncUrl || null, syncUsername || null, syncPassword || null, syncOnOpen, syncOnChange, syncIntervalMinutes);
|
||||||
// Reflect into the global store so the top-bar button visibility and the auto-sync
|
// Reflect into the active vault's config in the store so the top-bar button and auto-sync
|
||||||
// triggers update live, without needing an app restart.
|
// triggers update live, without an app restart.
|
||||||
if ($appConfig) $appConfig = {
|
if ($appConfig) {
|
||||||
...$appConfig,
|
const cur = $appConfig;
|
||||||
|
$appConfig = {
|
||||||
|
...cur,
|
||||||
|
vaults: cur.vaults.map((v) => v.path === cur.active_vault ? {
|
||||||
|
...v,
|
||||||
sync_provider: syncProvider,
|
sync_provider: syncProvider,
|
||||||
webdav_url: syncUrl || null,
|
webdav_url: syncUrl || null,
|
||||||
webdav_username: syncUsername || null,
|
webdav_username: syncUsername || null,
|
||||||
@@ -328,8 +348,10 @@
|
|||||||
sync_on_open: syncOnOpen,
|
sync_on_open: syncOnOpen,
|
||||||
sync_on_change: syncOnChange,
|
sync_on_change: syncOnChange,
|
||||||
sync_interval_minutes: syncIntervalMinutes,
|
sync_interval_minutes: syncIntervalMinutes,
|
||||||
|
} : v),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function handleTestSync() {
|
async function handleTestSync() {
|
||||||
syncTestLoading = true;
|
syncTestLoading = true;
|
||||||
@@ -367,7 +389,11 @@
|
|||||||
if (s.conflicts) parts.push(`${s.conflicts} conflict copies`);
|
if (s.conflicts) parts.push(`${s.conflicts} conflict copies`);
|
||||||
syncMessage = { type: 'success', text: parts.length ? `Synced: ${parts.join(', ')}.` : 'Already up to date.' };
|
syncMessage = { type: 'success', text: parts.length ? `Synced: ${parts.join(', ')}.` : 'Already up to date.' };
|
||||||
syncRunning = false;
|
syncRunning = false;
|
||||||
if ($appConfig && event.payload.last_sync_time) $appConfig = { ...$appConfig, last_sync_time: event.payload.last_sync_time };
|
if ($appConfig && event.payload.last_sync_time) {
|
||||||
|
const cur = $appConfig;
|
||||||
|
const ts = event.payload.last_sync_time;
|
||||||
|
$appConfig = { ...cur, vaults: cur.vaults.map((v) => v.path === cur.active_vault ? { ...v, last_sync_time: ts } : v) };
|
||||||
|
}
|
||||||
cleanup();
|
cleanup();
|
||||||
}));
|
}));
|
||||||
unlisteners.push(await listen<{ error?: string }>('sync-error', (event) => {
|
unlisteners.push(await listen<{ error?: string }>('sync-error', (event) => {
|
||||||
@@ -2088,8 +2114,8 @@
|
|||||||
<span>{syncMessage.text}</span>
|
<span>{syncMessage.text}</span>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{#if $appConfig?.last_sync_time}
|
{#if activeVaultConfig($appConfig)?.last_sync_time}
|
||||||
<p class="setting-hint">Last sync: {new Date($appConfig.last_sync_time).toLocaleString()}</p>
|
<p class="setting-hint">Last sync: {new Date(activeVaultConfig($appConfig)!.last_sync_time!).toLocaleString()}</p>
|
||||||
{/if}
|
{/if}
|
||||||
<p class="setting-hint">If a note is edited on two devices, both are kept (one as a "(conflict)" copy).</p>
|
<p class="setting-hint">If a note is edited on two devices, both are kept (one as a "(conflict)" copy).</p>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getCurrentWindow } from '@tauri-apps/api/window';
|
import { getCurrentWindow } from '@tauri-apps/api/window';
|
||||||
import { vaultReady, focusMode, readOnly, updateAvailable, showSettings, settingsTab, appConfig, syncState } from '$lib/stores/app';
|
import { vaultReady, focusMode, readOnly, updateAvailable, showSettings, settingsTab, appConfig, activeVaultConfig, syncState } from '$lib/stores/app';
|
||||||
import { syncNow } from '$lib/api';
|
import { syncNow } from '$lib/api';
|
||||||
|
|
||||||
let { onNewNote = () => {}, onDailyNote = () => {} }: {
|
let { onNewNote = () => {}, onDailyNote = () => {} }: {
|
||||||
@@ -112,7 +112,7 @@
|
|||||||
<line x1="3" y1="10" x2="21" y2="10" />
|
<line x1="3" y1="10" x2="21" y2="10" />
|
||||||
</svg>
|
</svg>
|
||||||
</button>
|
</button>
|
||||||
{#if $appConfig?.sync_provider === 'webdav'}
|
{#if activeVaultConfig($appConfig)?.sync_provider === 'webdav'}
|
||||||
<button class="switch-vault-btn" class:active={$syncState.running} onclick={() => { if (!$syncState.running) syncNow().catch(() => {}); }} disabled={$syncState.running} title={$syncState.error ? `Sync error: ${$syncState.error}` : ($syncState.running ? 'Syncing vault...' : 'Sync vault now')}>
|
<button class="switch-vault-btn" class:active={$syncState.running} onclick={() => { if (!$syncState.running) syncNow().catch(() => {}); }} disabled={$syncState.running} title={$syncState.error ? `Sync error: ${$syncState.error}` : ($syncState.running ? 'Syncing vault...' : 'Sync vault now')}>
|
||||||
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:sync-spin={$syncState.running}>
|
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class:sync-spin={$syncState.running}>
|
||||||
<path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0115-6.7L21 8"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 01-15 6.7L3 16"/>
|
<path d="M21 2v6h-6"/><path d="M3 12a9 9 0 0115-6.7L21 8"/><path d="M3 22v-6h6"/><path d="M21 12a9 9 0 01-15 6.7L3 16"/>
|
||||||
|
|||||||
Reference in new issue
Block a user