npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

electron-ipc-plus

v1.3.4

Published

Improved IPC operations for electron

Downloads

329

Readme

electron-ipc-plus

Linux Build Status Windows Build status Dependency Status devDependency Status

Improved IPC for Electron

Features

  • Enhance IPC Programming Experience
  • Allow sending ipc message to specific window
  • Allow sending ipc request and waiting for the reply in callback function

Install

npm install --save electron-ipc-plus

Run The Example

npm start examples/${name}

Usage

Send request from main process to renderer process and wait for reply.

main process

const ipcPlusM = require('electron-ipc-plus');

ipcPlusM.sendToWin(browserWin, 'app:say-hello', 'hello renderer process!', (err, message) => {
  console.log(`renderer replied: ${message}`);
});

renderer process

const ipcPlusR = require('electron-ipc-plus');

ipcPlusR.on('app:say-hello', (event, message) => {
  console.log(`main process said: ${message}`);

  setTimeout(() => {
    event.reply(null, 'hi main process!');
  }, 500);
});

Send request from renderer process to main process and wait for reply.

renderer process

const ipcPlusR = require('electron-ipc-plus');

ipcPlusR.sendToMain('app:say-hello', 'hello main process!', (err, message) => {
  console.log(`main replied: ${message}`);
});

main process

const ipcPlusM = require('electron-ipc-plus');

ipcPlusM.on('app:say-hello', (event, message) => {
  console.log(`renderer process said: ${message}`);

  setTimeout(() => {
    event.reply(null, 'hi renderer process!');
  }, 500);
});

FAQ

How can I know if an IPC is waiting for reply?

Just check if event.reply exists:

ipcMain.on('app:say-hello', (event, message) => {
  if ( event.reply ) {
    event.reply(null, 'hi renderer process!');
  }
});

Can I reply a message for multiple times?

Only the first reply will be handled, after that the session will be closed and the rest of replies will be ignored.

What happen when the window closed and I still waiting the reply from it.

An error with the code 'EWINCLOSED' will be sent to your reply handler.

ipcPlus.sendToWin(win, 'app:say-hello', (err, message) => {
  if ( err && err.code === 'EWINCLOSED' ) {
    console.error('Window closed');
  }
});

What happen when the reply is timed out.

An error with the code 'ETIMEDOUT' will be sent to your reply handler.

ipcPlus.sendToWin(win, 'app:say-hello', (err, message) => {
  if ( err && err.code === 'ETIMEDOUT' ) {
    console.error('Target failed to reply you: timedout for 100ms');
  }
}, 100);

Known Issues

ipcPlus.sendToWin could leave wild sessions in main process when the window reload.

I try to solve this problem by the code below:

app.on('browser-window-created', (event, browserWin) => {
  // close all session once the window closed
  browserWin.webContents.once('did-navigate', () => {
    _closeAllSessionsInWin(browserWin);
  });
});

The problem is 'did-navigate' will be triggerred at the first time we open the window and I disable the above solution and leave this to user. Currently the best way to solve it is wrapping your own reload function, and manually close all sessions in that wrapped function.

Different versions of electron-ipc-plus.

When running an Electron app that has several modules depends on different version of electron-ipc-plus, we will receive a warning message.

API Reference

License

MIT © 2017 Johnny Wu