(mb: Menubar)
| 8 | * @param mb - The menubar instance whose window events are configured. |
| 9 | */ |
| 10 | export function configureWindowEvents(mb: Menubar): void { |
| 11 | if (!mb.window) { |
| 12 | return; |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * Listen for 'before-input-event' to detect Escape key presses and hide the window. |
| 17 | */ |
| 18 | mb.window.webContents.on('before-input-event', (event, input) => { |
| 19 | if (input.key === 'Escape') { |
| 20 | mb.hideWindow(); |
| 21 | event.preventDefault(); |
| 22 | } |
| 23 | }); |
| 24 | |
| 25 | /** |
| 26 | * When DevTools is opened, resize and center the window for better visibility and allow resizing. |
| 27 | */ |
| 28 | mb.window.webContents.on('devtools-opened', () => { |
| 29 | if (!mb.window) { |
| 30 | return; |
| 31 | } |
| 32 | |
| 33 | mb.window.setSize(800, 600); |
| 34 | mb.window.center(); |
| 35 | mb.window.resizable = true; |
| 36 | mb.window.setAlwaysOnTop(true); |
| 37 | }); |
| 38 | |
| 39 | /** |
| 40 | * When DevTools is closed, restore the window to its original size and position it centered on the tray icon. |
| 41 | */ |
| 42 | mb.window.webContents.on('devtools-closed', () => { |
| 43 | if (!mb.window) { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | const trayBounds = mb.tray.getBounds(); |
| 48 | mb.window.setSize(WindowConfig.width!, WindowConfig.height!); |
| 49 | mb.positioner.move('trayCenter', trayBounds); |
| 50 | mb.window.resizable = false; |
| 51 | }); |
| 52 | } |
no outgoing calls
no test coverage detected