(absPath: string, reuseMainWindow: boolean)
| 466 | } |
| 467 | |
| 468 | async 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. |
no test coverage detected