- Added WINDOW_FULLSCREEN_CHANGED and WINDOW_IS_FULLSCREEN constants for fullscreen state management. - Enhanced main window to notify the renderer when entering or leaving fullscreen mode. - Implemented IPC handlers to check fullscreen status and notify changes to the renderer. - Introduced useFullScreen hook in the renderer to manage fullscreen state and adjust UI accordingly. These changes improve user experience by allowing dynamic adjustments to the UI based on fullscreen status.
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
/**
|
|
* IPC Handlers for native window controls.
|
|
* Used when the title bar is hidden (e.g. Windows / Linux) so the renderer
|
|
* can provide conventional min / maximize / close buttons.
|
|
*/
|
|
|
|
import { WINDOW_IS_FULLSCREEN } from '@preload/constants/ipcChannels';
|
|
import { createLogger } from '@shared/utils/logger';
|
|
import { BrowserWindow, type IpcMain } from 'electron';
|
|
|
|
const logger = createLogger('IPC:window');
|
|
|
|
function getMainWindow(): BrowserWindow | null {
|
|
const win = BrowserWindow.getFocusedWindow();
|
|
if (win && !win.isDestroyed()) return win;
|
|
const all = BrowserWindow.getAllWindows();
|
|
return all.length > 0 ? all[0] : null;
|
|
}
|
|
|
|
export function registerWindowHandlers(ipcMain: IpcMain): void {
|
|
ipcMain.handle('window:minimize', () => {
|
|
const win = getMainWindow();
|
|
if (win && !win.isDestroyed()) win.minimize();
|
|
});
|
|
|
|
ipcMain.handle('window:maximize', () => {
|
|
const win = getMainWindow();
|
|
if (win && !win.isDestroyed()) {
|
|
if (win.isMaximized()) win.unmaximize();
|
|
else win.maximize();
|
|
}
|
|
});
|
|
|
|
ipcMain.handle('window:close', () => {
|
|
const win = getMainWindow();
|
|
if (win && !win.isDestroyed()) win.close();
|
|
});
|
|
|
|
ipcMain.handle('window:isMaximized', (): boolean => {
|
|
const win = getMainWindow();
|
|
return win != null && !win.isDestroyed() && win.isMaximized();
|
|
});
|
|
|
|
ipcMain.handle(WINDOW_IS_FULLSCREEN, (): boolean => {
|
|
const win = getMainWindow();
|
|
return win != null && !win.isDestroyed() && win.isFullScreen();
|
|
});
|
|
|
|
logger.info('Window handlers registered');
|
|
}
|
|
|
|
export function removeWindowHandlers(ipcMain: IpcMain): void {
|
|
ipcMain.removeHandler('window:minimize');
|
|
ipcMain.removeHandler('window:maximize');
|
|
ipcMain.removeHandler('window:close');
|
|
ipcMain.removeHandler('window:isMaximized');
|
|
ipcMain.removeHandler(WINDOW_IS_FULLSCREEN);
|
|
logger.info('Window handlers removed');
|
|
}
|