21 lines
863 B
TypeScript
21 lines
863 B
TypeScript
import { ipcMain, type BrowserWindow } from 'electron';
|
|
|
|
export function registerWindowFullscreenHandlers(
|
|
requireWindow: (event: Electron.IpcMainInvokeEvent) => BrowserWindow,
|
|
): (window: BrowserWindow) => void {
|
|
ipcMain.handle('window:isFullScreen', (event) => requireWindow(event).isFullScreen());
|
|
|
|
const boundWindows = new WeakSet<BrowserWindow>();
|
|
return (window: BrowserWindow): void => {
|
|
if (window.isDestroyed() || window.webContents.isDestroyed() || boundWindows.has(window)) return;
|
|
boundWindows.add(window);
|
|
|
|
const notify = (fullscreen: boolean): void => {
|
|
if (window.isDestroyed() || window.webContents.isDestroyed()) return;
|
|
window.webContents.send('window:fullscreen-changed', fullscreen);
|
|
};
|
|
window.on('enter-full-screen', () => notify(true));
|
|
window.on('leave-full-screen', () => notify(false));
|
|
};
|
|
}
|