import { ipcMain } from 'electron'; type IpcHandler = (event: Electron.IpcMainInvokeEvent, ...args: T[]) => Promise | R; /** * Utility function to define IPC handlers with better type safety and error handling */ export function defineIpcHandler( channel: string, handler: IpcHandler, ): void { ipcMain.handle(channel, async (event, ...args) => { try { return await handler(event, ...args); } catch (error) { console.error(`Error in IPC handler '${channel}':`, error); throw error; } }); } /** * Remove an IPC handler */ export function removeIpcHandler(channel: string): void { ipcMain.removeHandler(channel); }