Electron 25.0.0
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! Bug 和功能请求可以在 Electron 的问题追踪器中报告。
重要变更
亮点
- 在 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 和微软的 Windows 7/8/8.1 弃用计划。更多详情请参阅此博客文章末尾。
技术栈变更
- Chromium
114
- Node.js
18.15.0
- V8
11.4
破坏性变更
已废弃:protocol.{register,intercept}{Buffer,String,Stream,File,Http}Protocol
protocol.register*Protocol
和 protocol.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,该 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,该 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()
。#36733net.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 - 为 navigator 事件添加了发起者信息。此信息允许区分由父帧引起的
window.open
导航与由子帧发起的导航。#37085 - 添加了 net.resolveHost,它使用 defaultSession 对象解析主机。#38152
- 向
app
添加了新的 'did-resign-active' 事件。#38018 - 为
webContents.print()
添加了几个标准页面尺寸选项。#37159 - 向 session 处理程序
ses.setDisplayMediaRequestHandler()
回调添加了enableLocalEcho
标志,以便在audio
为WebFrameMain
时允许远程音频输入在本地输出流中回显。#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 和微软的扩展支持日期。10 月 11 日,Electron 团队将恢复只支持最新的三个稳定主版本,这些版本将不再支持 Windows 7/8/8.1。
E25 (23 年 5 月) | E26 (23 年 8 月) | E27 (23 年 10 月) |
---|---|---|
25.x.y | 26.x.y | 27.x.y |
24.x.y | 25.x.y | 26.x.y |
23.x.y | 24.x.y | 25.x.y |
22.x.y | 22.x.y | -- |
下一步
短期内,您可以预期团队将继续专注于跟进构成 Electron 的主要组件(包括 Chromium、Node 和 V8)的开发。
您可以在此处找到 Electron 的公开时间线。
有关未来变更的更多信息,请参见计划中的破坏性变更页面。