feat(desktop): 持久化最近 Vault 授权

This commit is contained in:
2026-09-07 17:55:42 +08:00
parent 4288f90558
commit a64c2cd057
10 changed files with 262 additions and 23 deletions
@@ -28,6 +28,13 @@ describe('原生 Workspace 适配', () => {
})
it('取消原生目录选择不进入空 Vault', async () => {
native.enabled = true; native.invoke.mockResolvedValue(null)
await expect(workspace.openVault('ignored')).rejects.toThrow()
await expect(workspace.openVault('')).rejects.toThrow()
expect(native.invoke).toHaveBeenCalledWith('workspace_choose', undefined)
})
it('最近 Vault 只能通过已授权路径命令重开', async () => {
native.enabled = true
native.invoke.mockResolvedValue({ vault_id: 'vault', path: 'C:\\notes', name: 'notes' })
await expect(workspace.openVault('C:\\notes')).resolves.toMatchObject({ vault_id: 'vault' })
expect(native.invoke).toHaveBeenCalledWith('workspace_open', { path: 'C:\\notes' })
})
})
+4 -1
View File
@@ -98,7 +98,10 @@ export async function getRecentVaults(): Promise<VaultInfo[]> {
export async function openVault(path: string): Promise<VaultInfo> {
if (isDesktop()) {
const vault = await hostInvoke<HostVault | null>('workspace_choose')
// 空路径只表示用户点击“选择目录”;最近列表只能重开 Host 已持久化授权的路径。
const vault = path
? await hostInvoke<HostVault>('workspace_open', { path })
: await hostInvoke<HostVault | null>('workspace_choose')
if (!vault) throw new Error(t('已取消选择', 'Selection cancelled'))
cachedTree = null; noteIdByPath.clear(); typeByPath.clear(); treeRequestVersion++
return vault