Skip to main content

突破屏障:使用沙盒增强应用

· 10 min read

CVE-2023-4863:WebP 中的堆缓冲区溢出 发布已经一周多了,随之而来的是一系列用于渲染 webp 图片的软件新版本的发布:macOS、iOS、Chrome、Firefox 和各种 Linux 发行版均已收到更新。此前,公民实验室进行了调查,发现一个“华盛顿特区民间社会组织”使用的 iPhone 正遭受 iMessage 中零点击漏洞的攻击。

¥It’s been more than a week since CVE-2023-4863: Heap buffer overflow in WebP was made public, leading to a flurry of new releases of software rendering webp images: macOS, iOS, Chrome, Firefox, and various Linux distributions all received updates. This followed investigations by Citizen Lab, discovering that an iPhone used by a “Washington DC-based civil society organization” was under attack using a zero-click exploit within iMessage.

Electron 也在同一天迅速行动并发布了新版本:如果你的应用需要渲染任何用户提供的内容,则应更新你的 Electron 版本。 - v27.0.0-beta.2、v26.2.1、v25.8.1、v24.8.3 和 v22.3.24 均包含 libwebp 的修复版本,libwebp 是负责渲染 webp 图片的库。

¥Electron, too, spun into action and released new versions the same day: If your app renders any user-provided content, you should update your version of Electron - v27.0.0-beta.2, v26.2.1, v25.8.1, v24.8.3, and v22.3.24 all contain a fixed version of libwebp, the library responsible for rendering webp images.

现在我们都清楚地意识到,像“渲染图片”这样简单的交互也可能存在危险,我们想借此机会提醒大家,Electron 内置了一个进程沙盒,它可以限制下一次大规模攻击的波及范围 - 无论它是什么。

¥Now that we are all freshly aware that an interaction as innocent as “rendering an image” is a potentially dangerous activity, we want to use this opportunity to remind everyone that Electron comes with a process sandbox that will limit the blast radius of the next big attack — whatever it may be.

沙盒自 Electron v1 以来就已可用,并在 v20 中默认启用,但我们知道许多应用(尤其是那些已经存在一段时间的应用)的代码中可能包含 sandbox: falsenodeIntegration: true,当没有明确的 sandbox 设置时,它们同样会禁用沙盒。这很容易理解:如果你已经与我们合作很长时间,你可能已经享受过将 require("child_process")require("fs") 放入运行 HTML/CSS 的同一代码中的强大功能。

¥The sandbox was available ever since Electron v1 and enabled by default in v20, but we know that many apps (especially those that have been around for a while) may have a sandbox: false somewhere in their code – or a nodeIntegration: true, which equally disables the sandbox when there is no explicit sandbox setting. That’s understandable: If you’ve been with us for a long time, you probably enjoyed the power of throwing a require("child_process") or require("fs") into the same code that runs your HTML/CSS.

在讨论如何迁移到沙盒之前,我们先来讨论一下为什么需要它。

¥Before we talk about how you migrate to the sandbox, let’s first discuss why you want it.

沙盒为所有渲染器进程设置了一个严格的“笼子”,确保无论内部发生什么,代码都在受限的环境中执行。就概念而言,它比 Chromium 更古老,并且是所有主流操作系统都提供的一项功能。Electron 和 Chromium 的沙盒构建于这些系统功能之上。即使你从不显示用户生成的内容,也应该考虑渲染器可能被入侵的可能性:无论是像供应链攻击这样复杂的场景,还是像小错误这样简单的场景,都可能导致渲染器执行你未完全预期的操作。

¥The sandbox puts a hard cage around all renderer processes, ensuring that no matter what happens inside, code is executed inside a restricted environment. As a concept, it's a lot older than Chromium, and provided as a feature by all major operating systems. Electron's and Chromium's sandbox build on top of these system features. Even if you never display user-generated content, you should consider the possibility that your renderer might get compromised: Scenarios as sophisticated as supply chain attacks and as simple as little bugs can lead to your renderer doing things you didn't fully intend for it to do.

沙盒使这种情况变得不那么可怕:内部进程可以自由使用 CPU 周期和内存 - 就是这样。进程无法写入磁盘或显示自己的窗口。在我们的 libwep 漏洞中,沙盒确保攻击者无法安装或运行恶意软件。事实上,在最初针对员工 iPhone 的 Pegasus 攻击案例中,攻击专门针对未沙盒化的镜像进程来获取手机访问权限,首先突破了通常处于沙盒状态的 iMessage 的界限。当类似本例中的 CVE 公布时,你仍然需要将 Electron 应用升级到安全版本 - 但与此同时,攻击者造成的损害程度将大大降低。

¥The sandbox makes that scenario a lot less scary: A process inside gets to freely use CPU cycles and memory — that’s it. Processes cannot write to disk or display their own windows. In the case of our libwep bug, the sandbox makes sure that an attacker cannot install or run malware. In fact, in the case of the original Pegasus attack on the employee’s iPhone, the attack specifically targeted a non-sandboxed image process to gain access to the phone, first breaking out of the boundaries of the normally sandboxed iMessage. When a CVE like the one in this example is announced, you still have to upgrade your Electron apps to a secure version — but in the meantime, the amount of damage an attacker can do is limited dramatically.

将原生 Electron 应用从 sandbox: false 迁移到 sandbox: true 是一项艰巨的任务。我知道,因为尽管我亲自编写了 Electron 安全指南 的初稿,但我还没有成功迁移到我自己的应用来使用它。这周末发生了变化,我建议你也进行修改。

¥Migrating a vanilla Electron application from sandbox: false to sandbox: true is an undertaking. I know, because even though I have personally written the first draft of the Electron Security Guidelines, I have not managed to migrate one of my own apps to use it. That changed this weekend, and I recommend that you change it, too.

Don’t be scared by the number of line changes, most of it is in package-lock.json

你需要解决两件事:

¥There are two things you need to tackle:

  1. 如果你在 preload 脚本或实际的 WebContents 中使用 Node.js 代码,则需要将所有 Node.js 交互移至主进程(或者,如果你喜欢,也可以移至实用程序进程)。鉴于渲染器已经变得如此强大,你的绝大多数代码很可能不需要重构。

    ¥If you’re using Node.js code in either preload scripts or the actual WebContents, you need to move all that Node.js interaction to the main process (or, if you are fancy, a utility process). Given how powerful renderers have become, chances are high that the vast majority of your code doesn’t really need refactoring.

    请参阅我们关于 进程间通信 的文档。就我而言,我移动了大量代码并将其打包到 ipcRenderer.invoke()ipcMain.handle() 中,但这个过程很简单,很快就完成了。请注意你的 API - 如果你构建了一个名为 executeCodeAsRoot(code) 的 API,沙盒并不能很好地保护你的用户。

    ¥Consult our documentation on Inter-Process Communication. In my case, I moved a lot of code and wrapped it in ipcRenderer.invoke() and ipcMain.handle(), but the process was straightforward and quickly done. Be a little mindful of your APIs here - if you build an API called executeCodeAsRoot(code), the sandbox won't protect your users much.

  2. 由于启用沙盒会禁用预加载脚本中的 Node.js 集成,因此你将无法再使用 require("../my-script")。换句话说,你的预加载脚本需要是一个单独的文件。

    ¥Since enabling the sandbox disables Node.js integration in your preload scripts, you can no longer use require("../my-script"). In other words, your preload script needs to be a single file.

    有多种方法可以解决此问题:Webpack、esbuild、parcel 和 rollup 都可以完成这项工作。我使用了 Electron Forge 优秀的 Webpack 插件,同样流行的 electron-builder 的用户可以使用 electron-webpack

    ¥There are multiple ways to do that: Webpack, esbuild, parcel, and rollup will all get the job done. I used Electron Forge’s excellent Webpack plugin, users of the equally popular electron-builder can use electron-webpack.

总而言之,整个过程花了我大约四天时间 - 这期间我花了很多时间思考如何驾驭 Webpack 的强大功能,因为我决定利用这个机会以许多其他方式重构我的代码。

¥All in all, the entire process took me around four days — and that includes a lot of scratching my head at how to wrangle Webpack’s massive power, since I decided to use the opportunity to refactor my code in plenty of other ways, too.

Electron 26.0.0

· 5 min read

Electron 26.0.0 已发布!它包含对 Chromium 116.0.5845.62、V8 11.2 和 Node.js 18.16.1 的升级。请阅读下文了解更多详情!

¥Electron 26.0.0 has been released! It includes upgrades to Chromium 116.0.5845.62, V8 11.2, and Node.js 18.16.1. Read below for more details!


Electron 团队非常高兴地宣布 Electron 26.0.0 正式发布!你可以通过 npm install electron@latest 使用 npm 安装它,也可以从我们的 发布网站。继续阅读以了解有关此版本的详细信息。

¥The Electron team is excited to announce the release of Electron 26.0.0! You can install it with npm via npm install electron@latest or download it from our releases website. Continue reading for details about this release.

如果你有任何反馈,请在 Twitter 上与我们分享,或加入我们的社区 Discord!可以在 Electron 的 问题跟踪器 中报告错误和功能请求。

¥If you have any feedback, please share it with us on Twitter, or join our community Discord! Bugs and feature requests can be reported in Electron's issue tracker.

显著变化

¥Notable Changes

技术栈变更

¥Stack Changes

重大变化

¥Breaking Changes

已弃用:webContents.getPrinters

¥Deprecated: webContents.getPrinters

webContents.getPrinters 方法已被弃用。请改用 webContents.getPrintersAsync

¥The webContents.getPrinters method has been deprecated. Use webContents.getPrintersAsync instead.

const w = new BrowserWindow({ show: false });

// Deprecated
console.log(w.webContents.getPrinters());
// Replace with
w.webContents.getPrintersAsync().then((printers) => {
console.log(printers);
});

已弃用:systemPreferences.{get,set}AppLevelAppearancesystemPreferences.appLevelAppearance

¥Deprecated: systemPreferences.{get,set}AppLevelAppearance and systemPreferences.appLevelAppearance

systemPreferences.getAppLevelAppearancesystemPreferences.setAppLevelAppearance 方法以及 systemPreferences.appLevelAppearance 属性已被弃用。请改用 nativeTheme 模块。

¥The systemPreferences.getAppLevelAppearance and systemPreferences.setAppLevelAppearance methods have been deprecated, as well as the systemPreferences.appLevelAppearance property. Use the nativeTheme module instead.

// Deprecated
systemPreferences.getAppLevelAppearance();
// Replace with
nativeTheme.shouldUseDarkColors;

// Deprecated
systemPreferences.appLevelAppearance;
// Replace with
nativeTheme.shouldUseDarkColors;

// Deprecated
systemPreferences.setAppLevelAppearance('dark');
// Replace with
nativeTheme.themeSource = 'dark';

已弃用:systemPreferences.getColoralternate-selected-control-text

¥Deprecated: alternate-selected-control-text value for systemPreferences.getColor

systemPreferences.getColoralternate-selected-control-text 值已被弃用。请改用 selected-content-background

¥The alternate-selected-control-text value for systemPreferences.getColor has been deprecated. Use selected-content-background instead.

// Deprecated
systemPreferences.getColor('alternate-selected-control-text');
// Replace with
systemPreferences.getColor('selected-content-background');

新功能

¥New Features

  • 添加了 safeStorage.setUsePlainTextEncryptionsafeStorage.getSelectedStorageBackend API。#39107

    ¥Added safeStorage.setUsePlainTextEncryption and safeStorage.getSelectedStorageBackend api. #39107

  • 添加了 safeStorage.setUsePlainTextEncryptionsafeStorage.getSelectedStorageBackend API。#39155

    ¥Added safeStorage.setUsePlainTextEncryption and safeStorage.getSelectedStorageBackend api. #39155

  • senderIsMainFrame 添加到通过 ipcRenderer.sendTo() 发送的消息中。#39206

    ¥Added senderIsMainFrame to messages sent via ipcRenderer.sendTo(). #39206

  • 添加了将菜单标记为键盘启动的支持。#38954

    ¥Added support for flagging a Menu as being keyboard initiated. #38954

23.x.y 支持终止

¥End of Support for 23.x.y

根据项目的 支持政策,Electron 23.x.y 已达到支持终止状态。建议开发者和应用升级到较新版本的 Electron。

¥Electron 23.x.y has reached end-of-support as per the project's support policy. Developers and applications are encouraged to upgrade to a newer version of Electron.

E26 (2023 年 8 月)E27 (2023 年 10 月)E28 (2024 年 1 月)
26.x.y27.x.y28.x.y
25.x.y26.x.y27.x.y
24.x.y25.x.y26.x.y
22.x.y

下一步计划

¥What's Next

短期内,你可以预期团队将继续专注于跟上构成 Electron 的主要组件(包括 Chromium、Node 和 V8)的开发。

¥In the short term, you can expect the team to continue to focus on keeping up with the development of the major components that make up Electron, including Chromium, Node, and V8.

你可以找到 Electron 公开时间线

¥You can find Electron's public timeline here.

有关未来变更的更多信息,请参阅 计划中的突发事件变更 页面。

¥More information about future changes can be found on the Planned Breaking Changes page.

Electron 25.0.0

· 9 min read

Electron 25.0.0 已发布!它包含对 Chromium 114、V8 11.4 和 Node.js 18.15.0 的升级。请阅读下文了解更多详情!

¥Electron 25.0.0 has been released! It includes upgrades to Chromium 114, V8 11.4, and Node.js 18.15.0. Read below for more details!


Electron 团队非常高兴地宣布 Electron 25.0.0 正式发布!你可以通过 npm install electron@latest 使用 npm 安装它,也可以从我们的 发布网站。继续阅读以了解有关此版本的详细信息。

¥The Electron team is excited to announce the release of Electron 25.0.0! You can install it with npm via npm install electron@latest or download it from our releases website. Continue reading for details about this release.

如果你有任何反馈,请在 Twitter 上与我们分享,或加入我们的社区 Discord!可以在 Electron 的 问题跟踪器 中报告错误和功能请求。

¥If you have any feedback, please share it with us on Twitter, or join our community Discord! Bugs and feature requests can be reported in Electron's issue tracker.

显著变化

¥Notable Changes

亮点

¥Highlights

  • 在 Electron 的网络模块中实现了 net.fetch,使用了 Chromium 的网络堆栈。这与 Node 的 fetch() 不同,后者使用 Node.js 的 HTTP 堆栈。参见 #36733#36606

    ¥Implemented net.fetch within Electron's net module, using Chromium's networking stack. This differs from Node's fetch(), which uses Node.js' HTTP stack. See #36733 and #36606.

  • 已添加 protocol.handle,用于替换并弃用 protocol.{register,intercept}{String,Buffer,Stream,Http,File}Protocol#36674

    ¥Added protocol.handle, which replaces and deprecates protocol.{register,intercept}{String,Buffer,Stream,Http,File}Protocol. #36674

  • 扩展对 Electron 22 的支持,以配合 Chromium 和微软的 Windows 7/8/8.1 弃用计划。请参阅本博文末尾的更多详细信息。

    ¥Extended support for Electron 22, in order to match Chromium and Microsoft's Windows 7/8/8.1 deprecation plan. See additional details at the end of this blog post.

技术栈变更

¥Stack Changes

重大变化

¥Breaking Changes

已弃用:protocol.{register,intercept}{Buffer,String,Stream,File,Http}Protocol

¥Deprecated: protocol.{register,intercept}{Buffer,String,Stream,File,Http}Protocol

protocol.register*Protocolprotocol.intercept*Protocol 方法已替换为 protocol.handle

¥The protocol.register*Protocol and protocol.intercept*Protocol methods have been replaced with protocol.handle.

新方法可以注册新协议或拦截现有协议,并且响应可以是任何类型。

¥The new method can either register a new protocol or intercept an existing protocol, and responses can be of any type.

// Deprecated in Electron 25
protocol.registerBufferProtocol('some-protocol', () => {
callback({ mimeType: 'text/html', data: Buffer.from('<h5>Response</h5>') });
});

// Replace with
protocol.handle('some-protocol', () => {
return new Response(
Buffer.from('<h5>Response</h5>'), // Could also be a string or ReadableStream.
{ headers: { 'content-type': 'text/html' } },
);
});
// Deprecated in Electron 25
protocol.registerHttpProtocol('some-protocol', () => {
callback({ url: 'https://electron.nodejs.cn' });
});

// Replace with
protocol.handle('some-protocol', () => {
return net.fetch('https://electron.nodejs.cn');
});
// Deprecated in Electron 25
protocol.registerFileProtocol('some-protocol', () => {
callback({ filePath: '/path/to/my/file' });
});

// Replace with
protocol.handle('some-protocol', () => {
return net.fetch('file:///path/to/my/file');
});

已弃用:BrowserWindow.setTrafficLightPosition(position)

¥Deprecated: BrowserWindow.setTrafficLightPosition(position)

BrowserWindow.setTrafficLightPosition(position) 已被弃用,应使用 BrowserWindow.setWindowButtonPosition(position) API,它接受 null 而不是 { x: 0, y: 0 } 将位置重置为系统默认值。

¥BrowserWindow.setTrafficLightPosition(position) has been deprecated, the BrowserWindow.setWindowButtonPosition(position) API should be used instead which accepts null instead of { x: 0, y: 0 } to reset the position to system default.

// Deprecated in Electron 25
win.setTrafficLightPosition({ x: 10, y: 10 });
win.setTrafficLightPosition({ x: 0, y: 0 });

// Replace with
win.setWindowButtonPosition({ x: 10, y: 10 });
win.setWindowButtonPosition(null);

已弃用:BrowserWindow.getTrafficLightPosition()

¥Deprecated: BrowserWindow.getTrafficLightPosition()

BrowserWindow.getTrafficLightPosition() 已被弃用,应使用 BrowserWindow.getWindowButtonPosition() API,当没有自定义位置时,它会返回 null 而不是 { x: 0, y: 0 }

¥BrowserWindow.getTrafficLightPosition() has been deprecated, the BrowserWindow.getWindowButtonPosition() API should be used instead which returns null instead of { x: 0, y: 0 } when there is no custom position.

// Deprecated in Electron 25
const pos = win.getTrafficLightPosition();
if (pos.x === 0 && pos.y === 0) {
// No custom position.
}

// Replace with
const ret = win.getWindowButtonPosition();
if (ret === null) {
// No custom position.
}

新功能

¥New Features

  • 添加了 net.fetch()#36733

    ¥Added net.fetch(). #36733

    • net.fetch 支持对 file: URL 的请求以及在 protocol.register*Protocol 中注册的自定义协议。#36606

      ¥net.fetch supports requests to file: URLs and custom protocols registered with protocol.register*Protocol. #36606

  • 添加了 BrowserWindow.set/getWindowButtonPosition API。#37094

    ¥Added BrowserWindow.set/getWindowButtonPosition APIs. #37094

  • 已添加 protocol.handle,用于替换并弃用 protocol.{register,intercept}{String,Buffer,Stream,Http,File}Protocol#36674

    ¥Added protocol.handle, replacing and deprecating protocol.{register,intercept}{String,Buffer,Stream,Http,File}Protocol. #36674

  • 已将 will-frame-navigate 事件添加到 webContents<webview> 标签,该事件会在框架层次结构中的任何框架尝试导航时触发。#34418

    ¥Added a will-frame-navigate event to webContents and the <webview> tag, which fires whenever any frame within the frame hierarchy attempts to navigate. #34418

  • 在导航器事件中添加了启动器信息。这些信息可以区分 window.open 是来自父框架的导航,还是由子框架发起的导航。#37085

    ¥Added initiator information to navigator events. This information allows distinguishing window.open from a parent frame causing a navigation, as opposed to a child-initiated navigation. #37085

  • 添加了 net.resolveHost,用于使用 defaultSession 对象解析主机。#38152

    ¥Added net.resolveHost that resolves hosts using defaultSession object. #38152

  • app 添加了新的 'did-resign-active' 事件。#38018

    ¥Added new 'did-resign-active' event to app. #38018

  • webContents.print() 添加了几个标准页面大小选项。#37159

    ¥Added several standard page size options to webContents.print(). #37159

  • 在会话处理程序 ses.setDisplayMediaRequestHandler() 回调中添加了 enableLocalEcho 标志,以便在 audioWebFrameMain 时允许远程音频输入在本地输出流中回显。#37315

    ¥Added the enableLocalEcho flag to the session handler ses.setDisplayMediaRequestHandler() callback for allowing remote audio input to be echoed in the local output stream when audio is a WebFrameMain. #37315

  • powerMonitor 中添加了热管理信息。#38028

    ¥Added thermal management information to powerMonitor. #38028

  • 允许将绝对路径传递给 session.fromPath() API。#37604

    ¥Allows an absolute path to be passed to the session.fromPath() API. #37604

  • webContents 上暴露 audio-state-changed 事件。#37366

    ¥Exposes the audio-state-changed event on webContents. #37366

22.x.y 持续支持

¥22.x.y Continued Support

告别 Windows 7/8/8.1 所述,Electron 22(Chromium 108)的计划使用寿命终止日期将从 2023 年 5 月 30 日延长至 2023 年 10 月 10 日。Electron 团队将继续将此计划中的任何安全修复程序反向移植到 Electron 22,直到 2023 年 10 月 10 日。10 月份的支持日期紧随 Chromium 和微软的延长支持日期之后。10 月 11 日,Electron 团队将不再支持最新的三个稳定主要版本,这些版本将不再支持 Windows 7/8/8.1。

¥As noted in Farewell, Windows 7/8/8.1, Electron 22's (Chromium 108) planned end of life date will be extended from May 30, 2023 to October 10, 2023. The Electron team will continue to backport any security fixes that are part of this program to Electron 22 until October 10, 2023. The October support date follows the extended support dates from both Chromium and Microsoft. On October 11, the Electron team will drop support back to the latest three stable major versions, which will no longer support Windows 7/8/8.1.

E25 (2023 年 5 月)E26 (2023 年 8 月)E27 (2023 年 10 月)
25.x.y26.x.y27.x.y
24.x.y25.x.y26.x.y
23.x.y24.x.y25.x.y
22.x.y22.x.y--

下一步计划

¥What's Next

短期内,你可以预期团队将继续专注于跟上构成 Electron 的主要组件(包括 Chromium、Node 和 V8)的开发。

¥In the short term, you can expect the team to continue to focus on keeping up with the development of the major components that make up Electron, including Chromium, Node, and V8.

你可以找到 Electron 公开时间线

¥You can find Electron's public timeline here.

有关未来变更的更多信息,请参阅 计划中的突发事件变更 页面。

¥More information about future changes can be found on the Planned Breaking Changes page.

Electron 24.0.0

· 7 min read

Electron 24.0.0 已发布!它包含对 Chromium 112.0.5615.49、V8 11.2 和 Node.js 18.14.0 的升级。请阅读下文了解更多详情!

¥Electron 24.0.0 has been released! It includes upgrades to Chromium 112.0.5615.49, V8 11.2, and Node.js 18.14.0. Read below for more details!


Electron 团队非常高兴地宣布 Electron 24.0.0 正式发布!你可以通过 npm install electron@latest 使用 npm 安装它,也可以从我们的 发布网站。继续阅读以了解有关此版本的详细信息。

¥The Electron team is excited to announce the release of Electron 24.0.0! You can install it with npm via npm install electron@latest or download it from our releases website. Continue reading for details about this release.

如果你有任何反馈,请在 Twitter 上与我们分享,或加入我们的社区 Discord!可以在 Electron 的 问题跟踪器 中报告错误和功能请求。

¥If you have any feedback, please share it with us on Twitter, or join our community Discord! Bugs and feature requests can be reported in Electron's issue tracker.

显著变化

¥Notable Changes

技术栈变更

¥Stack Changes

重大变化

¥Breaking Changes

API 更改:nativeImage.createThumbnailFromPath(path, size)

¥API Changed: nativeImage.createThumbnailFromPath(path, size)

maxSize 参数已更改为 size,以反映传入的大小将是创建的缩略图的大小。以前,如果图片小于 maxSize,Windows 不会放大图片,而 macOS 总是将大小设置为 maxSize。现在跨平台的行为是相同的。

¥The maxSize parameter has been changed to size to reflect that the size passed in will be the size the thumbnail created. Previously, Windows would not scale the image up if it were smaller than maxSize, and macOS would always set the size to maxSize. Behavior is now the same across platforms.

// a 128x128 image.
const imagePath = path.join('path', 'to', 'capybara.png');

// Scaling up a smaller image.
const upSize = { width: 256, height: 256 };
nativeImage.createThumbnailFromPath(imagePath, upSize).then((result) => {
console.log(result.getSize()); // { width: 256, height: 256 }
});

// Scaling down a larger image.
const downSize = { width: 64, height: 64 };
nativeImage.createThumbnailFromPath(imagePath, downSize).then((result) => {
console.log(result.getSize()); // { width: 64, height: 64 }
});

新功能

¥New Features

  • 添加了使用 cookies.get() 过滤 HttpOnly Cookie 的功能。#37365

    ¥Added the ability to filter HttpOnly cookies with cookies.get(). #37365

  • shell.openExternal() 选项中添加了 logUsage,允许在 Windows 上将 SEE_MASK_FLAG_LOG_USAGE 标志传递给 ShellExecuteExSEE_MASK_FLAG_LOG_USAGE 标志表示用户发起的启动,可跟踪常用程序和其他行为。#37291

    ¥Added logUsage to shell.openExternal() options, which allows passing the SEE_MASK_FLAG_LOG_USAGE flag to ShellExecuteEx on Windows. The SEE_MASK_FLAG_LOG_USAGE flag indicates a user initiated launch that enables tracking of frequently used programs and other behaviors. #37291

  • 已将 types 添加到 webRequest 过滤器,从而能够过滤你监听的请求。#37427

    ¥Added types to the webRequest filter, adding the ability to filter the requests you listen to.#37427

  • webContents 中添加了新的 devtools-open-url 事件,允许开发者使用它们打开新窗口。#36774

    ¥Added a new devtools-open-url event to webContents to allow developers to open new windows with them. #36774

  • webContents.print() 添加了几个标准页面大小选项。#37265

    ¥Added several standard page size options to webContents.print(). #37265

  • 在会话处理程序 ses.setDisplayMediaRequestHandler() 回调中添加了 enableLocalEcho 标志,以便在 audioWebFrameMain 时允许远程音频输入在本地输出流中回显。#37528

    ¥Added the enableLocalEcho flag to the session handler ses.setDisplayMediaRequestHandler() callback for allowing remote audio input to be echoed in the local output stream when audio is a WebFrameMain. #37528

  • 允许将特定于应用的用户名传递给 inAppPurchase.purchaseProduct()#35902

    ¥Allow an application-specific username to be passed to inAppPurchase.purchaseProduct(). #35902

  • 暴露 window.invalidateShadow() 以清除 macOS 上残留的视觉伪影。#32452

    ¥Exposed window.invalidateShadow() to clear residual visual artifacts on macOS. #32452

  • 现在,Electron 节点头配置文件中默认启用了全程序优化,允许编译器使用程序中所有模块的信息进行优化,而不是逐个模块(编译单元)进行优化。#36937

    ¥Whole-program optimization is now enabled by default in electron node headers config file, allowing the compiler to perform opimizations with information from all modules in a program as opposed to a per-module (compiland) basis. #36937

  • SystemPreferences::CanPromptTouchID (macOS) 现在支持 Apple Watch。#36935

    ¥SystemPreferences::CanPromptTouchID (macOS) now supports Apple Watch. #36935

21.x.y 支持终止

¥End of Support for 21.x.y

根据项目的 支持政策,Electron 21.x.y 已达到支持终止日期。建议开发者和应用升级到较新版本的 Electron。

¥Electron 21.x.y has reached end-of-support as per the project's support policy. Developers and applications are encouraged to upgrade to a newer version of Electron.

告别 Windows 7/8/8.1 所述,Electron 22(Chromium 108)的计划使用寿命终止日期将从 2023 年 5 月 30 日延长至 2023 年 10 月 10 日。Electron 团队将继续将此计划中的任何安全修复程序反向移植到 Electron 22,直到 2023 年 10 月 10 日。

¥As noted in Farewell, Windows 7/8/8.1, Electron 22's (Chromium 108) planned end of life date will be extended from May 30, 2023 to October 10, 2023. The Electron team will continue to backport any security fixes that are part of this program to Electron 22 until October 10, 2023.

E24 (2023 年 4 月)E25 (2023 年 5 月)E26 (2023 年 8 月)
24.x.y25.x.y26.x.y
23.x.y24.x.y25.x.y
22.x.y23.x.y24.x.y
--22.x.y22.x.y

下一步计划

¥What's Next

短期内,你可以预期团队将继续专注于跟上构成 Electron 的主要组件(包括 Chromium、Node 和 V8)的开发。

¥In the short term, you can expect the team to continue to focus on keeping up with the development of the major components that make up Electron, including Chromium, Node, and V8.

你可以找到 Electron 公开时间线

¥You can find Electron's public timeline here.

有关未来变更的更多信息,请参阅 计划中的突发事件变更 页面。

¥More information about future changes can be found on the Planned Breaking Changes page.

Electron 十年 🎉

· 25 min read

¥10 Years of Electron 🎉

electron/electron 代码库的首次提交是在 2013 年 3 月 13 日 1

¥The first commit to the electron/electron repository was on March 13, 20131.

Initial commit on electron/electron by @aroben

10 年后,1192 位独立贡献者提交了 27,147 次提交,Electron 已成为当今最受欢迎的桌面应用构建框架之一。这个里程碑是我们庆祝和反思迄今为止的旅程,并分享我们一路走来所学知识的绝佳机会。

¥10 years and 27,147 more commits from 1192 unique contributors later, Electron has become one of the most popular frameworks for building desktop applications today. This milestone is the perfect opportunity to celebrate and reflect on our journey so far, and to share what we’ve learned along the way.

如果没有每一位为项目贡献时间和精力的朋友们,我们就不会有今天的成就。虽然源代码提交始终是最明显的贡献,但我们也必须感谢那些报告错误、维护用户空间模块、提供文档和翻译以及参与网络空间 Electron 社区的人们所付出的努力。作为维护者,每一份贡献对我们而言都弥足珍贵。

¥We would not be here today without everyone who has dedicated their time and effort to contribute to the project. Although source code commits are always the most visible contributions, we also have to acknowledge the effort of folks who report bugs, maintain userland modules, provide documentation and translations, and participate in the Electron community across cyberspace. Every contribution is invaluable to us as maintainers.

**在继续阅读本博文的其余部分之前:谢谢。❤️ **

¥Before we continue with the rest of the blog post: thank you. ❤️

我们是怎么走到这一步的?

¥How did we get here?

Atom Shell 是作为 GitHub Atom 编辑器 的骨干构建的,Atom 编辑器 于 2014 年 4 月发布了公测版。它是从头构建的,作为当时可用的基于 Web 的桌面框架(node-webkit 和 Chromium 嵌入式框架)的替代方案。它有一个杀手级功能:嵌入 Node.js 和 Chromium,为 Web 技术提供强大的桌面运行时。

¥Atom Shell was built as the backbone for GitHub’s Atom editor, which launched in public beta in April 2014. It was built from the ground up as an alternative to the web-based desktop frameworks available at the time (node-webkit and Chromium Embedded Framework). It had a killer feature: embedding Node.js and Chromium to provide a powerful desktop runtime for web technologies.

在一年之内,Atom Shell 的功能和受欢迎程度开始大幅提升。大型公司、初创公司和个人开发者都开始使用它构建应用(一些早期采用者包括 SlackGitKrakenWebTorrent),该项目也因此被恰当地更名为 Electron。

¥Within a year, Atom Shell began seeing immense growth in capabilities and popularity. Large companies, startups, and individual developers alike had started building apps with it (some early adopters include Slack, GitKraken, and WebTorrent), and the project was aptly renamed to Electron.

从那时起,Electron 便一路顺风顺水,从未停歇。以下是我们每周下载量随时间变化的概览,由 npmtrends.com 提供:

¥From then on, Electron hit the ground running and never stopped. Here’s a look at our weekly download count over time, courtesy of npmtrends.com:

Electron weekly downloads graph over time

Electron v1 于 2016 年发布,承诺提高 API 稳定性并提供更完善的文档和工具。Electron v2 于 2018 年发布,并引入了语义版本控制,使 Electron 开发者更容易跟踪发布周期。

¥Electron v1 was released in 2016, promising increased API stability and better docs and tooling. Electron v2 was released in 2018 and introduced semantic versioning, making it easier for Electron developers to keep track of the release cycle.

到 Electron v6 版本,我们改为每 12 周发布一次主要版本,以与 Chromium 保持一致。此决定改变了项目的理念,将“拥有最新的 Chromium 版本”从可有可无变成了优先事项。这减少了升级之间的技术债务,使我们更容易保持 Electron 的更新和安全。

¥By Electron v6, we shifted to a regular 12-week major release cadence to match Chromium’s. This decision was a change in mentality for the project, bringing “having the most up-to-date Chromium version” from a nice-to-have to a priority. This has reduced the amount of tech debt between upgrades, making it easier for us to keep Electron updated and secure.

从那时起,我们一直运转良好,在每个 Chromium 稳定版本发布的同一天发布新的 Electron 版本。到 2021 年 Chromium 将发布计划加快到 4 周时,我们能够轻松地将发布节奏相应提高到 8 周。

¥Since then, we’ve been a well-oiled machine, releasing a new Electron version on the same day as every Chromium stable. By the time Chromium sped up their release schedule to 4 weeks in 2021, we were able to shrug our shoulders and increase our release cadence to 8 weeks accordingly.

我们目前使用 Electron v23(并且仍在继续),并且仍然致力于构建用于构建跨平台桌面应用的最佳运行时。即使近年来 JavaScript 开发工具蓬勃发展,Electron 仍然是桌面应用框架字段中稳定且久经考验的中坚力量。如今,Electron 应用无处不在:你可以使用 Visual Studio Code 编程、使用 Figma 设计、使用 Slack 通信以及使用 Notion 做注意(以及许多其他用例)。我们为这一成就感到无比自豪,并感谢所有为此做出贡献的人。

¥We’re now on Electron v23 (and counting), and are still dedicated to building the best runtime for building cross-platform desktop applications. Even with the boom in JavaScript developer tools in recent years, Electron has remained a stable, battle-tested stalwart of the desktop app framework landscape. Electron apps are ubiquitous nowadays: you can program with Visual Studio Code, design with Figma, communicate with Slack, and take notes with Notion (amongst many other use cases). We’re incredibly proud of this achievement and grateful to everyone who has made it possible.

我们在此过程中学到了什么?

¥What did we learn along the way?

迈向十年之路漫长而曲折。以下是一些帮助我们可持续运营大型开源项目的关键因素。

¥The road to the decade mark has been long and winding. Here are some key things that have helped us run a sustainable large open source project.

使用治理模型扩展分布式决策

¥Scaling distributed decision-making with a governance model

我们必须克服的一个挑战是,在 Electron 首次流行起来后,如何掌控项目的长期发展方向。我们团队由几十位分布在不同公司、国家和时区的工程师组成,该如何处理这种情况?

¥One challenge we had to overcome was handling the long-term direction of the project once Electron first exploded in popularity. How do we handle being a team of a couple dozen engineers distributed across companies, countries, and time zones?

早期,Electron 的维护团队依赖于非正式协调,这种方式对于小型项目来说快速且轻量,但无法扩展到更广泛的协作。2019 年,我们转向了一种治理模式,不同的工作组拥有正式的职责范围。这有助于简化流程并将项目所有权部分分配给特定的维护者。目前每个工作组 (WG) 分别负责什么?

¥In the early days, Electron’s maintainer group relied on informal coordination, which is fast and lightweight for smaller projects, but doesn’t scale to wider collaboration. In 2019, we shifted to a governance model where different working groups have formal areas of responsibility. This has been instrumental in streamlining processes and assigning portions of project ownership to specific maintainers. What is each Working Group (WG) responsible for nowadays?

  • 发布 Electron 版本(发布工作组)

    ¥Getting Electron releases out the door (Releases WG)

  • 升级 Chromium 和 Node.js(升级工作组)

    ¥Upgrading Chromium and Node.js (Upgrades WG)

  • 监督公共 API 设计 (API WG)

    ¥Overseeing public API design (API WG)

  • 保障 Electron 安全(安全工作组)

    ¥Keeping Electron secure (Security WG)

  • 运行网站、文档和工具(生态系统工作组)

    ¥Running the website, documentation, and tooling (Ecosystem WG)

  • 社区和企业拓展(拓展工作组)

    ¥Community and corporate outreach (Outreach WG)

  • 社区审核(社区与安全工作组)

    ¥Community moderation (Community & Safety WG)

  • 维护我们的构建基础设施、维护工具和云服务(基础设施工作组)

    ¥Maintaining our build infrastructure, maintainer tools, and cloud services (Infrastructure WG)

在我们转向治理模式的同时,我们也将 Electron 的所有权从 GitHub OpenJS 基金会 转移。虽然最初的核心团队今天仍在微软工作,但他们只是构成 Electron 治理的更大合作者群体的一部分。2

¥Around the same time we shifted to the governance model, we also moved Electron's ownership from GitHub to the OpenJS Foundation. Although the original core team still works at Microsoft today, they are only a part of a larger group of collaborators that form Electron governance.2

虽然这种模式并不完美,但它在我们应对全球疫情和持续的宏观经济逆风时表现得非常出色。展望未来,我们计划修订治理章程,以指导我们度过 Electron 的第二个十年。

¥While this model isn’t perfect, it has suited us well through a global pandemic and ongoing macroeconomic headwinds. Going forward, we plan on revamping the governance charter to guide us through the second decade of Electron.

信息

如果你想了解更多信息,请查看 electron/governance 代码库!

¥If you want to learn more, check out the electron/governance repository!

社区

¥Community

开源的社区部分很难,尤其是当你的外联团队由十几名穿着风衣、标着“社区经理”的工程师组成时。话虽如此,作为一个大型开源项目,我们拥有大量用户,利用他们的精力为 Electron 构建用户空间生态系统是维持项目健康的关键。

¥The community part of open source is hard, especially when your Outreach team is a dozen engineers in a trench coat that says “community manager”. That said, being a large open source project means that we have a lot of users, and harnessing their energy for Electron to build a userland ecosystem is a crucial part of sustaining project health.

我们做了哪些工作来提升社区影响力?

¥What have we been doing to develop our community presence?

构建虚拟社区

¥Building virtual communities

  • 2020 年,我们推出了社区 Discord 服务器。我们之前在 Atom 论坛中有一个版块,但后来决定创建一个更非正式的交流平台,为维护人员和 Electron 开发者提供一个交流的空间,并提供常规的调试帮助。

    ¥In 2020, we launched our community Discord server. We previously had a section in Atom’s forum, but decided to have a more informal messaging platform to have a space for discussions between maintainers and Electron developers and for general debugging help.

  • 2021 年,我们在 @BlackHole1 的帮助下建立了 Electron 中国 用户组。该小组在 Electron 在中国蓬勃发展的科技字段用户中的增长中发挥了重要作用,为他们提供了一个在英语之外进行创意合作和讨论 Electron 的空间。空格。我们还要感谢 cnpm 在其 npm 中文镜像中支持 Electron 的夜间发布。

    ¥In 2021, we established the Electron China user group with the help of @BlackHole1. This group has been instrumental in Electron growth in users from China’s booming tech scene, providing a space for them to collaborate on ideas and discuss Electron outside of our English-language spaces. We’d also like to thank cnpm for their work in supporting Electron’s nightly releases in their Chinese mirror for npm.

参与高知名度开源项目

¥Participating in high-visibility open source programs

  • 自 2019 年以来,我们每年都会庆祝 Hacktoberfest。Hacktoberfest 是由 DigitalOcean 组织的年度开源庆祝活动,每年都会有数十位热情的贡献者参与其中,希望在开源软件字段留下自己的印记。

    ¥We have been celebrating Hacktoberfest every year since 2019. Hacktoberfest is yearly celebration of open source organized by DigitalOcean, and we get dozens of enthusiastic contributors every year looking to make their mark on open source software.

  • 2020 年,我们参与了 Google Season of Docs 的初始迭代,并与 @bandantonio 合作重新设计了 Electron 的新用户教程流程。

    ¥In 2020, we participated in the initial iteration of Google Season of Docs, where we worked with @bandantonio to rework Electron’s new user tutorial flow.

  • 2022 年,我们首次指导了一位 Google Summer of Code 的学生。@aryanshridhar 做了一些出色的工作,重构了 Electron Fiddle 的核心版本加载逻辑,并将其打包器迁移到 webpack

    ¥In 2022, we mentored a Google Summer of Code student for the first time. @aryanshridhar did some awesome work to refactor Electron Fiddle's core version loading logic and migrate its bundler to webpack.

让一切自动化!

¥Automate all the things!

目前,Electron 治理团队拥有约 30 名活跃维护者。我们中只有不到一半的人是全职贡献者,这意味着还有很多工作要做。我们有什么技巧可以确保一切顺利运行?我们的座右铭是:电脑便宜,人力时间昂贵。秉承工程师一贯的风格,我们开发了一套自动化支持工具,让我们的工作更加轻松。

¥Today, Electron governance has about 30 active maintainers. Less than half of us are full-time contributors, which means that there’s a lot of work to go around. What’s our trick to keeping everything running smoothly? Our motto is that computers are cheap, and human time is expensive. In typical engineer fashion, we’ve developed a suite of automated support tooling to make our lives easier.

非 Goma

¥Not Goma

Electron 的核心代码库是由大量的 C++ 代码组成的,构建时间一直是我们发布错误修复和新功能速度的限制因素。在 2020 年,我们部署了 非 Goma,这是一个为 Google Goma 分布式编译器服务定制的 Electron 专用后端。Not Goma 处理来自授权用户机器的编译请求,并将该过程分布到后端的数百个核心上。它还会缓存编译结果,以便其他编译相同文件的人只需下载预编译的结果。

¥The core Electron codebase is a behemoth of C++ code, and build times have always been a limiting factor in how fast we can ship bug fixes and new features. In 2020, we deployed Not Goma, a custom Electron-specific backend for Google’s Goma distributed compiler service. Not Goma processes compilation requests from authorized user’s machines and distributes the process across hundreds of cores in the backend. It also caches the compilation result so that someone else compiling the same files will only need to download the pre-compiled result.

自 Not Goma 上线以来,维护人员的编译时间已从数小时缩短到数分钟。稳定的网络连接已成为贡献者编译 Electron 的最低要求!

¥Since launching Not Goma, compilation times for maintainers have decreased from the scale of hours to minutes. A stable internet connection became the minimum requirement for contributors to compile Electron!

信息

如果你是开源贡献者,你还可以尝试 Not Goma 的只读缓存,该功能在 Electron 构建工具 中默认启用。

¥If you’re an open source contributor, you can also try Not Goma’s read-only cache, which is available by default with Electron Build Tools.

持续因素身份验证

¥Continuous Factor Authentication

持续因素身份验证 (CFA) 是围绕 npm 双因素身份验证 (2FA) 系统的自动化层,我们将其与 semantic-release 结合使用,以管理各种 @electron/ npm 软件包的安全自动发布。

¥Continuous Factor Authentication (CFA) is a layer of automation around npm’s two-factor authentication (2FA) system that we combine with semantic-release to manage secure and automated releases of our various @electron/ npm packages.

虽然 semantic-release 已经自动化了 npm 包发布流程,但它需要关闭双因素身份验证或传递一个可以绕过此限制的秘密令牌。

¥While semantic-release already automates the npm package publishing process, it requires turning off two-factor authentication or passing in a secret token that bypasses this restriction.

我们构建了 CFA,以便为 npm 2FA 向任意 CI 作业提供基于时间的一次性密码 (TOTP),这使我们能够利用语义发布的自动化功能,同时保留双因素身份验证的额外安全性。

¥We built CFA to deliver a time-based one-time password (TOTP) for npm 2FA to arbitrary CI jobs, allowing us to harness the automation of semantic-release while keeping the additional security of two-factor authentication.

我们使用 CFA 和 Slack 集成前端,允许维护人员在任何装有 Slack 的设备上验证软件包发布,只要他们手边有 TOTP 生成器即可。

¥We use CFA with a Slack integration front-end, allowing maintainers to validate package publishing from any device they have Slack on, as long as they have their TOTP generator handy.

信息

如果你想在自己的项目中尝试 CFA,请查看 GitHub 代码库文档!如果你使用 CircleCI 作为持续集成 (CI) 提供商,我们也有 一个方便的 orb 可以帮助你快速使用 CFA 搭建项目。

¥If you want to try CFA out in your own projects, check out the GitHub repository or the docs! If you use CircleCI as your CI provider, we also have a handy orb to quickly scaffold a project with CFA.

Sheriff

Sheriff 是我们编写的一个开源工具,用于自动化 GitHub、Slack 和 Google Workspace 之间的权限管理。

¥Sheriff is an open source tool we wrote to automate the management of permissions across GitHub, Slack, and Google Workspace.

Sheriff 的核心价值主张是权限管理应该是一个透明的过程。它使用一个 YAML 配置文件来指定所有上述服务的权限。使用 Sheriff,获取代码库的协作者状态或创建新的邮件列表就像获得 PR 批准和合并一样简单。

¥Sheriff’s key value proposition is that permission management should be a transparent process. It uses a single YAML config file that designates permissions across all the above listed services. With Sheriff, getting collaborator status on a repo or creating a new mailing list is as easy as getting a PR approved and merged.

Sheriff 还有一个审计日志,会发布到 Slack,当 Electron 组织内任何地方发生可疑活动时,它会向管理员发出警告。

¥Sheriff also has an audit log that posts to Slack, warning admins when suspicious activity occurs anywhere in the Electron organization.

……以及我们所有的 GitHub 机器人

¥…and all our GitHub bots

GitHub 是一个拥有丰富 API 可扩展性的平台,并拥有一个名为 Probot 的第一方机器人应用框架。为了帮助我们专注于工作中更具创造性的部分,我们构建了一套小型机器人来帮助我们完成繁重的工作。以下是一些示例:

¥GitHub is a platform with rich API extensibility and a first-party bot application framework called Probot. To help us focus on the more creative parts of our job, we built out a suite of smaller bots that help do the dirty work for us. Here are a few examples:

  • Sudowoodo 从头到尾自动化 Electron 发布流程,从启动构建到将发布资源上传到 GitHub 和 npm。

    ¥Sudowoodo automates the Electron release process from start to finish, from kicking off builds to uploading the release assets to GitHub and npm.

  • Trop 通过尝试根据 GitHub PR 标签挑选补丁到之前的版本分支,自动化了 Electron 的反向移植过程。

    ¥Trop automates the backporting process for Electron by attempting to cherry-pick patches to previous release branches based on GitHub PR labels.

  • Roller 自动滚动升级 Electron 的 Chromium 和 Node.js 依赖。

    ¥Roller automates rolling upgrades of Electron’s Chromium and Node.js dependencies.

  • Cation 是我们用于 electron/electron PR 状态检查的机器人。

    ¥Cation is our status check bot for electron/electron PRs.

总而言之,我们的机器人小家族极大地提高了开发者的生产力!

¥Altogether, our little family of bots has given us a huge boost in developer productivity!

下一步是什么?

¥What’s next?

当我们进入项目第二个十年之际,你可能会问:Electron 的下一步计划是什么?

¥As we enter our second decade as a project, you might be asking: what’s next for Electron?

我们将与 Chromium 的发布节奏保持同步,每 8 周发布一次 Electron 的新主要版本,使框架始终使用 Web 平台和 Node.js 的最新和最佳功能进行更新,同时确保企业级应用的稳定性和安全性。

¥We’re going to stay in sync with Chromium's release cadence, releasing new major versions of Electron every 8 weeks, keeping the framework updated with the latest and greatest from the web platform and Node.js while maintaining stability and security for enterprise-grade applications.

我们通常会在即将推出的计划具体化后发布消息。如果你想了解未来的版本发布、功能和常规项目更新,你可以阅读 我们的博客 并关注我们的社交媒体资料(TwitterMastodon)!

¥We generally announce news on upcoming initiatives when they become concrete. If you want to keep up with future releases, features, and general project updates, you can read our blog and follow our social media profiles (Twitter and Mastodon)!

Footnotes

  1. 这实际上是 electron-archive/brightray 项目 的第一次提交,electron-archive/brightray 项目 于 2017 年被并入 Electron,并将其 git 历史记录合并。但谁在乎呢?今天是我们的生日,所以我们来制定规则吧!

    ¥This is actually the first commit from the electron-archive/brightray project, which got absorbed into Electron in 2017 and had its git history merged. But who’s counting? It’s our birthday, so we get to make the rules! 2

  2. 与普遍看法相反,Electron 不再归 GitHub 或 Microsoft 所有,而是现在属于 OpenJS 基金会 的一部分。

    ¥Contrary to popular belief, Electron is no longer owned by GitHub or Microsoft, and is part of the OpenJS Foundation nowadays. 2

Electron 23.0.0

· 6 min read

Electron 23.0.0 已发布!它包含对 Chromium 110、V8 11.0 和 Node.js 18.12.1 的升级。此外,对 Windows 7/8/8.1 的支持已停止。请阅读下文了解更多详情!

¥Electron 23.0.0 has been released! It includes upgrades to Chromium 110, V8 11.0, and Node.js 18.12.1. Additionally, support for Windows 7/8/8.1 has been dropped. Read below for more details!


Electron 团队非常高兴地宣布 Electron 23.0.0 正式发布!你可以通过 npm install electron@latest 使用 npm 安装它,也可以从我们的 发布网站。继续阅读以了解有关此版本的详细信息。

¥The Electron team is excited to announce the release of Electron 23.0.0! You can install it with npm via npm install electron@latest or download it from our releases website. Continue reading for details about this release.

如果你有任何反馈,请在 Twitter 上与我们分享,或加入我们的社区 Discord!可以在 Electron 的 问题跟踪器 中报告错误和功能请求。

¥If you have any feedback, please share it with us on Twitter, or join our community Discord! Bugs and feature requests can be reported in Electron's issue tracker.

显著变化

¥Notable Changes

技术栈变更

¥Stack Changes

新功能

¥New Features

  • Display 对象中添加了 label 属性。#36933

    ¥Added label property to Display objects. #36933

  • 添加了一个 app.getPreferredSystemLanguages() API 来返回用户的系统语言。#36035

    ¥Added an app.getPreferredSystemLanguages() API to return the user's system languages. #36035

  • 添加了对 WebUSB API 的支持。#36289

    ¥Added support for the WebUSB API. #36289

  • 添加了对 SerialPort.forget() 的支持,以及在给定来源被撤销时在 会议 对象上发出的新事件 serial-port-revoked#35310

    ¥Added support for SerialPort.forget() as well as a new event serial-port-revoked emitted on Session objects when a given origin is revoked. #35310

  • 添加了新的 win.setHiddenInMissionControl API,允许开发者在 macOS 上选择退出 Mission Control。#36092

    ¥Added new win.setHiddenInMissionControl API to allow developers to opt out of Mission Control on macOS. #36092

放弃对 Windows 7/8/8.1 的支持

¥Dropping Windows 7/8/8.1 Support

Electron 23 不再支持 Windows 7/8/8.1。Electron 遵循计划中的 Chromium 弃用政策,该政策将于 弃用 Windows 7/8/8.1 以及 Windows Chromium 109 支持 Server 2012 和 2012 R2(点击此处了解更多信息)

¥Electron 23 no longer supports Windows 7/8/8.1. Electron follows the planned Chromium deprecation policy, which will deprecate Windows 7/8/8.1 , as well as Windows Server 2012 and 2012 R2 support in Chromium 109 (read more here).

API 重大变更

¥Breaking API Changes

以下是 Electron 23 中引入的重大变更。你可以在 计划中的突发事件变更 页面上阅读有关这些更改和未来更改的更多信息。

¥Below are breaking changes introduced in Electron 23. You can read more about these changes and future changes on the Planned Breaking Changes page.

删除:BrowserWindow scroll-touch-* 事件

¥Removed: BrowserWindow scroll-touch-* events

BrowserWindow 上已弃用的 scroll-touch-beginscroll-touch-endscroll-touch-edge 事件已被删除。请使用 WebContents 上新推出的 input-event 事件。

¥The deprecated scroll-touch-begin, scroll-touch-end and scroll-touch-edge events on BrowserWindow have been removed. Instead, use the newly available input-event event on WebContents.

// Removed in Electron 23.0
-win.on('scroll-touch-begin', scrollTouchBegin)
-win.on('scroll-touch-edge', scrollTouchEdge)
-win.on('scroll-touch-end', scrollTouchEnd)

// Replace with
+win.webContents.on('input-event', (_, event) => {
+ if (event.type === 'gestureScrollBegin') {
+ scrollTouchBegin()
+ } else if (event.type === 'gestureScrollUpdate') +{
+ scrollTouchEdge()
+ } else if (event.type === 'gestureScrollEnd') {
+ scrollTouchEnd()
+ }
+})

20.x.y 支持终止

¥End of Support for 20.x.y

Electron 20.x.y 已根据项目 支持政策 终止支持。建议开发者和应用升级到较新版本的 Electron。

¥Electron 20.x.y has reached end-of-support as per the project's support policy. Developers and applications are encouraged to upgrade to a newer version of Electron.

E22 (2022 年 11 月)E23 (2023 年 2 月)E24 (2023 年 4 月)E25 (2023 年 5 月)E26 (2023 年 8 月)
22.x.y23.x.y24.x.y25.x.y26.x.y
21.x.y22.x.y23.x.y24.x.y25.x.y
20.x.y21.x.y22.x.y23.x.y24.x.y

下一步计划

¥What's Next

短期内,你可以预期团队将继续专注于跟上构成 Electron 的主要组件(包括 Chromium、Node 和 V8)的开发。

¥In the short term, you can expect the team to continue to focus on keeping up with the development of the major components that make up Electron, including Chromium, Node, and V8.

你可以找到 Electron 公开时间线

¥You can find Electron's public timeline here.

有关未来变更的更多信息,请参阅 计划中的突发事件变更 页面。

¥More information about future changes can be found on the Planned Breaking Changes page.

Electron 22.0.0

· 10 min read

Electron 22.0.0 已发布!它包含一个新的实用程序进程 API、Windows 7/8/8.1 支持更新以及 Chromium 108、V8 10.8 和 Node.js 16.17.1 的升级。请阅读下文了解更多详情!

¥Electron 22.0.0 has been released! It includes a new utility process API, updates for Windows 7/8/8.1 support, and upgrades to Chromium 108, V8 10.8, and Node.js 16.17.1. Read below for more details!


Electron 团队非常高兴地宣布 Electron 22.0.0 正式发布!你可以通过 npm install electron@latest 使用 npm 安装它,也可以从我们的 发布网站。继续阅读以了解有关此版本的详细信息。

¥The Electron team is excited to announce the release of Electron 22.0.0! You can install it with npm via npm install electron@latest or download it from our releases website. Continue reading for details about this release.

如果你有任何反馈,请在 Twitter 上与我们分享,或加入我们的社区 Discord!可以在 Electron 的 问题跟踪器 中报告错误和功能请求。

¥If you have any feedback, please share it with us on Twitter, or join our community Discord! Bugs and feature requests can be reported in Electron's issue tracker.

显著变化

¥Notable Changes

技术栈变更

¥Stack Changes

亮点功能

¥Highlighted Features

UtilityProcess API #36089

新的 UtilityProcess 主进程模块允许创建一个轻量级的 Chromium 子进程,只需集成 Node.js,同时还允许使用 MessageChannel 与沙盒渲染器进行通信。该 API 基于 Node.js child_process.fork 设计,以便于更容易地过渡,主要区别在于入口点 modulePath 必须位于打包的应用内部,这样才能只允许加载受信任的脚本。此外,该模块默认阻止与渲染器建立通信通道,从而维护了主进程是应用中唯一可信进程的约定。

¥The new UtilityProcess main process module allows the creation of a lightweight Chromium child process with only Node.js integration while also allowing communication with a sandboxed renderer using MessageChannel. The API was designed based on Node.js child_process.fork to allow for easier transition, with one primary difference being that the entry point modulePath must be from within the packaged application to allow only for trusted scripts to be loaded. Additionally the module prevents establishing communication channels with renderers by default, upholding the contract in which the main process is the only trusted process in the application.

你可以阅读更多关于 新的 UtilityProcess API 在我们的文档中 的信息。

¥You can read more about the new UtilityProcess API in our docs here.

Windows 7/8/8.1 支持更新

¥Windows 7/8/8.1 Support Update

信息

2023/02/16:Windows Server 2012 支持更新

¥2023/02/16: An update on Windows Server 2012 support

上个月,谷歌宣布 Windows Server 2012 和 Windows Server 2012 R2 的 Chrome 109 将继续接收关键安全修复 将持续到 2023 年 10 月 10 日。因此,Electron 22(Chromium 108)的计划生命周期终止日期将从 2023 年 5 月 30 日延长至 2023 年 10 月 10 日。Electron 团队将继续将此计划中的任何安全修复程序反向移植到 Electron 22,直到 2023 年 10 月 10 日。

¥Last month, Google announced that Chrome 109 would continue to receive critical security fixes for Windows Server 2012 and Windows Server 2012 R2 until October 10, 2023. In accordance, Electron 22's (Chromium 108) planned end of life date will be extended from May 30, 2023 to October 10, 2023. The Electron team will continue to backport any security fixes that are part of this program to Electron 22 until October 10, 2023.

请注意,我们不会为 Windows 7/8/8.1 提供额外的安全修复。此外,正如之前宣布的那样,Electron 23(Chromium 110)将仅在 Windows 10 及更高版本上运行。

¥Note that we will not make additional security fixes for Windows 7/8/8.1. Also, Electron 23 (Chromium 110) will only function on Windows 10 and above as previously announced.

Electron 22 将是支持 Windows 7/8/8.1 的最后一个 Electron 主要版本。Electron 遵循计划中的 Chromium 弃用政策,该政策将于 Chromium 109 弃用 Windows 7/8/8.1 支持(点击此处了解更多信息)

¥Electron 22 will be the last Electron major version to support Windows 7/8/8.1. Electron follows the planned Chromium deprecation policy, which will deprecate Windows 7/8/8.1 support in Chromium 109 (read more here).

Electron 23 及更高主要版本将不支持 Windows 7/8/8.1。

¥Windows 7/8/8.1 will not be supported in Electron 23 and later major releases.

其他高亮的变更

¥Additional Highlighted Changes

  • 添加了对 Linux 和 Windows 上 Web 蓝牙引脚配对的支持。#35416

    ¥Added support for Web Bluetooth pin pairing on Linux and Windows. #35416

  • 添加了 LoadBrowserProcessSpecificV8Snapshot 作为新的保险丝,允许主/浏览器进程从 browser_v8_context_snapshot.bin 的文件加载其 v8 快照。任何其他流程都将使用与当前相同的路径。#35266

    ¥Added LoadBrowserProcessSpecificV8Snapshot as a new fuse that will let the main/browser process load its v8 snapshot from a file at browser_v8_context_snapshot.bin. Any other process will use the same path as is used today. #35266

  • 添加了 WebContents.opener 以访问窗口打开器,并添加了 webContents.fromFrame(frame) 以获取与 WebFrameMain 实例对应的 WebContents。#35140

    ¥Added WebContents.opener to access window opener and webContents.fromFrame(frame) to get the WebContents corresponding to a WebFrameMain instance. #35140

  • 通过新的会话处理程序 ses.setDisplayMediaRequestHandler 添加了对 navigator.mediaDevices.getDisplayMedia 的支持。#30702

    ¥Added support for navigator.mediaDevices.getDisplayMedia via a new session handler, ses.setDisplayMediaRequestHandler. #30702

API 重大变更

¥Breaking API Changes

以下是 Electron 22 中引入的重大变更。你可以在 计划中的突发事件变更 页面上阅读有关这些更改和未来更改的更多信息。

¥Below are breaking changes introduced in Electron 22. You can read more about these changes and future changes on the Planned Breaking Changes page.

已弃用:webContents.incrementCapturerCount(stayHidden, stayAwake)

¥Deprecated: webContents.incrementCapturerCount(stayHidden, stayAwake)

webContents.incrementCapturerCount(stayHidden, stayAwake) 已被弃用。现在,当页面捕获完成时,它由 webContents.capturePage 自动处理。

¥webContents.incrementCapturerCount(stayHidden, stayAwake) has been deprecated. It is now automatically handled by webContents.capturePage when a page capture completes.

const w = new BrowserWindow({ show: false })

- w.webContents.incrementCapturerCount()
- w.capturePage().then(image => {
- console.log(image.toDataURL())
- w.webContents.decrementCapturerCount()
- })

+ w.capturePage().then(image => {
+ console.log(image.toDataURL())
+ })

已弃用:webContents.decrementCapturerCount(stayHidden, stayAwake)

¥Deprecated: webContents.decrementCapturerCount(stayHidden, stayAwake)

webContents.decrementCapturerCount(stayHidden, stayAwake) 已被弃用。现在,当页面捕获完成时,它由 webContents.capturePage 自动处理。

¥webContents.decrementCapturerCount(stayHidden, stayAwake) has been deprecated. It is now automatically handled by webContents.capturePage when a page capture completes.

const w = new BrowserWindow({ show: false })

- w.webContents.incrementCapturerCount()
- w.capturePage().then(image => {
- console.log(image.toDataURL())
- w.webContents.decrementCapturerCount()
- })

+ w.capturePage().then(image => {
+ console.log(image.toDataURL())
+ })

删除:WebContents new-window 事件

¥Removed: WebContents new-window event

WebContents 的 new-window 事件已被删除。已被 webContents.setWindowOpenHandler() 取代。

¥The new-window event of WebContents has been removed. It is replaced by webContents.setWindowOpenHandler().

- webContents.on('new-window', (event) => {
- event.preventDefault()
- })

+ webContents.setWindowOpenHandler((details) => {
+ return { action: 'deny' }
+ })

已弃用:BrowserWindow scroll-touch-* 事件

¥Deprecated: BrowserWindow scroll-touch-* events

BrowserWindow 上的 scroll-touch-beginscroll-touch-endscroll-touch-edge 事件已弃用。相反,请使用 WebContents 上新推出的 input-event 事件

¥The scroll-touch-begin, scroll-touch-end and scroll-touch-edge events on BrowserWindow are deprecated. Instead, use the newly available input-event event on WebContents.

// Deprecated
- win.on('scroll-touch-begin', scrollTouchBegin)
- win.on('scroll-touch-edge', scrollTouchEdge)
- win.on('scroll-touch-end', scrollTouchEnd)

// Replace with
+ win.webContents.on('input-event', (_, event) => {
+ if (event.type === 'gestureScrollBegin') {
+ scrollTouchBegin()
+ } else if (event.type === 'gestureScrollUpdate') {
+ scrollTouchEdge()
+ } else if (event.type === 'gestureScrollEnd') {
+ scrollTouchEnd()
+ }
+ })

19.x.y 支持终止

¥End of Support for 19.x.y

Electron 19.x.y 已根据项目 支持政策 终止支持。建议开发者和应用升级到较新版本的 Electron。

¥Electron 19.x.y has reached end-of-support as per the project's support policy. Developers and applications are encouraged to upgrade to a newer version of Electron.

E19 (2022 年 5 月)E20 (2022 年 8 月)E21 (2022 年 9 月)E22 (2022 年 11 月)E23 (2023 年 1 月)
19.x.y20.x.y21.x.y22.x.y23.x.y
18.x.y19.x.y20.x.y21.x.y22.x.y
17.x.y18.x.y19.x.y20.x.y21.x.y

下一步计划

¥What's Next

Electron 项目将在 2022 年 12 月暂停,然后在 2023 年 1 月恢复全速运行。更多信息请参阅 十二月关闭博客文章

¥The Electron project will pause for the the month of December 2022, and return in January 2023. More information can be found in the December shutdown blog post.

短期内,你可以预期团队将继续专注于跟上构成 Electron 的主要组件(包括 Chromium、Node 和 V8)的开发。

¥In the short term, you can expect the team to continue to focus on keeping up with the development of the major components that make up Electron, including Chromium, Node, and V8.

你可以找到 Electron 公开时间线

¥You can find Electron's public timeline here.

有关未来变更的更多信息,请参阅 计划中的突发事件变更 页面。

¥More information about future changes can be found on the Planned Breaking Changes page.

告别 Windows 7/8/8.1

· 7 min read

Electron 将从 Electron 23 开始停止对 Windows 7、Windows 8 和 Windows 8.1 的支持。

¥Electron will end support of Windows 7, Windows 8 and Windows 8.1 beginning in Electron 23.


符合 Chromium 的弃用政策,Electron 将从 Electron 23 开始终止对 Windows 7、Windows 8 和 Windows 8.1 的支持。这与微软将于 2023 年 1 月 10 日终止对 Windows 7 ESUWindows 8.1 扩展 的支持相吻合。

¥In line with Chromium’s deprecation policy, Electron will end support of Windows 7, Windows 8 and Windows 8.1 beginning in Electron 23. This matches Microsoft's end of support for Windows 7 ESU and Windows 8.1 extended on January 10th, 2023.

Electron 22 将是支持 Windows 10 以上版本的最后一个 Electron 主要版本。Electron 23 及更高主要版本将不支持 Windows 7/8/8.1。旧版本的 Electron 将继续在 Windows 7 上运行,我们将继续为 Electron 22.x 系列发布补丁,直到 2023 年 5 月 30 日 Electron 将终止对 22.x 的支持(根据我们的 支持时间表)。

¥Electron 22 will be the last Electron major version to support Windows versions older than 10. Windows 7/8/8.1 will not be supported in Electron 23 and later major releases. Older versions of Electron will continue to function on Windows 7, and we will continue to release patches for Electron the 22.x series until May 30 2023, when Electron will end support for 22.x (according to our support timeline).

为什么要弃用?

¥Why deprecate?

Electron 遵循计划中的 Chromium 弃用政策,该政策将在 Chromium 109(点击此处了解更多关于 Chromium 时间线的信息)中弃用支持。Electron 23 将包含 Chromium 110,它将不再支持旧版本的 Windows。

¥Electron follows the planned Chromium deprecation policy, which will deprecate support in Chromium 109 (read more about Chromium's timeline here). Electron 23 will contain Chromium 110, which won’t support older versions of Windows.

因此,包含 Chromium 108 的 Electron 22 将成为最后一个受支持的版本。

¥Electron 22, which contains Chromium 108, will thus be the last supported version.

弃用时间表

¥Deprecation timeline

以下是我们计划的弃用时间表:

¥The following is our planned deprecation timeline:

  • 2022 年 12 月:Electron 团队即将进入假期静默期

    ¥December 2022: The Electron team is entering a quiet period for the holidays

  • 2023 年 1 月:所有受支持的版本分支均接受与 Windows 7 和 8 相关的问题。

    ¥January 2023: Windows 7 & 8 related issues are accepted for all supported release branches.

  • 2023 年 2 月 7 日:Electron 23 已发布。

    ¥February 7 2023: Electron 23 is released.

  • 2023 年 2 月 8 日 - 2023 年 5 月 29 日:Electron 将继续接受对 Electron 23 之前版本支持的修复。

    ¥February 8 2023 - May 29 2023: Electron will continue to accept fixes for supported lines older than Electron 23.

  • 2023 年 5 月 30 日:Electron 22 已达到其支持周期的结束日期。

    ¥May 30 2023: Electron 22 reaches the end of its support cycle.

这对开发者意味着什么:

¥What this means for developers:

  • Electron 团队将接受与 Windows 7/8/8.1 相关的问题和修复,以支持稳定的产品线,直到每个产品线达到其支持周期的结束。

    ¥The Electron team will accept issues and fixes related to Windows 7/8/8.1 for stable supported lines, until each line reaches the end of its support cycle.

    • 这特别适用于 Electron 22、Electron 21 和 Electron 20。

      ¥This specifically applies to Electron 22, Electron 21 and Electron 20.

  • 对于 Electron 23 之前的 Electron 版本,将接受与 Windows 7/8/8.1 相关的新问题。

    ¥New issues related to Windows 7/8/8.1 will be accepted for Electron versions older than Electron 23.

    • 任何较新的发行版将不再接受新问题。

      ¥New issues will not be accepted for any newer release lines.

  • 一旦 Electron 22 达到其支持周期的结束,所有与 Windows 7/8/8.1 相关的现有问题都将被关闭。

    ¥Once Electron 22 has reached the end of its support cycle, all existing issues related to Windows 7/8/8.1 will be closed.

信息

2023/02/16:Windows Server 2012 支持更新

¥2023/02/16: An update on Windows Server 2012 support

上个月,谷歌宣布 Windows Server 2012 和 Windows Server 2012 R2 的 Chrome 109 将继续接收关键安全修复 将持续到 2023 年 10 月 10 日。因此,Electron 22(Chromium 108)的计划生命周期终止日期将从 2023 年 5 月 30 日延长至 2023 年 10 月 10 日。Electron 团队将继续将此计划中的任何安全修复程序反向移植到 Electron 22,直到 2023 年 10 月 10 日。

¥Last month, Google announced that Chrome 109 would continue to receive critical security fixes for Windows Server 2012 and Windows Server 2012 R2 until October 10, 2023. In accordance, Electron 22's (Chromium 108) planned end of life date will be extended from May 30, 2023 to October 10, 2023. The Electron team will continue to backport any security fixes that are part of this program to Electron 22 until October 10, 2023.

请注意,我们不会为 Windows 7/8/8.1 提供额外的安全修复。此外,正如之前宣布的那样,Electron 23(Chromium 110)将仅在 Windows 10 及更高版本上运行。

¥Note that we will not make additional security fixes for Windows 7/8/8.1. Also, Electron 23 (Chromium 110) will only function on Windows 10 and above as previously announced.

下一步是什么

¥What's next

如果你有任何问题或疑虑,请随时写信至 info@electronjs.org。你还可以在我们的官方 Electron Discord 中找到社区支持。

¥Please feel free to write to us at info@electronjs.org if you have any questions or concerns. You can also find community support in our official Electron Discord.

寂静之地 第二部分 (2022 年 12 月)

· 3 min read

Electron 项目将在 2022 年 12 月暂停,然后在 2023 年 1 月恢复全速运行。

¥The Electron project will pause for the month of December 2022, then return to full speed in January 2023.

via GIPHY


12 月会有什么相同之处?

¥What will be the same in December

  1. 零日漏洞和其他主要安全相关版本将根据需要发布。安全事件应通过 SECURITY.md 报告。

    ¥Zero-day and other major security-related releases will be published as necessary. Security incidents should be reported via SECURITY.md.

  2. 行为准则 的报告和审核将继续进行。

    ¥Code of Conduct reports and moderation will continue.

12 月会有什么不同?

¥What will be different in December

  1. 12 月未发布新的稳定版。12 月最后两周未发布 Nightly 和 Alpha 版本。

    ¥No new Stable releases in December. No Nightly and Alpha releases for the last two weeks of December.

  2. 除了少数例外,无需进行拉取请求审核或合并。

    ¥With few exceptions, no pull request reviews or merges.

  3. 任何代码库均未更新问题跟踪器。

    ¥No issue tracker updates on any repositories.

  4. 维护人员未提供 Discord 调试帮助。

    ¥No Discord debugging help from maintainers.

  5. 无需更新社交媒体内容。

    ¥No social media content updates.

为什么会发生这种情况?

¥Why is this happening?

随着 2021 年 12 月“静默月”的成功举办,我们希望在 2022 年将其恢复。对于大多数公司来说,十二月仍然是一个平静的月份,因此我们希望给我们的维护人员一个机会充电。大家都期待 2023 年,我们期待美好的事情发生!我们鼓励其他项目考虑采取类似措施。

¥With the success of December Quiet Month 2021, we wanted to bring it back for 2022. December continues to be a quiet month for most companies, so we want to give our maintainers a chance to recharge. Everyone is looking forward to 2023, and we expect good things to come! We encourage other projects to consider similar measures.

Electron Forge 6 介绍

· 13 min read

我们很高兴地宣布,Electron Forge v6.0.0 现已发布!此版本标志着 Forge 自 2018 年以来的首个主要版本发布,并将项目从 electron-userland 迁移到 Github 上的 electron 主组织。

¥We are excited to announce that Electron Forge v6.0.0 is now available! This release marks the first major release of Forge since 2018 and moves the project from electron-userland into the main electron organization on Github.

继续阅读,了解最新动态以及你的应用如何应用 Electron Forge!

¥Keep on reading to see what's new and how your app can adopt Electron Forge!

什么是 Electron Forge?

¥What is Electron Forge?

Electron Forge 是一款用于打包和分发 Electron 应用的工具。它将 Electron 的构建工具生态系统统一到一个可扩展的界面中,以便任何人都可以直接开始制作 Electron 应用。

¥Electron Forge is a tool for packaging and distributing Electron applications. It unifies Electron's build tooling ecosystem into a single extensible interface so that anyone can jump right into making Electron apps.

亮点功能包括:

¥Highlight features include:

  • 📦 应用打包和代码签名

    ¥📦 Application packaging and code signing

  • 🚚 可在 Windows、macOS 和 Linux 上自定义的安装程序(DMG、deb、MSI、PKG、AppX 等)

    ¥🚚 Customizable installers on Windows, macOS, and Linux (DMG, deb, MSI, PKG, AppX, etc.)

  • ☁️ 云提供商(GitHub、S3、Bitbucket 等)的自动化发布流程

    ¥☁️ Automated publishing flow for cloud providers (GitHub, S3, Bitbucket, etc.)

  • ⚡ 易于使用的 webpack 和 TypeScript 样板模板

    ¥⚡️ Easy-to-use boilerplate templates for webpack and TypeScript

  • ⚙️ 原生 Node.js 模块支持

    ¥⚙️ Native Node.js module support

  • 🔌 可扩展的 JavaScript 插件 API

    ¥🔌 Extensible JavaScript plugin API

进一步阅读

访问 为何选择 Electron Forge 解释文档,了解更多关于 Forge 的理念和架构。

¥Visit the Why Electron Forge explainer document to learn more about Forge's philosophy and architecture.

v6 有什么新功能?

¥What's new in v6?

完全重写

¥Completely rewritten

从 v1 到 v5,Electron Forge 一直基于现已停止的 electron-compile 项目。Forge 6 是对该项目的完全重写,采用了新的模块化架构,可以进行扩展以满足任何 Electron 应用的需求。

¥From v1 to v5, Electron Forge was based on the now-discontinued electron-compile project. Forge 6 is a complete rewrite of the project with a new modular architecture that can be extended to meet any Electron application's needs.

在过去的几年里,Forge v6.0.0-beta 的功能已与 v5 保持一致,代码更新速度也显著降低,使该工具已准备好被广泛采用。

¥In the past few years, Forge v6.0.0-beta has achieved feature parity with v5 and code churn has slowed down dramatically, making the tool ready for general adoption.

不要安装错误的软件包

对于 Electron Forge 5 及以下版本,已发布到 npm 上的 electron-forge 软件包中。从 v6 重写版本开始,Forge 的结构将改为一个包含许多较小项目的 monorepo 项目。

¥For versions 5 and below, Electron Forge was published to the electron-forge package on npm. Starting with the v6 rewrite, Forge is instead structured as a monorepo project with many smaller projects.

官方支持

¥Officially supported

从历史上看,Electron 维护者对构建工具一直持开放态度,将这项任务留给了各种社区软件包。然而,随着 Electron 项目的日趋成熟,新的 Electron 开发者越来越难以理解构建和分发应用所需的工具。

¥Historically, Electron maintainers have been unopinionated about build tooling, leaving the task to various community packages. However, with Electron maturing as a project, it has become harder for new Electron developers to understand which tools they need to build and distribute their apps.

为了指导 Electron 开发者完成分发流程,我们决定将 Forge 作为 Electron 的官方完整构建流程。

¥To help guide Electron developers in the distribution process, we have have decided to make Forge the official batteries-included build pipeline for Electron.

在过去的一年里,我们一直在慢慢地将 Forge 集成到 Electron 官方文档中,最近我们已将 Forge 从 electron-userland/electron-forge 的旧仓库迁移到 electron/forge 仓库。现在,我们终于准备好向公众发布 Electron Forge 了!

¥Over the past year, we have been slowly integrating Forge into the official Electron documentation, and we have recently moved Forge over from its old home in electron-userland/electron-forge to the electron/forge repo. Now, we are finally ready to release Electron Forge to a general audience!

入门

¥Getting started

初始化新的 Forge 项目

¥Initializing a new Forge project

可以使用 create-electron-app CLI 脚本搭建新的 Electron Forge 项目。

¥Scaffolding a new Electron Forge project can be done using the create-electron-app CLI script.

yarn create electron-app my-app --template=webpack
cd my-app
yarn start

该脚本将在 my-app 文件夹中创建一个 Electron 项目,其中包含完整的 JavaScript 打包和预配置的构建管道。

¥The script will create an Electron project in the my-app folder with completely JavaScript bundling and a preconfigured build pipeline.

更多信息,请参阅 Forge 文档中的 入门 指南。

¥For more info, see the Getting Started guide in the Forge docs.

一流的 Webpack 支持

以上代码片段使用了 Forge 的 Webpack 模板,我们推荐将其作为新 Electron 项目的起点。此模板基于 @electron-forge/plugin-webpack 插件构建,该插件通过几种方式将 webpack 与 Electron Forge 集成,包括:

¥The above snippet uses Forge's Webpack Template, which we recommend as a starting point for new Electron projects. This template is built around the @electron-forge/plugin-webpack plugin, which integrates webpack with Electron Forge in a few ways, including:

  • 使用 webpack-dev-server 增强本地开发流程,包括在渲染器中支持 HMR;

    ¥enhancing local dev flow with webpack-dev-server, including support for HMR in the renderer;

  • 在应用打包之前处理 webpack 包的构建逻辑;and

    ¥handling build logic for webpack bundles before application packaging; and

  • 在 Webpack 打包过程中添加对原生 Node 模块的支持。

    ¥adding support for Native Node modules in the webpack bundling process.

如果你需要 TypeScript 支持,请考虑使用 Webpack + TypeScript 模板

¥If you need TypeScript support, consider using the Webpack + TypeScript Template instead.

导入现有项目

¥Importing an existing project

Electron Forge CLI 还包含用于导入现有 Electron 项目的命令。

¥The Electron Forge CLI also contains an import command for existing Electron projects.

cd my-app
yarn add --dev @electron-forge/cli
yarn electron-forge import

当你使用 import 命令时,Electron Forge 会添加一些核心依赖并创建一个新的 forge.config.js 配置。如果你有任何现有的构建工具(例如 Electron Packager、Electron Builder 或 Forge 5),它将尝试迁移尽可能多的设置。你的某些现有配置可能需要手动迁移。

¥When you use the import command, Electron Forge will add a few core dependencies and create a new forge.config.js configuration. If you have any existing build tooling (e.g. Electron Packager, Electron Builder, or Forge 5), it will try to migrate as many settings as possible. Some of your existing configuration may need to be migrated manually.

手动迁移的详细信息可以在 Forge 导入文档 中找到。如果你需要帮助,请访问 我们的 Discord 服务器

¥Manual migration details can be found in the Forge import documentation. If you need help, please stop by our Discord server!

为什么要切换到 Forge?

¥Why switch to Forge?

如果你已经拥有用于打包和发布 Electron 应用的工具,那么采用 Electron Forge 带来的好处仍然可以超过最初的切换成本。

¥If you already have tooling for packaging and publishing your Electron app, the benefits associated with adopting Electron Forge can still outweigh the initial switching cost.

我们认为使用 Forge 有两个主要好处:

¥We believe there are two main benefits to using Forge:

  1. Forge 会在 Electron 支持新功能后立即提供应用构建功能。这样,你无需自行添加新的工具支持,也无需等待其他软件包最终实现该支持后再进行升级。有关最新示例,请参阅 macOS 通用二进制文件ASAR 完整性检查

    ¥Forge receives new features for application building as soon as they are supported in Electron. In this case, you won't need to wire in new tooling support yourself, or wait for that support to be eventually implemented by other packages before upgrading. For recent examples, see macOS universal binaries and ASAR integrity checking.

  2. Forge 的多包架构使其易于理解和扩展。由于 Forge 由许多职责明确的小型软件包组成,因此更容易遵循代码流程。此外,Forge 的可扩展 API 设计意味着你可以编写自己的额外构建逻辑,而无需使用提供的配置选项来处理高级用例。有关编写自定义 Forge 插件、创建器和发布器的更多详细信息,请参阅文档的 扩展 Electron Forge 部分。

    ¥Forge's multi-package architecture makes it easy to understand and extend. Since Forge is made up of many smaller packages with clear responsibilities, it is easier to follow code flow. In addition, Forge's extensible API design means that you can write your own additional build logic separate from the provided configuration options for advanced use cases. For more details on writing custom Forge plugins, makers, and publishers, see the Extending Electron Forge section of the docs.

重大变更

¥Breaking changes

Forge 6 已在 Beta 阶段进行了很长时间的测试,其发布节奏也逐渐放缓。但是,我们在 2022 年下半年加快了开发速度,并利用最近的几个版本在 v6.0.0 稳定版本发布之前推动了一些最后的重大更改。

¥Forge 6 has spent a long time in the beta phase, and its release cadence has gradually slowed down. However, we have accelerated development in the second half of 2022 and used the last few releases to push some final breaking changes before the v6.0.0 stable release.

如果你是 Electron Forge 6 测试版用户,请参阅 v6.0.0 GitHub 发行说明 表格,查看近期测试版(>=6.0.0-beta.65)中的重大更改列表。

¥If you are an Electron Forge 6 beta user, see the v6.0.0 GitHub release notes for a list of breaking changes made in recent betas (>=6.0.0-beta.65).

完整的更改和提交列表可在代码库的 CHANGELOG.md 中找到。

¥A complete list of changes and commits can be found in the repo's CHANGELOG.md.

提交你的反馈!

¥Submit your feedback!

告诉我们你的需求!Electron Forge 团队始终致力于构建更适合用户的项目。

¥Tell us what you need! The Electron Forge team is always looking to build the project to better suit its users.

你可以通过提交功能请求、发布 issues 或仅仅告诉我们你的反馈来帮助我们改进 Electron Forge!你还可以加入我们的 官方 Electron Discord 服务器,那里有一个专门的 Electron Forge 讨论通道。

¥You can help us improve Electron Forge by submitting feature requests, posting issues, or just letting us know your feedback! You can also join us in the official Electron Discord server, where there is a dedicated channel for Electron Forge discussion.

如果你想在 https://electronforge.io 上对 Forge 文档提供任何反馈,我们有一个已同步到 electron-forge/electron-forge-docs 代码库的 GitBook 实例。

¥If you want to give any feedback on the Forge docs at https://electronforge.io, we have a GitBook instance synced to the electron-forge/electron-forge-docs repo.