electron-typesafe-ipc
Module for safe inter process communication (IPC) in electron. TypeScript supported.
Installation
yarn add electron-typesafe-ipc
Usage
configure typesafe ipc object:
// src/tsipc.ts; //first, describe the ipc communication schema - channel names, their direction (main->rend / rend->main) and type of their params (void means no params); //then create the typesafe ipc object via library function;
use it in main process:
// src/main.ts; //register listenertsipc.main.on.login; //send message to renderer process (BrowserWindow win - your app window with target renderer process)tsipc.main.send.trayLogoutClickwin;
use it in renderer process:
// src/renderer.ts; //register listenertsipc.rend.on.trayItemClick; //send message to main processtsipc.rend.send.login;
API
configuration
createIpcChannel;createTypesafeIpcipcSchema: TIpcSchema;
usage
tsipc.main.send; tsipc.main.on;tsipc.main.once;tsipc.main.remove;
tsipc.rend.send; tsipc.rend.on;tsipc.rend.once;tsipc.rend.remove;
Notes
- currently, this library is designed to support only one renderer process (although it may work across many renderer processes, it is not tested)
TODO
- app for testing (with webpack)
- minimal app as an example
- bi-directional channels (both main->rend and rend->main)
- document the end-2-end politics (you always register only one event, which distributes the event further)
sync communication
- design API
- implement it (with typesafe return)
- implement timeout option
mutliple renderer processes
- design API to support multiple renderer processes
- implement API to support multiple renderer processes
runtime checking
- check that consumer uses the correct side of tsipc (
tsipc.main.*
in main,tsipc.rend.*
in renderer)