ipc use as Promises
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.eslintignore
.eslintrc
.gitignore
.npmignore
.travis.yml
HISTORY.md
LICENSE
README.md
ipc-promise.js
ipc-promise.min.js
package.json

README.md

ipc-promise

Build Status Dependency Status NPM version

ipc use as Promises

Installation

npm

$ npm install ipc-promise

Usage

main process

var ipcPromise = require('ipc-promise');

ipcPromise.on('twice', function(params) {
  return Promise.resolve(params.value * 2);
});

var electron = require('electron'),
    app = electron.app,
    BrowserWindow = electron.BrowserWindow,
    mainWindow;

app.on('ready', function() {
  mainWindow = new BrowserWindow({});
  mainWindow.loadURL('file://' + __dirname + '/index.html');
});

renderer process

<!DOCTYPE html>
<script src="ipc-promise.min.js"></script>
<script>
  ipcPromise
    .send('twice', {
      value: 1
    })
    .then(function(result) {
      console.log(result);  // => "2"
    });
</script>

Functions

on(event, listener)

  • event
    • String - event name
  • listener
    • Function(*): Promise - listener function

listen event.

send(event, data)

  • event
    • String - event name
  • data
    • * - data for send
  • return
    • Promise - Promises

trigger event.

Test

$ npm install
$ npm test

License

The MIT license. Please see LICENSE file.