Skip to content
This repository has been archived by the owner on Jun 15, 2021. It is now read-only.

Latest commit

 

History

History
86 lines (62 loc) · 1.45 KB

README.md

File metadata and controls

86 lines (62 loc) · 1.45 KB

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.