(absPath: string)
| 533 | // per-window so the renderer can read/write/move it without ever passing |
| 534 | // an arbitrary path back over IPC. |
| 535 | function openExternalFileWindow(absPath: string): void { |
| 536 | const resolved = path.resolve(absPath) |
| 537 | for (const [winId, file] of externalFileWindows) { |
| 538 | if (path.resolve(file) !== resolved) continue |
| 539 | const existing = BrowserWindow.fromId(winId) |
| 540 | if (existing && !existing.isDestroyed()) { |
| 541 | focusWindow(existing) |
| 542 | return |
| 543 | } |
| 544 | externalFileWindows.delete(winId) |
| 545 | } |
| 546 | |
| 547 | const mac = isMac() |
| 548 | const win = new BrowserWindow({ |
| 549 | width: DEFAULT_WINDOW_WIDTH, |
| 550 | height: DEFAULT_WINDOW_HEIGHT, |
| 551 | minWidth: MIN_WINDOW_WIDTH, |
| 552 | minHeight: MIN_WINDOW_HEIGHT, |
| 553 | show: false, |
| 554 | autoHideMenuBar: true, |
| 555 | titleBarStyle: mac ? 'hiddenInset' : 'hidden', |
| 556 | trafficLightPosition: { x: 16, y: 16 }, |
| 557 | ...(mac |
| 558 | ? { backgroundColor: MAC_WINDOW_BACKGROUND_COLOR } |
| 559 | : { backgroundColor: '#faf7f0', icon: windowIconPath() }), |
| 560 | webPreferences: { |
| 561 | preload: path.join(__dirname, '../preload/index.js'), |
| 562 | sandbox: false, |
| 563 | contextIsolation: true, |
| 564 | nodeIntegration: false |
| 565 | } |
| 566 | }) |
| 567 | |
| 568 | externalFileWindows.set(win.id, resolved) |
| 569 | win.on('closed', () => { |
| 570 | externalFileWindows.delete(win.id) |
| 571 | readyWindowIds.delete(win.id) |
| 572 | pendingWindowNoteOpens.delete(win.id) |
| 573 | windowVaults.clearWindow(win.id) |
| 574 | }) |
| 575 | win.webContents.on('did-start-loading', () => { |
| 576 | readyWindowIds.delete(win.id) |
| 577 | }) |
| 578 | win.on('ready-to-show', () => win.show()) |
| 579 | |
| 580 | installNavigationGuards(win) |
| 581 | installZoomControls(win) |
| 582 | applyZoomFactor(win, currentZoomFactor) |
| 583 | |
| 584 | const params = `?externalFile=${encodeURIComponent(resolved)}` |
| 585 | const devServerUrl = process.env['ELECTRON_RENDERER_URL'] |
| 586 | if (devServerUrl) { |
| 587 | void win.loadURL(`${devServerUrl}${params}`) |
| 588 | } else { |
| 589 | void win.loadFile(path.join(__dirname, '../renderer/index.html'), { |
| 590 | search: params.slice(1) |
| 591 | }) |
| 592 | } |
no test coverage detected