专栏名称: 程序猿
本微信公众号:imkuqin,为程序员提供最新最全的编程学习资料的查询。目前已经开通PHP、C/C++函数库、.NET Framework类库、J2SE API查询功能。
目录
相关文章推荐
码农翻身  ·  Chrome背后最大的秘密:印度人拯救了Go ... ·  昨天  
OSC开源社区  ·  鸿蒙生态繁荣背后:WPS全面适配Harmon ... ·  1 周前  
程序员的那些事  ·  造福无数打工人,世界第 7 ... ·  1 周前  
51好读  ›  专栏  ›  程序猿

Electron 32 正式发布

程序猿  · 公众号  · 程序员  · 2024-09-15 23:01

正文

来自公众号:前端充电宝

8 月 20 日,Electron 32.0.0 正式发布!该版本包括了对 Chromium 128.0.6613.36、 V8 12.8和 Node.js 20.16.0 的升级。下面就来看看该版本都有哪些更新吧!

可以通过以下命令来安装最新版本:


npm install electron@latest

主要变化

亮点

  • 更新了文档,新增了API版本历史记录功能

  • 移除了Web文件API中非标准的File.path扩展名。

  • 优化了Web文件系统API,在尝试访问被阻止路径中的文件或目录时,失败路径与上游保持一致。

  • 将以下导航相关API整合至webcontents.navigationHistorycanGoBackgoBackcanGoForwardgoForwardcanGoToOffsetgoToOffsetclear。原导航 API 已弃用。

技术栈

  • Chromium:升级到 128.0.6613.36

  • Node:升级到 20.16.0

  • V8:升级到 12.8

新特性

  • 新增了对实用程序进程中发起的身份验证请求的响应机制,通过app模块的login事件实现。#43317

  • CPUUsage结构现包含cumulativeCPUUsage属性,用于返回进程启动以来的累计CPU使用时间(秒)。

  • 将以下导航API集成至webContents.navigationHistorycanGoBackgoBackcanGoForwardgoForwardcanGoToOffsetgoToOffsetclear,同时原API已废弃。

  • WebContentsView现可接受已存在的webContents实例。

  • nativeTheme新增prefersReducedTransparency属性,用于检测用户是否通过系统辅助功能设置关闭了操作系统级别的透明度。

  • 文件系统访问API在尝试打开受限路径中的文件或目录时,其失败处理流程与上游保持一致。

  • 在Linux平台上支持Windows控制覆盖API。

  • 网络请求现支持zstd压缩算法。

重要变化

移除:File.path

Web文件对象的非标准path属性曾在Electron早期版本中提供,以便于在渲染器中处理本地文件。但由于不符合标准并存在安全隐患,自 Electron 32 起已被移除,推荐使用webUtils.getPathForFile方法替代。


// 旧版(渲染器)
const file = document.querySelector('input[type=file]');
alert(`上传文件路径是:${file.path}`);

// 新版(渲染器)
const file = document.querySelector('input[type=file]');
electron.showFilePath(file);

// 新版(预加载脚本)
const { contextBridge, webUtils } = require('electron');

contextBridge.exposeInMainWorld('electron', {
showFilePath(file) {
const path = webUtils.getPathForFile(file);
alert(`上传文件路径是:${path}`);
},
});

弃用:WebContents上的clearHistory、canGoBack、goBack、canGoForward、goForward、goToIndex、canGoToOffset、goToOffset

WebContents实例的导航 API 已弃用,现已迁移到WebContents的navigationHistory属性,以提供更加结构化和用户友好的导航历史管理接口。


// 弃用API
win.webContents.clearHistory();
win.webContents.canGoBack();
win.webContents.goBack();
win.webContents.canGoForward();
win.webContents.goForward();
win.webContents.goToIndex(index);
win.webContents.canGoToOffset();
win.webContents.goToOffset(index);

// 更新后的API
win.webContents.navigationHistory.clear();
win.webContents.navigationHistory.canGoBack();
win.webContents.navigationHistory.goBack();
win.webContents.navigationHistory.canGoForward();
win.webContents.navigationHistory.goForward();
win.webContents.navigationHistory.canGoToOffset();
win.webContents.navigationHistory.goToOffset(index);

注意事项

根据项目的支持政策,Electron 29.x.y 已经达到了支持结束的状态,建议升级到更新的 Electron 版本。

编辑&整理:前端充电宝

参考:https://www.electronjs.org/blog/electron-32-0

---END---