ElectricIPC is an extension to the Electron framework. It extends the Electron IPC solution and enables easy shareable classes.
npm i -s electric-ipc
export class SampleIPCService extends ElectricIPC {
// Sample private declarations
private identifier: number;
// Make sure to declare window as optional
public constructor(window?: BrowserWindow) {
// Here you can add methods
// you don't want to share
// with the renderer.
super(window, 'init' /*, 'and', 'more', 'methods'*/);
}
public init(min: number, max: number): void {
this.identifier = Math.floor(Math.random() * (max - min + 1) + min);
}
public getIdentifier(): number {
return this.identifier;
}
}
app.on('ready', () => {
const window = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
});
new SampleIPCService(window).init(1, 100);
}));
const service = new SampleIPCService();
console.log(service.getIdentifier());
This library also supports Promises. Just write a function in your service and return a Promise<T>
.