Add ability to remove vaults from the app list without deleting files on disk, and restore the bundled Getting Started demo vault when needed. Changes: - Rust: add hidden_defaults field to VaultList for tracking removed default vaults - useVaultSwitcher: add removeVault() and restoreGettingStarted() with auto-switch - useCommandRegistry: add 'Remove Vault from List' and 'Restore Getting Started Vault' commands - StatusBar: add X button per vault item in vault menu dropdown - 25 new tests covering removal, restore, edge cases, and command palette Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
import { invoke } from '@tauri-apps/api/core'
|
|
import { isTauri, mockInvoke } from '../mock-tauri'
|
|
import type { VaultOption } from '../components/StatusBar'
|
|
|
|
export interface PersistedVaultList {
|
|
vaults: Array<{ label: string; path: string }>
|
|
active_vault: string | null
|
|
hidden_defaults: string[]
|
|
}
|
|
|
|
function tauriCall<T>(command: string, args: Record<string, unknown>): Promise<T> {
|
|
return isTauri() ? invoke<T>(command, args) : mockInvoke<T>(command, args)
|
|
}
|
|
|
|
async function checkAvailability(v: { label: string; path: string }): Promise<VaultOption> {
|
|
try {
|
|
const exists = await tauriCall<boolean>('check_vault_exists', { path: v.path })
|
|
return { label: v.label, path: v.path, available: exists }
|
|
} catch {
|
|
return { label: v.label, path: v.path, available: false }
|
|
}
|
|
}
|
|
|
|
export async function loadVaultList(): Promise<{ vaults: VaultOption[]; activeVault: string | null; hiddenDefaults: string[] }> {
|
|
const data = await tauriCall<PersistedVaultList>('load_vault_list', {})
|
|
const persisted = data?.vaults ?? []
|
|
const checked = await Promise.all(persisted.map(checkAvailability))
|
|
return { vaults: checked, activeVault: data?.active_vault ?? null, hiddenDefaults: data?.hidden_defaults ?? [] }
|
|
}
|
|
|
|
export function saveVaultList(vaults: VaultOption[], activeVault: string, hiddenDefaults: string[] = []): Promise<void> {
|
|
const list: PersistedVaultList = {
|
|
vaults: vaults.map(v => ({ label: v.label, path: v.path })),
|
|
active_vault: activeVault,
|
|
hidden_defaults: hiddenDefaults,
|
|
}
|
|
return tauriCall('save_vault_list', { list })
|
|
}
|