Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Added minimize, toggle-maximize and close functions exposed through window object #1574

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/src/components/mainWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 8 additions & 0 deletions app/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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;
Expand Down