跳到主要内容

Electron 29.0.0

·阅读时长 4 分钟

Electron 29.0.0 已发布!它包含了对 Chromium 122.0.6261.39、V8 12.2 和 Node.js 20.9.0 的升级。


Electron 团队很高兴地宣布 Electron 29.0.0 发布了!您可以通过 npm 使用 npm install electron@latest 安装,或者从我们的版本网站下载。请继续阅读以获取有关此版本的详细信息。

如果您有任何反馈,请通过 TwitterMastodon 与我们分享,或者加入我们的社区 Discord!Bug 和功能请求可以在 Electron 的问题跟踪器中报告。

值得注意的变更

亮点

  • 新增了顶级模块 webUtils,这是一个渲染器进程模块,提供了一个工具层用于与 Web API 对象交互。该模块中的第一个可用 API 是 webUtils.getPathForFile。Electron 之前对 File.path 的增强偏离了 Web 标准;这个新 API 更符合当前的 Web 标准行为。

技术栈变更

Electron 29 将 Chromium 从 120.0.6099.56 升级到 122.0.6261.39,Node 从 18.18.2 升级到 20.9.0,V8 从 12.0 升级到 12.2

新特性

  • 新增了 webUtils 模块,这是一个用于与 Web API 对象交互的工具层,取代了 File.path 增强功能。#38776
  • net 模块添加到了工具进程中。#40890
  • 新增了一个新的 Electron FusegrantFileProtocolExtraPrivileges,使 file:// 协议具有更安全和限制性的行为,与 Chromium 相匹配。#40372
  • protocol.registerSchemesAsPrivileged 中新增了一个选项,允许在自定义 Scheme 中使用 V8 代码缓存。#40544
  • 在 macOS 13.0+ 上,将 app.{set|get}LoginItemSettings(settings) 迁移为使用 Apple 新推荐的底层框架。#37244

重大变更

行为变更:ipcRenderer 不再能通过 contextBridge 发送

尝试通过 contextBridge 将整个 ipcRenderer 模块作为对象发送,现在将在桥的接收端得到一个空对象。此更改是为了移除/减轻一个安全隐患。您不应该直接将 ipcRenderer 或其方法暴露在桥上。相反,应提供一个安全的包装器,如下所示

contextBridge.exposeInMainWorld('app', {
onEvent: (cb) => ipcRenderer.on('foo', (e, ...args) => cb(args)),
});

已移除:app 上的 renderer-process-crashed 事件

app 上的 renderer-process-crashed 事件已被移除。请改用新的 render-process-gone 事件。

// Removed
app.on('renderer-process-crashed', (event, webContents, killed) => {
/* ... */
});

// Replace with
app.on('render-process-gone', (event, webContents, details) => {
/* ... */
});

已移除:WebContents<webview> 上的 crashed 事件

WebContents<webview> 上的 crashed 事件已被移除。请改用新的 render-process-gone 事件。

// Removed
win.webContents.on('crashed', (event, killed) => {
/* ... */
});
webview.addEventListener('crashed', (event) => {
/* ... */
});

// Replace with
win.webContents.on('render-process-gone', (event, details) => {
/* ... */
});
webview.addEventListener('render-process-gone', (event) => {
/* ... */
});

已移除:app 上的 gpu-process-crashed 事件

app 上的 gpu-process-crashed 事件已被移除。请改用新的 child-process-gone 事件。

// Removed
app.on('gpu-process-crashed', (event, killed) => {
/* ... */
});

// Replace with
app.on('child-process-gone', (event, details) => {
/* ... */
});

26.x.y 版本停止支持

根据项目的支持政策,Electron 26.x.y 已达到停止支持期限。鼓励开发者和应用程序升级到更新版本的 Electron。

E29 (24 年 2 月)E30 (24 年 4 月)E31 (24 年 6 月)
29.x.y30.x.y31.x.y
28.x.y29.x.y30.x.y
27.x.y28.x.y29.x.y

后续计划

您知道 Electron 最近新增了社区征求意见稿 (RFC) 流程吗?如果您想为框架添加新功能,RFC 是一个与维护者就其设计展开对话的有用工具。您还可以在 Pull Request 中看到正在讨论的即将进行的变更。要了解更多信息,请查看我们的引入 electron/rfcs 博客文章,或直接查看 electron/rfcs 仓库的 README。

短期内,您可以期待团队继续专注于跟进构成 Electron 的主要组件的开发,包括 Chromium、Node 和 V8。

您可以在此处查看 Electron 的公共时间线

您可以在计划中的重大变更页面找到有关未来变更的更多信息。