跳转到主要内容

Electron 28.0.0

·阅读时长 4 分钟

Electron 28.0.0 已发布! 此版本升级了 Chromium 120.0.6099.56、V8 12.0 和 Node.js 18.18.2


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

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

值得注意的变化

  • 实现了对 ECMAScript 模块或 ESM 的支持(什么是 ECMAScript 模块? 在此处了解更多)。这包括对 Electron 本身的 ESM 支持,以及诸如 UtilityProcess API 入口点等领域。 请参阅我们的 ESM 文档 以获取更多详细信息。
  • 除了在 Electron 本身中启用 ESM 支持外,Electron Forge 也支持使用 ESM 来打包、构建和开发 Electron 应用程序。您可以在 Forge v7.0.0 或更高版本中找到此支持。

堆栈变化

新特性

  • 启用了 ESM 支持。 #37535
    • 有关更多详细信息,请参阅 ESM 文档
  • 将 ESM 入口点添加到 UtilityProcess API。 #40047
  • display 对象添加了几个属性,包括 detectedmaximumCursorSizenativeOrigin#40554
  • 在 Linux 上添加了 ELECTRON_OZONE_PLATFORM_HINT 环境变量的支持。 #39792

破坏性变更

行为变更:将 WebContents.backgroundThrottling 设置为 false 会影响宿主 BrowserWindow 中的所有 WebContents

WebContents.backgroundThrottling 设置为 false 将禁用 BrowserWindow 中所有由它显示的 WebContents 的帧节流。

已移除:BrowserWindow.setTrafficLightPosition(position)

已移除 BrowserWindow.setTrafficLightPosition(position),应改用 BrowserWindow.setWindowButtonPosition(position) API,该 API 接受 null 而不是 { x: 0, y: 0 } 来将位置重置为系统默认值。

// Removed in Electron 28
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()

已移除 BrowserWindow.getTrafficLightPosition(),应改用 BrowserWindow.getWindowButtonPosition() API,当没有自定义位置时,该 API 返回 null 而不是 { x: 0, y: 0 }

// Removed in Electron 28
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.
}

已移除:ipcRenderer.sendTo()

ipcRenderer.sendTo() API 已被移除。应将其替换为在两个渲染器之间设置 MessageChannel

IpcRendererEventsenderIdsenderIsMainFrame 属性也已被移除。

已移除:app.runningUnderRosettaTranslation

app.runningUnderRosettaTranslation 属性已被移除。 请改用 app.runningUnderARM64Translation

// Removed
console.log(app.runningUnderRosettaTranslation);
// Replace with
console.log(app.runningUnderARM64Translation);

25.x.y 版本停止支持

根据项目的 支持策略,Electron 25.x.y 版本已停止支持。鼓励开发者和应用程序升级到较新版本的 Electron。

E28 (23年12月)E29 (24年2月)E30 (24年4月)
28.x.y29.x.y30.x.y
27.x.y28.x.y29.x.y
26.x.y27.x.y28.x.y

接下来是什么

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

您可以在 此处 找到 Electron 的公共时间线。

有关未来变更的更多信息,请参见 计划中的破坏性变更 页面。