Excuse me, is there a relatively good Typescript encapsulation for the communication between ipcMain and ipcRenderer?
According to the code written in the official documentation:
In the main process:
ipcMain.on('ping', () => console.log('pong'))
In the renderer process:
window.electron.ipcRenderer.send('ping')
This usage is not very good because:
send/sendSync/sendTo/invoke
. And sometimes when the main process listens, it is:on/handle
declare global {
interface Window {
electron: ElectronAPI
api: unknown
IPC: {
invoke: (channel: string, data: unknown[]) => Promise<unknown>
ipcOn: (
channel: string,
fun: (event: IpcRendererEvent, data: unknown[]) => void
) => Electron.IpcRenderer
removeAllListeners: (channel: string) => Electron.IpcRenderer
}
}
}
Generally, data: unknown[]
is defined. When transmitting, it is very difficult to know in the main process what data type is passed in. This should be optimized. Determine a data structure.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too