Added hooks for minimize, toggle-maximize and close, in the main process, and exposed same named emitted events through the window object. This makes it easy to integreate inline window control buttons, for when not having a window frame

This commit is contained in:
Rasmus Zweidorff Iversen 2023-09-13 12:11:49 +02:00
parent 45d7981761
commit 1618775096
2 changed files with 24 additions and 0 deletions

View File

@ -150,6 +150,22 @@ export async function createMainWindow(
mainWindow.show();
});
ipcMain.on('window-minimize', () => {
mainWindow.minimize();
});
ipcMain.on('window-toggle-maximize', () => {
if (mainWindow.isMaximized()) {
mainWindow.restore();
} else {
mainWindow.maximize();
}
});
ipcMain.on('window-close', () => {
mainWindow.close();
})
setupSessionInteraction(mainWindow);
setupSessionPermissionHandler(mainWindow);

View File

@ -62,6 +62,12 @@ function setNotificationCallback(
window.Notification = newNotify;
}
function exposeWindowControls() {
(<any>window).minimize = () => ipcRenderer.send('window-minimize');
(<any>window).toggleMaximize = () => ipcRenderer.send('window-toggle-maximize');
(<any>window).close = () => ipcRenderer.send('window-close');
}
async function getDisplayMedia(
sourceId: number | string,
): Promise<MediaStream> {
@ -327,6 +333,8 @@ function notifyNotificationClick(): void {
setNotificationCallback(notifyNotificationCreate, notifyNotificationClick);
setDisplayMediaPromise();
exposeWindowControls();
ipcRenderer.on('params', (event, message: string) => {
log.debug('ipcRenderer.params', { event, message });
const appArgs: unknown = JSON.parse(message) as OutputOptions;