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! 错误和功能请求可以在 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 - 向导航器事件添加了发起者信息。此信息允许区分由父框架引起的
window.open
导航,而不是子框架发起的导航。 #37085 - 添加了 net.resolveHost,它使用 defaultSession 对象解析主机。 #38152
- 为
app
添加了新的 'did-resign-active' 事件。 #38018 - 为
webContents.print()
添加了几个标准的页面尺寸选项。 #37159 - 在会话处理器
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 的公开时间线。
有关未来变更的更多信息,请参阅计划中的破坏性变更页面。