Skip to content

lightningminers/electron-easy-ipc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

electron-easy-ipc

img img

简单易用的 electron ipc 通信实现。

Install

$ yarn add electron-easy-ipc

Usage

数据结构返回:

{
  code: number;
  message: any;
}

renderer 单向通信:

// main
const { simpleOn, OK } = require("../lib/index");
simpleOn("simple-on", (options) => {
  const response = {
    code: OK,
    message: options
  }
  return Promise.resolve(response);
});
// renderer
const { longSend } = require("../lib/index");
const simples = {
  simple: "simple"
}

simpleSend("simple-on", simples).then((response) => {
  console.log(response);
});

long 双向通信:

// main
const { longOn } = require("../lib/index");
longOn("long-on", (options, server) => {
  // open
    server.onMessage = (message) => {
      console.log(message);
      // renderer send message to main
      // handler and use sendMessage send result message
      // server.sendMessage("main to renderer icepy");
    }
  //
  return () => {
    // disconnect
  }
});
// renderer
const { longSend } = require("../lib/index");
const initLongs = {
  long: "long"
}

const longClient = longSend("long-on", initLongs);
longClient.sendMessage("init renderer");
longClient.onMessage = (message) => {
  // longClient.sendMessage()
  longClient.sendMessage("renderer to main message");
}

LICENSE

MIT License Copyright (c) 2019 子曰五溪

About

简单易用的 electron ipc 通信实现

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published