跳到主要内容

Electron 25.0.0

·5 分钟阅读

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


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

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

值得关注的变更

亮点

  • 在 Electron 的 net 模块中实现了 net.fetch,使用 Chromium 的网络堆栈。这与 Node 的 fetch() 不同,后者使用 Node.js 的 HTTP 堆栈。请参阅 #36733#36606
  • 添加了 protocol.handle,它替换并弃用了 protocol.{register,intercept}{String,Buffer,Stream,Http,File}Protocol#36674
  • 扩展了对 Electron 22 的支持,以匹配 Chromium 和 Microsoft 的 Windows 7/8/8.1 弃用计划。请参阅此博客文章末尾的更多详细信息。

堆栈变更

破坏性变更

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

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

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

// 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.js.cn' });
});

// Replace with
protocol.handle('some-protocol', () => {
return net.fetch('https://electron.js.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)

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

// 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()

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

// 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.
}

新特性

  • 添加了 net.fetch()#36733
    • net.fetch 支持对 file: URL 和使用 protocol.register*Protocol 注册的自定义协议的请求。 #36606
  • 添加了 BrowserWindow.set/getWindowButtonPosition API。 #37094
  • 添加了 protocol.handle,替换并弃用了 protocol.{register,intercept}{String,Buffer,Stream,Http,File}Protocol#36674
  • webContents<webview> 标签添加了 will-frame-navigate 事件,每当帧层次结构中的任何帧尝试导航时,都会触发该事件。 #34418
  • 为导航器事件添加了发起者信息。此信息允许区分 window.open 和父框架引起的导航,以及子框架发起的导航。 #37085
  • 添加了 net.resolveHost,它使用 defaultSession 对象解析主机。 #38152
  • app 添加了新的 'did-resign-active' 事件。 #38018
  • webContents.print() 添加了几个标准页面尺寸选项。 #37159
  • 为会话处理程序 ses.setDisplayMediaRequestHandler() 回调添加了 enableLocalEcho 标志,以便在 audioWebFrameMain 时允许在本地输出流中回显远程音频输入。 #37315
  • powerMonitor 添加了散热管理信息。 #38028
  • 允许将绝对路径传递给 session.fromPath() API。 #37604
  • webContents 上公开了 audio-state-changed 事件。 #37366

22.x.y 继续支持

正如 告别 Windows 7/8/8.1 中所述,Electron 22(Chromium 108)计划的生命周期结束日期将从 2023 年 5 月 30 日延长至 2023 年 10 月 10 日。Electron 团队将继续将此计划中的任何安全修复程序反向移植到 Electron 22,直到 2023 年 10 月 10 日。10 月的支持日期遵循 Chromium 和 Microsoft 的扩展支持日期。10 月 11 日,Electron 团队将放弃对最新三个稳定主要版本的支持,这些版本将不再支持 Windows 7/8/8.1。

E25 (23 年 5 月)E26 (23 年 8 月)E27 (23 年 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--

接下来是什么

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

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

有关未来更改的更多信息,请访问计划的破坏性变更页面。