1.3.2 • Published 5 years ago
electron-api-ipc v1.3.2
Electron-api-ipc
A set of decorators and a inversifyJS wrapper to manage ipc event on the main process, the same way you would manage nestjs http routes.
check the doc
Installation
npm i electron-api-ipc
yarn add electron-api-ipc
Getting started
main process
import { bootstrapIpcApi, IpcController, IpcEvent } from 'electron-api-ipc';
import { injectable, inject } from 'inversify';
@injectable()
class MyDummyService {
doSomething() {
console.log('i am useless');
}
}
const $$dummy = Symbol('dummy-service');
@IpcController('test')
class MyCtrl {
constructor(@inject($$dummy) dummyService) {
this.dummy = dummyService;
}
@IpcEvent('foo')
handleFoo(event, data) {
console.log(data); // print hello world
this.dummy.doSomething();
}
@IpcEvent('once-event', { once: true })
handleOnce() {
console.log('you will see me only once :(');
}
}
const app = bootstrapIpcApi({
controllers: [MyCtrl],
services: [{ provide: $$dummy, useClass: MyDummyService }]
});
app.listen();
renderer process
import { ipcRenderer } from 'electron';
ipcRenderer.send('test-foo', 'hello world');
ipcRenderer.send('once-event');
ipcRenderer.send('once-event'); // nothing happen