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

sasaplus1/ipc-promise

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.