diff --git a/src/main/windows/quickCaptureWindow.ts b/src/main/windows/quickCaptureWindow.ts new file mode 100644 index 0000000..624db35 --- /dev/null +++ b/src/main/windows/quickCaptureWindow.ts @@ -0,0 +1,40 @@ +import { BrowserWindow, screen } from 'electron'; +import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +let win: BrowserWindow | null = null; +const __dirname = fileURLToPath(new URL('.', import.meta.url)); + +export function getQuickCaptureWindow(): BrowserWindow | null { return win; } + +export function createQuickCaptureWindow(): BrowserWindow { + if (win && !win.isDestroyed()) return win; + const primary = screen.getPrimaryDisplay(); + const W = 640, H = 280; + const x = Math.round((primary.workArea.width - W) / 2 + primary.workArea.x); + const y = Math.round((primary.workArea.height - H) / 3 + primary.workArea.y); + + win = new BrowserWindow({ + width: W, height: H, x, y, + frame: false, show: false, alwaysOnTop: true, + skipTaskbar: true, resizable: false, + webPreferences: { + preload: join(__dirname, '../preload/index.js'), + contextIsolation: true, nodeIntegration: false, sandbox: false + } + }); + + if (process.env.ELECTRON_RENDERER_URL) { + win.loadURL(`${process.env.ELECTRON_RENDERER_URL}/quickcapture/index.html`); + } else { + win.loadFile(join(__dirname, '../renderer/quickcapture/index.html')); + } + + win.on('blur', () => { if (win?.isVisible()) win.hide(); }); + return win; +} + +export function showQuickCapture(): void { + const w = createQuickCaptureWindow(); + w.show(); w.focus(); +}