feat: gestion desktop des vaults & dossiers — retrait par menu contextuel et ajout en configuration #159
CI / lint (push) Successful in 3m2s
CI / security (push) Successful in 2m2s
CI / test (push) Successful in 4m42s
CI / build (push) Successful in 1m52s
CI / e2e (push) Successful in 15m54s

This commit is contained in:
2026-10-02 21:04:17 -04:00
parent bab272bb5c
commit d2734dc8ce
22 changed files with 331 additions and 18 deletions
+52 -2
View File
@@ -163,14 +163,64 @@ export async function pickAndAddVault() {
if (!path) return undefined;
// Derive a display name from the final path segment.
const segments = path.replace(/[\\/]+$/, '').split(/[\\/]/);
const name = segments[segments.length - 1] || 'Vault';
const name = lastPathSegment(path) || 'Vault';
await invoke('add_vault', { name: name, path: path });
await invoke('restart_backend');
return path;
}
// ── Vault & root-directory management (#159) ────────────────────────────
// The Tauri shell injects vaults (VAULT_N_*) and root directories (DIR_N_*)
// into the backend as environment variables. These helpers unregister them
// from the desktop config, restart the backend and reload the page.
// Pure: classify a root name against the desktop config lists.
// Returns 'vault' | 'dir' | null.
export function resolveRootKind(vaults, dirs, name) {
if ((vaults || []).some((v) => v.name === name)) return 'vault';
if ((dirs || []).some((d) => d.name === name)) return 'dir';
return null;
}
// Pure: last path segment, Windows or POSIX separators, trailing
// separators ignored ('' for root-ish inputs).
export function lastPathSegment(path) {
const segments = String(path).replace(/[\\/]+$/, '').split(/[\\/]/);
return segments[segments.length - 1] || '';
}
// Remove a vault or a root directory from the desktop config. `confirmMsg`
// (already translated) gates the destructive step; nothing on disk is
// deleted. Returns 'vault' | 'dir', or undefined when not on desktop,
// cancelled, unknown root, or a command failed.
export async function removeRoot(name, confirmMsg) {
if (!isTauriEnv() || !name) return undefined;
if (confirmMsg && !window.confirm(confirmMsg)) return undefined;
const vaults = (await invoke('list_vaults')) || [];
const dirs = (await invoke('list_dirs')) || [];
const kind = resolveRootKind(vaults, dirs, name);
if (!kind) return undefined;
const res = await invoke(kind === 'vault' ? 'remove_vault' : 'remove_dir', { name: name });
if (res === undefined) return undefined; // command failed (see invoke wrapper)
await invoke('restart_backend');
window.location.reload();
return kind;
}
// Add a root directory: side-effect-free native folder picker, register it,
// restart the backend and reload. Mirrors pickAndAddVault.
export async function pickAndAddDir() {
if (!isTauriEnv()) return undefined;
const path = await invoke('pick_folder');
if (typeof path !== 'string' || !path) return undefined;
const name = lastPathSegment(path) || 'Dossier';
await invoke('add_dir', { name: name, path: path });
await invoke('restart_backend');
window.location.reload();
return path;
}
// ── First-run wizard (DOM) ─────────────────────────────────────────────────
// Shows a dismissible welcome banner on first desktop launch offering to pick
// the user's Obsidian vault folder. Non-blocking; the default vault created