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-im

v0.1.1

Published

electron ipc better, buffer design

Downloads

2

Readme

概述

主窗口server与其他窗口client的通信过程,可以用一种简易的消息模型来理解。

Feature

  • 支持离线消息模型

安装

npm i electron-ipc-im

配置说明

serverId: 'im' // 主窗口唯一标识
id: 'plugin', // 非主窗口唯一标识

非主窗口

const Client = require('electron-ipc-im/src/client');

const imClient = new Client({
    ipcRenderer: require('electron').ipcRenderer,
    serverId: 'im',
    id: 'plugin',
});

imClient.on({
    type: 'some type',
    callback: (err, res) => {}
})

imClient.request({
    type: 'offline',
    callback: (err, res) => {
        imClient.distribute(res);
    }
})

callback返回值

{
    rescode: 0, // 0 正确 401 鉴权失败 403 用户未授权 404 协议类型错误,协议过期 408 超时
    data: {}
}

主窗口

const Server = require('electron-ipc-im/src/server');

let imServer = new Server({
    ipcRenderer: require('electron').ipcRenderer,
    rendererManager: require('electron').remote.getGlobal('rendererManager'),
    winId: require('electron').remote.getCurrentWindow().id,
    serverId: 'im'
});

imServer.on({
    type: 'some type',
    callback: (err, res) => {
        imServer.response(Object.assign({}, res, { data: { rescode: 0, data: { name: 'lizheng' } } }))
    }
})

// 窗口管理
let plugin = {
    url: 'file:///Users/lizhengnacl/liz/learn/electron-quick-start/plugin/plugin.html',
    id: 'plugin'
};
imServer.rendererManager.load(plugin.url, plugin.id);
imServer.rendererManager.unload(plugin.id);

主进程

const Main = require('electron-ipc-im/src/main');
try {
    new Main({
        debug: false, // 是否开启调试
        ipcMain: require('electron').ipcMain,
        BrowserWindow: require('electron').BrowserWindow,
        capacity: 10 // 窗体消息缓存容量
    })
} catch(e) {}

Promisify

可以选择业界任意一个标准的promisify库,例如:

  • bluebird 模块里有 promisify 方法
  • es6-promisify 模块
  • ThinkJS 里的 promisify 方法

当然,也可以直接使用下面的示例代码

let promisify = (fn, receiver = null) => {
    return (...args) => {
        return new Promise((resolve, reject) => {
            fn.apply(receiver, [...args, (err, data) => {
                return err? reject(err): resolve(data);
            }]);
        });
    };
};

client.request = promisify(c.request, c);

client.request({
    type: '',
}).then((data) => {})

// 显式的callback参数优先级会更高,但不建议这么使用
c.request({
    type: '',
    callback: (err, data) => {}
}).then((data) => {})