/ipc-promise

ipc use as Promises

Primary LanguageJavaScriptMIT LicenseMIT

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.