(relPath: string)
| 2856 | */ |
| 2857 | const floatingNoteWindows = new Map<string, BrowserWindow>() |
| 2858 | function openFloatingNoteWindow(relPath: string): void { |
| 2859 | const floatingWindowStartedAt = performance.now() |
| 2860 | const sourceWindow = currentIpcWindow() ?? mainWindow |
| 2861 | const sourceVault = |
| 2862 | sourceWindow && !sourceWindow.isDestroyed() ? windowVaults.vaultForWindow(sourceWindow.id) : currentVault |
| 2863 | const floatingKey = `${sourceVault?.root ?? 'no-vault'}:${relPath}` |
| 2864 | const existing = floatingNoteWindows.get(floatingKey) |
| 2865 | if (existing && !existing.isDestroyed()) { |
| 2866 | if (existing.isMinimized()) existing.restore() |
| 2867 | existing.focus() |
| 2868 | return |
| 2869 | } |
| 2870 | const mac = isMac() |
| 2871 | const win = new BrowserWindow({ |
| 2872 | width: 720, |
| 2873 | height: 720, |
| 2874 | minWidth: 360, |
| 2875 | minHeight: 320, |
| 2876 | show: false, |
| 2877 | autoHideMenuBar: true, |
| 2878 | titleBarStyle: mac ? 'hiddenInset' : 'hidden', |
| 2879 | trafficLightPosition: { x: 12, y: 12 }, |
| 2880 | ...(mac |
| 2881 | ? { |
| 2882 | backgroundColor: MAC_WINDOW_BACKGROUND_COLOR |
| 2883 | } |
| 2884 | : { |
| 2885 | backgroundColor: '#faf7f0', |
| 2886 | icon: windowIconPath() |
| 2887 | }), |
| 2888 | webPreferences: { |
| 2889 | preload: path.join(__dirname, '../preload/index.js'), |
| 2890 | // Keep the renderer isolated and node-free, but the current preload |
| 2891 | // still relies on Node/Electron APIs that are not available inside a |
| 2892 | // fully sandboxed preload context. |
| 2893 | sandbox: false, |
| 2894 | contextIsolation: true, |
| 2895 | nodeIntegration: false |
| 2896 | } |
| 2897 | }) |
| 2898 | |
| 2899 | floatingNoteWindows.set(floatingKey, win) |
| 2900 | win.on('closed', () => { |
| 2901 | floatingNoteWindows.delete(floatingKey) |
| 2902 | windowVaults.clearWindow(win.id) |
| 2903 | }) |
| 2904 | win.on('ready-to-show', () => { |
| 2905 | recordMainPerf('main.floating-window.ready-to-show', performance.now() - floatingWindowStartedAt, { |
| 2906 | path: relPath |
| 2907 | }) |
| 2908 | win.show() |
| 2909 | }) |
| 2910 | win.webContents.once('did-finish-load', () => { |
| 2911 | recordMainPerf( |
| 2912 | 'main.floating-window.did-finish-load', |
| 2913 | performance.now() - floatingWindowStartedAt, |
| 2914 | { path: relPath } |
| 2915 | ) |
no test coverage detected