Electron项目结构——main process与renderer process

公司使用微服务的架构进行开发,这就会带来频繁的下载制品,上传镜像的操作,为此利用 electron 开发一个简单的自动化工具就显得尤为重要,以下是摘自官方文档的内容,对 electron 进行记录。

Main and Render Process

In Electron, the process that runs package.json’s main script is called the main process. The script that runs in the main process can display a GUI by creating web pages. An Electron app always has one main process, but never more.

Since Electron uses Chromium for displaying web pages, Chromium’s multi-process architecture is also used. Each web page in Electron runs in its own process, which is called the renderer process.

In normal browsers, web pages usually run in a sandboxed environment and are not allowed access to native resources. Electron users, however, have the power to use Node.js APIs in web pages allowing lower level operating system interactions.

以上一段大致结论翻译:

  • 运行 main.jsprocess 被成为 main process, 而且 electron app 有且仅有一个 main processelectron 使用 Chromium 进行展示网页。
  • Chromium 的多进程架构也使得每一个在 electron 中的页面都独立运行在各自的 process 中,称为 renderer process
  • 在通常的浏览器中,网页都运行在沙箱环境中并且不能访问本地的资源,但是 electron 可以使用 Node.js APIs ,有权与底层操作系统进行交互。

Differences Between Main Process and Renderer Process

The main process creates web pages by creating BrowserWindow instances. Each BrowserWindow instance runs the web page in its own renderer process. When a BrowserWindow instance is destroyed, the corresponding renderer process is also terminated.

The main process manages all web pages and their corresponding renderer processes. Each renderer process is isolated and only cares about the web page running in it.

In web pages, calling native GUI related APIs is not allowed because managing native GUI resources in web pages is very dangerous and it is easy to leak resources. If you want to perform GUI operations in a web page, the renderer process of the web page must communicate with the main process to request that the main process perform those operations.

以上一段大致结论翻译:

  • main process 通过创建 BrowserWindow 实例来创建网页,每一个 BrowserWindow 实例运行在各自的 renderer process中,当一个 renderer process 销毁,对应的renderer process 也会停止。
  • main process 管理所有的页面以及他们对应的 renderer processes, 每个renderer processes 都是独立的并且只关心运行在各自上面的页面。
  • 在页面中调用 native GUI 相关的 API 是不允许的,因为可能会泄漏资源,如果想进行相关操作,renderer processes 必须与 main process 通信,请求 main process 允许。

reference

Electron Application Architecture

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值