1.3.0-alpha0007 • Published 5 years ago

electric-ipc v1.3.0-alpha0007

Weekly downloads
7
License
MIT
Repository
github
Last release
5 years ago

ElectricIPC

ElectricIPC is an extension to the Electron framework. It extends the Electron IPC solution and enables easy shareable classes.

Build Status npm version

Usage

Install the package

npm i -s electric-ipc

Create a service which extends ElectricIPC

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;
  }
}

Create an instance of the service in the main process

app.on('ready', () => {
    const window = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
            nodeIntegration: true
        }
    });
    new SampleIPCService(window).init(1, 100);
}));

Create an instance of the service in the renderer process and use methods

const service = new SampleIPCService();
console.log(service.getIdentifier());

Promises

This library also supports Promises. Just write a function in your service and return a Promise<T>.