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

Function openMarkdownFileFromOS

apps/desktop/src/main/index.ts:468–507  ·  view source on GitHub ↗
(absPath: string, reuseMainWindow: boolean)

Source from the content-addressed store, hash-verified

466}
467
468async function openMarkdownFileFromOS(absPath: string, reuseMainWindow: boolean): Promise<boolean> {
469 let stat
470 try {
471 stat = await fsp.stat(absPath)
472 } catch {
473 return false
474 }
475 if (!stat.isFile() || !isMarkdownFilePath(absPath)) return false
476
477 const cfg = await loadConfig()
478 const knownRoots: string[] = []
479 for (const win of BrowserWindow.getAllWindows()) {
480 if (win.isDestroyed()) continue
481 const vault = windowVaults.vaultForWindow(win.id)
482 if (vault) knownRoots.push(vault.root)
483 }
484 for (const entry of cfg.localVaults ?? []) knownRoots.push(entry.root)
485 if (cfg.vaultRoot) knownRoots.push(cfg.vaultRoot)
486
487 const target = resolveMarkdownOpenTarget(absPath, knownRoots)
488
489 if (target.kind === 'vault') {
490 const existing = findWindowForVaultRoot(target.vaultRoot)
491 if (existing) {
492 focusWindow(existing)
493 queueNoteOpenForWindow(existing, target.relPath)
494 return true
495 }
496 const win = await createWindow({
497 initialVaultRoot: target.vaultRoot,
498 persistInitialVault: true
499 })
500 if (!reuseMainWindow) focusWindow(win)
501 queueNoteOpenForWindow(win, target.relPath)
502 return true
503 }
504
505 openExternalFileWindow(target.absPath)
506 return true
507}
508
509// Pick a local vault to move an external file into: any open local
510// vault, else the active local vault, else the last-used vault on disk.

Callers 2

flushPendingFileOpensFunction · 0.85
registerIpcFunction · 0.85

Calls 9

isMarkdownFilePathFunction · 0.90
loadConfigFunction · 0.90
findWindowForVaultRootFunction · 0.85
focusWindowFunction · 0.85
queueNoteOpenForWindowFunction · 0.85
createWindowFunction · 0.85
openExternalFileWindowFunction · 0.85
vaultForWindowMethod · 0.80

Tested by

no test coverage detected