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 🙏

© 2026 – Pkg Stats / Ryan Hefner

easier-electron-ipc

v1.0.1

Published

Make electron-ipc communication easier.

Readme

Easier Electron IPC

中文 | English

使Electron IPC通信更加简单的TypeScript库。

支持通信场景

  • 主进程内
  • 主进程与渲染进程
  • 渲染进程之间
  • 渲染进程内

简洁的 API

  • send & on
  • request & response

API 方法说明

| 方法 | 类型 | 描述 | 使用场景 | | -------------------------------------------- | -------- | ---------------------------------------------- | -------------------------- | | send(channel, data, options: ISendOptions) | 发送 | 发送消息到指定频道 | 单向通信,不需要返回值 | | on(channel, callback) | 监听 | 监听指定频道的消息 | 接收来自其他进程的消息 | | request(channel, data, options) | 请求 | 发送请求并等待响应 | 双向通信,需要返回值 | | response(channel, callback) | 响应 | 响应来自指定频道的请求,默认超时时间是 15000ms | 处理请求并返回结果 | | once(channel, callback, options) | 发送 | 单次监听指定频道的消息 | 单次单向通信,不需要返回值 | | off(channel, callback) | 取消监听 | 取消对指定频道的监听 | 清理事件监听器 |

类型

export interface ISendOptions {
  /** 定向通信的目标窗口 ID,定义主窗口是 -1 */
  targetIds?: number[];
  mode?: ESendMode;
}

/**
 * 发送模式:
 * IPC:默认,进程间通信,主进程与渲染进程、渲染进程之间
 * Event:仅事件模式,同渲染进程内的事件分发
 * Both:同时支持 ipc 与事件模式
 * OnlyMain:进程间通信,仅发送到主进程,当 OnlyMain 时,则不再使用 targetIds
 * OnlyClient:进程间通信,仅发送到渲染进程
 */
export enum ESendMode {
  IPC = 'IPC',
  Event = 'Event',
  Both = 'Both',
  OnlyMain = 'OnlyMain',
  OnlyClient = 'OnlyClient',
}

安装

npm install easier-electron-ipc

使用

// 主进程 在主进程代码入口初始化即可
import { IPCMain } from 'easier-electron-ipc';
global.ipcMain = new IPCMain();

global.ipcMain.on('CLOSE_SETTING', (data, options) => {
  // ...
})
global.ipcMain.response('GET_SYSTEM_INFO', (data, options) => {
  return 'ok';
});

// preload 中初始化
import { IPCClient } from 'easier-electron-ipc';
const ipcClient = new IPCClient();

window.electron = {
  ipc: ipcClient,
  api: {
    system: {
      closeSetting: (,data, options) => ipcClient.send('CLOSE_SETTING', data, options)
      getSystemInfo: (data, options) =>
        ipcClient.request('GET_SYSTEM_INFO', data, options),
    },
  },
};

// renderer 中使用

window.electron.api.system.closeSetting({ time: Date.now() }, { mode: 'OnlyMain' })

window.electron.api.system.getSystemInfo(
  { time: Date.now() },
  { timeout: 5000 }
);

其他使用场景

相同的 channel,流式操作:先触发主进程,再触发其他渲染进程(多标签的关闭存在此场景)

// A 渲染进程监听 channelA
window.electron.ipc.on('channelA', () => {});
// 主进程监听 channelA
global.enow.ipcMain.on('channelA', () => {});

// 发送:
// 渲染进程 B
window.electron.ipc.send('channelA', data, { mode: 'OnlyMain' }); // 主进程响应
window.electron.ipc.send('channelA', data, { mode: 'OnlyRender' }); // 包括 A 渲染进程在内的其他渲染响应

同渲染进程中使用 send-on,当事件使用

// A 渲染进程中
window.electron.ipc.on('channelA', () => {});

// 某个时刻调用
window.electron.ipc.send('channelA', data); // A 渲染进程(自己)不会响应
window.electron.ipc.send('channelA', data, { mode: 'Event' }); // 当第三个参数中 mode 设置为 Event、Both时,A 渲染进程(自己)会响应