1

他们是否有任何工具可以简化 IPC 并在单个网页和 node.js 进程之间进行数据编组?

我已阅读:http ://tangiblejs.com/posts/nw-js-and-electron-compared-2016-edition

其中概述了 nw.js 和电子之间的差异。两者看起来几乎一样,但我喜欢在不需要时尽量减少复杂性,所以我倾向于使用 nw.js 来避免 IPC 的问题。

但这可能是一个错误,因为我看到这个组中涉及电子的评论比 NW.JS 多 10 倍

(我的 IDE 将是 Visual Studio Code,它现在具有 NW.JS 调试扩展,但没有用于 Electron)。

4

1 回答 1

2

出于这个原因,我们开始使用 NWJS,也因为它支持chrome.serial. 最近我将项目转换为电子项目有几个原因:

没错,NWJS 没有主/渲染过程的复杂性,但我发现很少有理由必须处理 IPC。

许多 API 仅在进程中可用,但可以通过远程API 访问。因此,例如要从我使用的渲染过程中访问主要内容: process.argv

{process} = require('electron').remote
process.argv ...

在我的 index.js 中,我不得不做一些 IPC 的事情,但是电子有库来简化这个:

// ensure we only have a single instance, but pass args to renderer to open any files passed by explorer
const shouldQuit = app.makeSingleInstance((argv, workingDir) => {
  win.webContents.send('open-instance', argv);
})

然后在我的渲染器代码中,我有以下内容:

ipcRenderer.on('open-instance', (event, arg) => {
  this.restoreAndFocus();
  // TODO - handle another instance opening a file from explorer
});
于 2017-01-15T14:21:53.377 回答