Skip to main content

词汇表

🌐 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).

ASAR 完整性

🌐 ASAR integrity

ASAR 完整性是一项安全功能,用于在运行时验证应用 ASAR 存档的内容。启用后,你的 Electron 应用将在运行时验证其 ASAR 存档的头部哈希。如果未提供哈希或哈希不匹配,应用将强制终止。

🌐 ASAR integrity is a security feature that validates the contents of your app's ASAR archives at runtime. When enabled, your Electron app will verify the header hash of its ASAR archive on runtime. If no hash is present or if there is a mismatch in the hashes, the app will forcefully terminate.

有关更多详情,请参阅 ASAR 完整性 指南。

🌐 See the ASAR Integrity guide for more details.

代码签名

🌐 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 泄露给渲染进程中的网页内容。在启用上下文隔离的情况下,唯一从预加载脚本中暴露 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 文件通常用于分发应用“安装程序”。

🌐 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.jsonmain 属性中指定。这就是 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

苹果 Mac 应用商店的缩写。有关提交应用到 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 上,MSI 包由 Windows 安装程序(也称为 Microsoft Installer)服务用于安装和配置应用。

🌐 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 中也称为 插件)是用 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 支持原生 Node 模块,但由于 Electron 很可能使用的 V8 版本与系统中安装的 Node 二进制文件不同,因此在构建原生模块时,你必须手动指定 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 特有的一个进程,开发者可以将经过代码签名的应用发送到苹果服务器,通过自动化服务验证是否包含恶意组件。

🌐 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 a heavy page in background and then displaying it after (it will be much faster). It allows you to render a page without showing it on screen.

欲了解更多信息,请阅读 离屏渲染 教程。

🌐 For more information, read the Offscreen Rendering tutorial.

预加载脚本

🌐 preload script

预加载脚本包含在渲染器进程中执行的代码,这些代码在其网页内容开始加载之前运行。这些脚本在渲染器上下文中运行,但通过访问 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

进程是正在执行的计算机程序的一个实例。使用 并且一个或多个 渲染器 进程的 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.

另见:进程

🌐 See also: process

Squirrel

Squirrel 是一个开源框架,使 Electron 应用能够在新版本发布时自动更新。有关入门信息,请参阅 自动更新器 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 社区中被普及,用来区分“Node 核心”中可用的功能与由更大“用户”社区发布到 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,这些 API 提供了开发多平台桌面应用所需的所有基本功能。这种设计理念使 Electron 保持灵活,而不会对其使用方式提出过多规定。Userland 使用户能够创建和共享工具,在“核心”提供的功能基础上提供额外的功能。

🌐 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 中,你可以使用 实用程序进程 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 是谷歌的开源 JavaScript 引擎。它是用 C++ 编写的,并且用于谷歌浏览器。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 在构建 Chromium 时会构建 V8,然后在构建 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 应用中嵌入“访客”内容(例如外部网页)。它们类似于 iframe,但不同之处在于每个 webview 都在独立的进程中运行。它没有与你的网页相同的权限,并且应用与嵌入内容之间的所有交互都是异步的。这可以保护你的应用免受嵌入内容的影响。