This package has been deprecated

Author message:

!!!This project is no longer maintained!!!

electron-aware

2.1.0 • Public • Published

electron-aware

Library that enables communication with the main Electron process.

Greenkeeper badge Build Status Dependency Status devDependency Status Version npm npm Downloads license Gratipay User Package Quality JavaScript Style Guide

NPM Package Quality JavaScript Style Guide


Installation

# Install as a development dependency (NPM)
npm install electron-aware --save-dev
# OR
# Install as a development dependency (Yarn)
yarn add electron-aware --dev

Usage

electron-aware can be used inside a gulp file to enable live reloading of your electron app.

const gulp = require('gulp')
const awareServer = require('electron-aware/server')

gulp.task('serve', () => {
  // this will activate electron-aware
  awareServer.start()
  
  // any changes made to the index.html file will refresh the electron app 
  gulp.watch('./index.html', awareServer.refresh)
  
  // any changes made to the electron main process file,
  // will cause electron to restart 
  gulp.watch('./main.js', awareServer.reload)
});

To get your electron app to work with electron-aware, as intended, a couple of lines of code need to be added to the main.js file (or whatever you named your electron main process file).

const {app, BrowserWindow} = require('electron')
...
// the 'main' sub-module must only be used inside the electron process!
const aware = require('electron-aware/main')

The next bit of code must be called on the ready or activate app events.

let window = new BrowserWindow({ /* your options here - its up to you :) */ });
...
// the window parameter is required, in order for electron-aware to work
aware.initialize(window);

electron-aware also allows you to create, subscribe, and raise custom events! On the server-side:

// subscribe to the 'my-custom-event' (raised by the client)
aware.on('my-custom-event', (args) => {
    // some logic
    ...
    // raise the 'my-other-custom-event' on the client
    aware.send('my-other-custom-event', /* your arguments here (optional) */)
})

On the client-side (electron main process):

...
// reference the client object
const awareClient = aware.initialize(window)
// subscribe to the 'my-other-custom-event' (raised by the server)
awareClient.on('my-other-custom-event', (args) => {
    // some logic
})

// raise the 'my-custom-event' on the server
awareClient.send('message', { event: 'my-custom-event', args: /* your arguments here (optional) */ })

License

MIT


Donating

Please support this project via gratipay.

Support via Gratipay

Package Sidebar

Install

npm i electron-aware

Weekly Downloads

3

Version

2.1.0

License

MIT

Last publish

Collaborators

  • heartnett