-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathwindow.ts
More file actions
52 lines (45 loc) · 1.34 KB
/
window.ts
File metadata and controls
52 lines (45 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import type { Menubar } from 'menubar';
import { WindowConfig } from '../config';
/**
* Attach window-level event listeners for keyboard input and DevTools.
*
* @param mb - The menubar instance whose window events are configured.
*/
export function configureWindowEvents(mb: Menubar): void {
if (!mb.window) {
return;
}
/**
* Listen for 'before-input-event' to detect Escape key presses and hide the window.
*/
mb.window.webContents.on('before-input-event', (event, input) => {
if (input.key === 'Escape') {
mb.hideWindow();
event.preventDefault();
}
});
/**
* When DevTools is opened, resize and center the window for better visibility and allow resizing.
*/
mb.window.webContents.on('devtools-opened', () => {
if (!mb.window) {
return;
}
mb.window.setSize(800, 600);
mb.window.center();
mb.window.resizable = true;
mb.window.setAlwaysOnTop(true);
});
/**
* When DevTools is closed, restore the window to its original size and position it centered on the tray icon.
*/
mb.window.webContents.on('devtools-closed', () => {
if (!mb.window) {
return;
}
const trayBounds = mb.tray.getBounds();
mb.window.setSize(WindowConfig.width!, WindowConfig.height!);
mb.positioner.move('trayCenter', trayBounds);
mb.window.resizable = false;
});
}