electron-events
TypeScript icon, indicating that this package has built-in type declarations

0.3.2 • Public • Published

electron-events

Provide a cross process event communication system for Electron.

Install

# use npm
npm install electron-events

# or use yarn
yarn add electron-events

Usage

Add the window module to the event system in the main process:

import { useEvents } from 'electron-events';

const events = useEvents('browser');
const mainWindow = new BrowserWindow();

events.addWindow(
  /* The name here will be used later to specify the target or recipient of the event triggered. */
  'app',
  mainWindow
);

Now you don't have to care about the process, just communicate events based on the name of the window:

// Renderer
import { useEvents } from 'electron-events';

const events = useEvents();

events.on('main' /* Name of the main process */, 'say_hi', text => {
  console.log(text);
});

// Main
import { useEvents } from 'electron-events';

const events = useEvents();

events.emitTo('app', 'say_hi', 'Hello World!');

As you can see, event can be sent and received in either the main process or the renderer process.

See more.

License

MIT

Dependencies (1)

Dev Dependencies (13)

Package Sidebar

Install

npm i electron-events

Weekly Downloads

5

Version

0.3.2

License

MIT

Unpacked Size

154 kB

Total Files

73

Last publish

Collaborators

  • kisstar