在Electron中简化IPC的工具(tools to simplify IPC in Electron [closed])

系统教程 行业动态 更新时间:2024-06-14 17:03:54
在Electron中简化IPC的工具(tools to simplify IPC in Electron [closed])

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

我看过: http : //tangiblejs.com/posts/nw-js-and-electron-compared-2016-edition

其中概述了nw.js与电子之间的差异。 两者看起来几乎相同,但我喜欢在不需要时最小化复杂性,所以我倾向于nw.js以避免IPC的问题。

但这可能是一个错误,因为我看到这组中有超过10倍的关于电子的评论而不是NW.JS

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

Are their any tools for simplifying IPC and doing data marshaling between a single web page and the node.js processes?

I have read: http://tangiblejs.com/posts/nw-js-and-electron-compared-2016-edition

Which overviews the differences between nw.js and electron. Both seem pretty much the same, but I like to minimize complexity when not needed, so I am leaning to nw.js to avoid the issues of IPC.

But this might be a mistake, since I see 10X more comments dealing with electron in this group as opposed to NW.JS

(My IDE will be Visual Studio Code, which now has an extension for NW.JS debug, but none for Electron).

最满意答案

我们之所以开始使用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 });

We started using NWJS for that reason and also because it had support for chrome.serial. Lately I converted the project to electron for a few reasons:

More large companies on board more commits, testing and maintenance More built-in functionality eg, block power save Better packaging tooling Better test tooling

You're right that NWJS doesn't have the complication of the main/render processes but I've found very few reasons to have to deal with IPC.

Many of the APIs are only available in the main process but can be accessed via the remote API. So for example to get access to the main process.argv from the render process I use:

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

In my index.js I've had to do a few IPC things but electron has libraries to simplify this:

// 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); })

Then in my renderer code somewhere I have the following:

ipcRenderer.on('open-instance', (event, arg) => { this.restoreAndFocus(); // TODO - handle another instance opening a file from explorer });

更多推荐

本文发布于:2023-04-24 14:09:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/e5e65e33eeb022698558d516fe346bed.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:工具   IPC   Electron   closed   simplify

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!