import { ipcRenderer } from 'electron'; import type { IpcEventMap, IpcInvokeMap } from '../shared/ipc/contracts'; export async function invoke( channel: K, payload: IpcInvokeMap[K]['req'], ): Promise { return (await ipcRenderer.invoke(channel as string, payload)) as IpcInvokeMap[K]['res']; } export function on( channel: K, listener: (payload: IpcEventMap[K]) => void, ): () => void { const wrapped = (_: Electron.IpcRendererEvent, payload: unknown) => { listener(payload as IpcEventMap[K]); }; ipcRenderer.on(channel as string, wrapped); return () => { ipcRenderer.off(channel as string, wrapped); }; }