词汇表
¥Glossary
本页定义了 Electron 开发中常用的一些术语。
¥This page defines some terminology that is commonly used in Electron development.
ASAR
ASAR 代表 Atom Shell 存档格式。asar 存档是一种类似 tar
的简单格式,它将文件连接成单个文件。Electron 可以从中读取任意文件,而无需解压整个文件。
¥ASAR stands for Atom Shell Archive Format. An asar archive is a simple
tar
-like format that concatenates files into a single file. Electron can read
arbitrary files from it without unpacking the whole file.
创建 ASAR 格式的主要目的是提高 Windows 上读取大量小文件时的性能(例如,从 node_modules
加载应用的 JavaScript 依赖树时)。
¥The ASAR format was created primarily to improve performance on Windows when
reading large quantities of small files (e.g. when loading your app's JavaScript
dependency tree from node_modules
).
代码签名
¥code signing
代码签名是应用开发者对其代码进行数字签名的过程,以确保其在打包后未被篡改。Windows 和 macOS 都实现了自己的代码签名版本。作为桌面应用开发者,如果你打算将代码分发给公众,那么对代码进行签名非常重要。
¥Code signing is a process where an app developer digitally signs their code to ensure that it hasn't been tampered with after packaging. Both Windows and macOS implement their own version of code signing. As a desktop app developer, it's important that you sign your code if you plan on distributing it to the general public.
有关更多信息,请阅读 代码签名 教程。
¥For more information, read the Code Signing tutorial.
上下文隔离
¥context isolation
上下文隔离是 Electron 中的一项安全措施,可确保你的预加载脚本不会将特权 Electron 或 Node.js API 泄漏到渲染器进程中的 Web 内容。启用上下文隔离后,从预加载脚本公开 API 的唯一方法是通过 contextBridge
API。
¥Context isolation is a security measure in Electron that ensures that your
preload script cannot leak privileged Electron or Node.js APIs to the web
contents in your renderer process. With context isolation enabled, the
only way to expose APIs from your preload script is through the
contextBridge
API.
有关更多信息,请阅读 上下文隔离 教程。
¥For more information, read the Context Isolation tutorial.
¥See also: preload script, renderer process
CRT
C 运行时库 (CRT) 是 C++ 标准库的一部分,其中包含 ISO C99 标准库。实现 CRT 的 Visual C++ 库支持原生代码开发、混合原生代码和托管代码以及用于 .NET 开发的纯托管代码。
¥The C Runtime Library (CRT) is the part of the C++ Standard Library that incorporates the ISO C99 standard library. The Visual C++ libraries that implement the CRT support native code development, and both mixed native and managed code, and pure managed code for .NET development.
DMG
Apple 磁盘映像是 macOS 使用的一种打包格式。DMG 文件通常用于分发应用 "installers"。
¥An Apple Disk Image is a packaging format used by macOS. DMG files are commonly used for distributing application "installers".
IME
输入法编辑器。允许用户输入键盘上找不到的字符和符号的程序。例如,这允许拉丁键盘的用户输入中文、日文、韩文和印度字符。
¥Input Method Editor. A program that allows users to enter characters and symbols not found on their keyboard. For example, this allows users of Latin keyboards to input Chinese, Japanese, Korean and Indic characters.
IDL
接口描述语言。以可用于生成 Java、C++、JavaScript 等接口的格式编写函数签名和数据类型。
¥Interface description language. Write function signatures and data types in a format that can be used to generate interfaces in Java, C++, JavaScript, etc.
IPC
IPC 代表进程间通信。Electron 使用 IPC 在主进程和渲染进程之间发送序列化的 JSON 消息。
¥IPC stands for inter-process communication. Electron uses IPC to send serialized JSON messages between the main and renderer processes.
¥see also: main process, renderer process
主进程
¥main process
主进程(通常是名为 main.js
的文件)是每个 Electron 应用的入口点。它控制应用的生命周期,从打开到关闭。它还管理原生元素,例如菜单、菜单栏、Dock、托盘等。主进程负责创建应用中的每个新渲染器进程。内置完整的 Node API。
¥The main process, commonly a file named main.js
, is the entry point to every
Electron app. It controls the life of the app, from open to close. It also
manages native elements such as the Menu, Menu Bar, Dock, Tray, etc. The
main process is responsible for creating each new renderer process in the app.
The full Node API is built in.
每个应用的主进程文件都在 package.json
中的 main
属性中指定。这就是 electron .
知道启动时要执行哪个文件的方式。
¥Every app's main process file is specified in the main
property in
package.json
. This is how electron .
knows what file to execute at startup.
在 Chromium 中,此进程称为 "浏览器进程"。它在 Electron 中被重命名,以避免与渲染器进程混淆。
¥In Chromium, this process is referred to as the "browser process". It is renamed in Electron to avoid confusion with renderer processes.
¥See also: process, renderer process
MAS
Apple Mac App Store 的缩写。有关向 MAS 提交应用的详细信息,请参阅 Mac App Store 提交指南。
¥Acronym for Apple's Mac App Store. For details on submitting your app to the MAS, see the Mac App Store Submission Guide.
Mojo
用于进程内或进程间通信的 IPC 系统,这很重要,因为 Chrome 热衷于能够将其工作拆分为单独的进程或不拆分,具体取决于内存压力等。
¥An IPC system for communicating intra- or inter-process, and that's important because Chrome is keen on being able to split its work into separate processes or not, depending on memory pressures etc.
见 https://chromium.googlesource.com/chromium/src/+/main/mojo/README.md
¥See https://chromium.googlesource.com/chromium/src/+/main/mojo/README.md
也可以看看:IPC
¥See also: IPC
MSI
在 Windows 上,Windows Installer(也称为 Microsoft Installer)服务使用 MSI 包来安装和配置应用。
¥On Windows, MSI packages are used by the Windows Installer (also known as Microsoft Installer) service to install and configure applications.
更多信息可以在 微软的文档 中找到。
¥More information can be found in Microsoft's documentation.
原生模块
¥native modules
原生模块(在 Node.js 中也称为 addons)是用 C 或 C++ 编写的模块,可以使用 require() 函数加载到 Node.js 或 Electron 中,并像普通 Node.js 模块一样使用。它们主要用于在 Node.js 中运行的 JavaScript 和 C/C++ 库之间提供接口。
¥Native modules (also called addons in Node.js) are modules written in C or C++ that can be loaded into Node.js or Electron using the require() function, and used as if they were an ordinary Node.js module. They are used primarily to provide an interface between JavaScript running in Node.js and C/C++ libraries.
Electron 支持 Native Node 模块,但由于 Electron 很可能使用与系统中安装的 Node 二进制文件不同的 V8 版本,因此在构建原生模块时必须手动指定 Electron 标头的位置。
¥Native Node modules are supported by Electron, but since Electron is very likely to use a different V8 version from the Node binary installed in your system, you have to manually specify the location of Electron’s headers when building native modules.
有关更多信息,请阅读 原生 Node 模块 教程。
¥For more information, read the Native Node Modules tutorial.
notarization
公证是 macOS 特定的过程,开发者可以将代码签名的应用发送到 Apple 服务器,以通过自动化服务验证是否存在恶意组件。
¥Notarization is a macOS-specific process where a developer can send a code-signed app to Apple servers to get verified for malicious components through an automated service.
也可以看看:代码签名
¥See also: code signing
OSR
OSR(离屏渲染)可用于在后台加载大量页面,然后再显示它(速度会快得多)。它允许你渲染页面而不将其显示在屏幕上。
¥OSR (offscreen rendering) can be used for loading heavy page in background and then displaying it after (it will be much faster). It allows you to render page without showing it on screen.
有关更多信息,请阅读 离屏渲染 教程。
¥For more information, read the Offscreen Rendering tutorial.
预加载脚本
¥preload script
预加载脚本包含在 Web 内容开始加载之前在渲染器进程中执行的代码。这些脚本在渲染器上下文中运行,但通过访问 Node.js API 被授予更多权限。
¥Preload scripts contain code that executes in a renderer process before its web contents begin loading. These scripts run within the renderer context, but are granted more privileges by having access to Node.js APIs.
¥See also: renderer process, context isolation
process
进程是正在执行的计算机程序的实例。使用 main 和一个或多个 renderer 进程的 Electron 应用实际上同时运行多个程序。
¥A process is an instance of a computer program that is being executed. Electron apps that make use of the main and one or many renderer process are actually running several programs simultaneously.
在 Node.js 和 Electron 中,每个正在运行的进程都有一个 process
对象。该对象是一个全局对象,提供有关当前进程的信息和对当前进程的控制。作为全局变量,应用始终可以使用它,而无需使用 require()。
¥In Node.js and Electron, each running process has a process
object. This
object is a global that provides information about, and control over, the
current process. As a global, it is always available to applications without
using require().
¥See also: main process, renderer process
渲染进程
¥renderer process
渲染器进程是应用中的浏览器窗口。与主进程不同,可以有多个进程,并且每个进程都在单独的进程中运行。它们也可以被隐藏。
¥The renderer process is a browser window in your app. Unlike the main process, there can be multiple of these and each is run in a separate process. They can also be hidden.
¥See also: process, main process
sandbox
沙箱是从 Chromium 继承的一项安全功能,它将渲染器进程限制为一组有限的权限。
¥The sandbox is a security feature inherited from Chromium that restricts your renderer processes to a limited set of permissions.
有关更多信息,请阅读 进程沙箱 教程。
¥For more information, read the Process Sandboxing tutorial.
也可以看看:process
¥See also: process
Squirrel
Squirrel 是一个开源框架,使 Electron 应用能够在新版本发布时自动更新。有关 Squirrel 入门的信息,请参阅 autoUpdater API。
¥Squirrel is an open-source framework that enables Electron apps to update automatically as new versions are released. See the autoUpdater API for info about getting started with Squirrel.
userland
这个术语起源于 Unix 社区,其中 "userland" 或 "userspace" 指的是在操作系统内核之外运行的程序。最近,该术语在 Node 和 npm 社区中流行起来,用于区分 "节点核心" 中可用的功能与由更大的 "user" 社区发布到 npm 注册表的包。
¥This term originated in the Unix community, where "userland" or "userspace" referred to programs that run outside of the operating system kernel. More recently, the term has been popularized in the Node and npm community to distinguish between the features available in "Node core" versus packages published to the npm registry by the much larger "user" community.
与 Node 一样,Electron 专注于拥有一小组 API,为开发多平台桌面应用提供所有必要的基础类型。这种设计理念使得 Electron 仍然是一个灵活的工具,而不会过度规范它的使用方式。Userland 使用户能够创建和共享工具,这些工具在 "core" 中提供的功能之上提供附加功能。
¥Like Node, Electron is focused on having a small set of APIs that provide all the necessary primitives for developing multi-platform desktop applications. This design philosophy allows Electron to remain a flexible tool without being overly prescriptive about how it should be used. Userland enables users to create and share tools that provide additional functionality on top of what is available in "core".
实用进程
¥utility process
实用程序进程是主进程的子进程,允许运行无法在主进程中运行的任何不受信任的服务。Chromium 使用此进程来执行网络 I/O、音频/视频处理、设备输入等。在 Electron 中,你可以使用 UtilityProcess API 创建此进程。
¥The utility process is a child of the main process that allows running any untrusted services that cannot be run in the main process. Chromium uses this process to perform network I/O, audio/video processing, device inputs etc. In Electron, you can create this process using UtilityProcess API.
¥See also: process, main process
V8
V8 是 Google 的开源 JavaScript 引擎。它是用 C++ 编写的,并在 Google Chrome 中使用。V8 可以独立运行,也可以嵌入到任何 C++ 应用中。
¥V8 is Google's open source JavaScript engine. It is written in C++ and is used in Google Chrome. V8 can run standalone, or can be embedded into any C++ application.
Electron 将 V8 构建为 Chromium 的一部分,然后在构建时将 Node 指向该 V8。
¥Electron builds V8 as part of Chromium and then points Node to that V8 when building it.
V8 的版本号始终与 Google Chrome 的版本号相对应。Chrome 59 包括 V8 5.9,Chrome 58 包括 V8 5.8 等。
¥V8's version numbers always correspond to those of Google Chrome. Chrome 59 includes V8 5.9, Chrome 58 includes V8 5.8, etc.
webview
webview
标签用于在 Electron 应用中嵌入 'guest' 内容(例如外部网页)。它们与 iframe
类似,但不同之处在于每个 webview 都在单独的进程中运行。它没有与你的网页相同的权限,并且你的应用和嵌入内容之间的所有交互都将是异步的。这可以确保你的应用免受嵌入内容的影响。
¥webview
tags are used to embed 'guest' content (such as external web pages) in
your Electron app. They are similar to iframe
s, but differ in that each
webview runs in a separate process. It doesn't have the same
permissions as your web page and all interactions between your app and
embedded content will be asynchronous. This keeps your app safe from the
embedded content.