MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / closeLocalVaultForWindow

Function closeLocalVaultForWindow

apps/desktop/src/main/index.ts:1300–1344  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1298}
1299
1300async function closeLocalVaultForWindow(): Promise<VaultInfo | null> {
1301 const win = currentIpcWindow() ?? mainWindow
1302 if (win && !win.isDestroyed() && windowVaults.isRemoteWindow(win.id)) return null
1303 if ((!win || win.isDestroyed()) && currentWorkspaceMode === 'remote') return null
1304 const vault = win && !win.isDestroyed() ? windowVaults.vaultForWindow(win.id) : currentVault
1305 if (!vault) return null
1306
1307 const cfg = await loadConfig()
1308 const candidates = new Map<string, { root: string; name: string }>()
1309 const remainingLocalVaults = forgetLocalVault(cfg.localVaults, vault.root)
1310 for (const entry of remainingLocalVaults) {
1311 candidates.set(path.resolve(entry.root), entry)
1312 }
1313 for (const entry of windowVaults.localVaultsExcept(vault.root)) {
1314 const root = path.resolve(entry.root)
1315 if (!candidates.has(root)) candidates.set(root, entry)
1316 }
1317 const nextLocalVault = candidates.values().next().value ?? null
1318 const nextVault =
1319 nextLocalVault && win && !win.isDestroyed()
1320 ? await setVaultForWindow(win, nextLocalVault.root, { persist: false })
1321 : nextLocalVault
1322 ? await setVault(nextLocalVault.root)
1323 : null
1324
1325 if (!nextVault) {
1326 if (win && !win.isDestroyed()) {
1327 windowVaults.clearWindow(win.id)
1328 }
1329 if (currentVault && path.resolve(currentVault.root) === path.resolve(vault.root)) {
1330 currentVault = null
1331 }
1332 currentWorkspaceMode = 'local'
1333 }
1334
1335 await updateConfig((cfg) => ({
1336 ...cfg,
1337 workspaceMode: 'local',
1338 vaultRoot: nextVault ? nextVault.root : null,
1339 localVaults: forgetLocalVault(cfg.localVaults, vault.root),
1340 remoteWorkspaceProfileId: null
1341 }))
1342
1343 return nextVault
1344}
1345
1346async function listLocalVaults(): Promise<LocalVaultEntry[]> {
1347 const cfg = await loadConfig()

Callers 1

registerIpcFunction · 0.85

Calls 10

loadConfigFunction · 0.90
forgetLocalVaultFunction · 0.90
updateConfigFunction · 0.90
currentIpcWindowFunction · 0.85
setVaultForWindowFunction · 0.85
setVaultFunction · 0.85
isRemoteWindowMethod · 0.80
vaultForWindowMethod · 0.80
localVaultsExceptMethod · 0.80
clearWindowMethod · 0.80

Tested by

no test coverage detected