公司使用微服务的架构进行开发,这就会带来频繁的下载制品,上传镜像的操作,为此利用 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.js
的process
被成为main process
, 而且electron app
有且仅有一个main process
。electron
使用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
允许。