Files
makelore/electron/main/ipc/window-fullscreen.ts
2026-09-30 00:58:46 +08:00

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));
};
}