Skip to main content

Electron 3.0.0

· 7 min read

Electron 团队很高兴地宣布,Electron 3 的第一个稳定版本现已从 electronjs.org 和通过 npm install electron@latest 获取!它包含了大量的升级、修复和新功能,我们迫不及待想看看你会用它们创造出什么。以下是此次发布的详细信息,我们欢迎你在探索进程中提供反馈。

🌐 The Electron team is excited to announce that the first stable release of Electron 3 is now available from electronjs.org and via npm install electron@latest! It's jam-packed with upgrades, fixes, and new features, and we can't wait to see what you build with them. Below are details about this release, and we welcome your feedback as you explore.


发布进程

🌐 Release Process

在我们进行 v3.0.0 的开发时,我们试图通过对渐进式测试版反馈进程进行规范化,更加实证地定义稳定版本的标准。没有我们的 应用反馈计划 合作伙伴提供的早期测试和反馈,v3.0.0 就不可能实现。感谢 Atlassian、Atom、Microsoft Teams、Oculus、OpenFin、Slack、Symphony、VS Code 以及其他计划成员的努力。如果你希望参与未来的测试版,请发送邮件至 info@electronjs.org

🌐 As we undertook development of v3.0.0, we sought to more empirically define criteria for a stable release by formalizing the feedback progress for progressive beta releases. v3.0.0 would not have been possible without our App Feedback Program partners, who provided early testing and feedback during the beta cycle. Thanks to Atlassian, Atom, Microsoft Teams, Oculus, OpenFin, Slack, Symphony, VS Code, and other program members for their work. If you'd like to participate in future betas, please mail us at info@electronjs.org.

变更/新功能

🌐 Changes / New Features

对 Electron 工具链的几个重要部分进行了重大升级,包括 Chrome v66.0.3359.181、Node v10.2.0 和 V8 v6.6.346.23.

🌐 Major bumps to several important parts of Electron's toolchain, including Chrome v66.0.3359.181, Node v10.2.0, and V8 v6.6.346.23.

  • [#12656] 功能:app.isPackaged
  • [#12652] 功能:app.whenReady()
  • [#13183] 功能:process.getHeapStatistics()
  • [#12485] 功能:win.moveTop() 将窗口 Z 顺序移到最上层
  • [#13110] 功能:TextField 和 Button API
  • [#13068] 功能:用于动态日志控制的 netLog API
  • [#13539] 功能:在沙箱渲染器中启用 webview
  • [#14118] 功能:fs.readSync 现在支持大型文件
  • [#14031] 功能:节点 fs 封装,使 fs.realpathSync.nativefs.realpath.native 可用

重大 API 更改

🌐 Breaking API changes

  • [#12362] 功能:更新菜单项排序控制
  • [#13050] 重构:移除了已记录的弃用 API
    • 查看更多详情请参阅文档
  • [#12477] 重构:移除了 did-get-response-detailsdid-get-redirect-request 事件
  • [#12655] 功能:默认在拖放时禁用导航
  • [#12993] 功能:需要 Node v4.x 或更高版本才能使用 electron npm 模块
  • [#12008 #12140 #12503 #12514 #12584 #12596 #12637 #12660 #12696 #12716 #12750 #12787 #12858] 重构: NativeWindow
  • [#11968] 重构:menu.popup()
  • [#8953] 特性:不再使用 JSON 发送 ipcRenderer.sendSync 的结果
  • [#13039] 功能:默认忽略 URL 后的命令行参数
  • [#12004] 重构:将 api::Window 重命名为 api::BrowserWindow
  • [#12679] 功能:视觉缩放现在默认关闭
  • [#12408] 重构:将应用命令 media-play_pause 重命名为 media-play-pause

macOS

  • [#12093] 功能:支持工作区通知
  • [#12496] 功能:tray.setIgnoreDoubleClickEvents(ignore) 忽略托盘双击事件。
  • [#12281] 功能:macOS 上的鼠标前进功能
  • [#12714] 功能:屏幕锁定/解锁事件

Windows

  • [#12879] 功能:添加了 DIP 与屏幕坐标的转换

注意事项: 在运行此版本后切换到较旧版本的 Electron 时,你需要清除用户数据目录,以避免旧版本崩溃。你可以通过运行 console.log(app.getPath("userData")) 获取用户数据目录,或查看文档了解更多详情。

错误修复

🌐 Bug Fixes

  • [#13397] 修复:fs.statSyncNoException 抛出异常的问题
  • [#13476, #13452] 修复:使用 jquery 加载网站时崩溃
  • [#14092] 修复:net::ClientSocketHandle 析构函数中的崩溃
  • [#14453] 修复:立即通知焦点变化,而不是在下一个周期

苹果系统

🌐 MacOS

  • [#13220] 修复:解决了在 <input file="type"> 打开文件对话框中允许选择打包包的问题
  • [#12404] 修复:使用异步对话时阻塞主进程的问题
  • [#12043] 修复:右键菜单点击回调
  • [#12527] 修复:触控栏项目重用时的事件泄漏
  • [#12352] 修复:托盘标题崩溃
  • [#12327] 修复:不可拖动区域
  • [#12809] 修复:防止菜单在打开时更新
  • [#13162] 修复:托盘图标边界不允许负值
  • [#13085] 修复:托盘标题高亮时未反转
  • [#12196] 修复:当 enable_run_as_node==false 时的 Mac 构建问题
  • [#12157] 修复:无边框窗口在启用模糊效果时的额外问题
  • [#13326] 修复:在调用 app.removeAsDefaultProtocolClient 后将 MAC 协议设置为无
  • [#13530] 修复:MAS 版本中私有 API 的错误使用
  • [#13517] 修复:tray.setContextMenu 崩溃
  • [#14205] 修复:现在按下对话框的 Esc 键会关闭它,即使设置了 defaultId

Linux

  • [#12507] 修复:针对屏幕外窗口的 BrowserWindow.focus()

其他说明

🌐 Other Notes

  • PDF 查看器目前无法运行,但正在改进中,很快就会恢复运行。
  • TextFieldButton API 是实验性的,因此默认是关闭的
    • 它们可以通过 enable_view_api 构建标志启用

下一步计划

🌐 What's Next

Electron 团队将继续致力于定义我们的进程,以实现更快速、更顺畅的升级,我们力求最终与 Chromium、Node 和 V8 的开发节奏保持一致。

🌐 The Electron team continues to work on defining our processes for more rapid and smooth upgrades as we seek to ultimately maintain parity with the development cadences of Chromium, Node, and V8.

使用 GN 构建 Electron

· 4 min read

Electron 现在使用 GN 来构建自身。以下是关于原因的讨论。

🌐 Electron now uses GN to build itself. Here's a discussion of why.


GYP 和 GN

🌐 GYP and GN

当 Electron 于 2013 年首次发布时,Chromium 的构建配置是用 GYP 编写的,GYP 是“生成你的项目”的缩写。

🌐 When Electron was first released in 2013, Chromium's build configuration was written with GYP, short for "Generate Your Projects".

2014年,Chromium 项目引入了一种新的构建配置工具,名为 GN(“Generate Ninja” 的缩写)。Chromium 的构建文件被迁移到 GN,GYP 从源代码中被移除。

🌐 In 2014, the Chromium project introduced a new build configuration tool called GN (short for "Generate Ninja") Chromium's build files were migrated to GN and GYP was removed from the source code.

Electron 历来将主 [Electron 代码] 与 libchromiumcontent 分开,后者是 Electron 中封装 Chromium 'content' 子模块的部分。Electron 一直使用 GYP,而 libchromiumcontent 作为 Chromium 的一个子集,则在 Chromium 切换到 GN 时也进行了切换。

🌐 Electron has historically kept a separation between the main Electron code and libchromiumcontent, the part of Electron that wraps Chromium's 'content' submodule. Electron has carried on using GYP, while libchromiumcontent -- as a subset of Chromium -- switched to GN when Chromium did.

就像啮合不完全的齿轮一样,使用这两种构建系统之间存在摩擦。保持兼容性容易出错,从编译器标志到 #defines,都需要在 Chromium、Node、V8 和 Electron 之间仔细同步。

🌐 Like gears that don't quite mesh, there was friction between using the two build systems. Maintaining compatibility was error-prone, from compiler flags and #defines that needed to be meticulously kept in sync between Chromium, Node, V8, and Electron.

为了解决这个问题,Electron 团队一直在努力将所有内容迁移到 GN。今天,删除 Electron 中最后一部分 GYP 代码的提交 已经合并到主分支。

🌐 To address this, the Electron team has been working on moving everything to GN. Today, the commit to remove the last of the GYP code from Electron was landed in master.

这对你意味着什么

🌐 What this means for you

如果你正在为 Electron 本身做贡献,从 master 或 4.0.0 检出并构建 Electron 的进程与 3.0.0 及更早版本有很大不同。详情请参阅GN 构建说明

🌐 If you're contributing to Electron itself, the process of checking out and building Electron from master or 4.0.0 is very different than it was in 3.0.0 and earlier. See the GN build instructions for details.

如果你正在使用 Electron 开发应用,你可能会注意到在新的 Electron 4.0.0-nightly 版本中有一些小的变化;但更有可能的是,Electron 在构建系统上的变化对你来说是完全透明的。

🌐 If you're developing an app with Electron, there are a few minor changes you might notice in the new Electron 4.0.0-nightly; but more than likely, Electron's change in build system will be totally transparent to you.

这对 Electron 意味着什么

🌐 What this means for Electron

GN 比 GYP 更快,其生成的文件也更易读且更易维护。此外,我们希望使用单一的构建配置系统能够减少将 Electron 升级到新版本 Chromium 所需的工作量。

🌐 GN is faster than GYP and its files are more readable and maintainable. Moreover, we hope that using a single build configuration system will reduce the work required to upgrade Electron to new versions of Chromium.

  • 它已经大大促进了 Electron 4.0.0 的开发,因为 Chromium 67 移除了对 MSVC 的支持,并改为在 Windows 上使用 Clang 构建。通过 GN 构建,我们可以直接继承 Chromium 的所有编译器命令,所以我们在 Windows 上免费获得了 Clang 构建!
  • 这也使 Electron 更容易在 Electron、Chromium 和 Node 的统一构建中使用 BoringSSL——这是以前有问题的事情。

WebPreferences 漏洞修复

· 4 min read

已发现一个远程代码执行漏洞,影响能够在 Electron 版本(3.0.0-beta.6、2.0.7、1.8.7 和 1.7.15)上打开嵌套子窗口的应用。该漏洞已被分配 CVE 标识符 CVE-2018-15685

🌐 A remote code execution vulnerability has been discovered affecting apps with the ability to open nested child windows on Electron versions (3.0.0-beta.6, 2.0.7, 1.8.7, and 1.7.15). This vulnerability has been assigned the CVE identifier CVE-2018-15685.


受影响的平台

🌐 Affected Platforms

如果出现以下情况,你将会受到影响:

🌐 You are impacted if:

  1. 你嵌入了 任何 远程用户内容,即使是在沙盒中
  2. 你接受任何存在 XSS 漏洞的用户输入

详情

🌐 Details

如果任何用户代码在 iframe 中运行或可以创建 iframe,你将受到影响。鉴于存在 XSS 漏洞的可能性,可以认为大多数应用都存在这种情况的风险。

🌐 You are impacted if any user code runs inside an iframe / can create an iframe. Given the possibility of an XSS vulnerability it can be assumed that most apps are vulnerable to this case.

如果你使用 nativeWindowOpen: truesandbox: true 选项打开任意窗口,你也会受到影响。尽管此漏洞还需要你的应用中存在 XSS 漏洞,但如果你使用其中任一选项,仍应应用以下一种缓解措施。

🌐 You are also impacted if you open any of your windows with the nativeWindowOpen: true or sandbox: true option. Although this vulnerability also requires an XSS vulnerability to exist in your app, you should still apply one of the mitigations below if you use either of these options.

缓解措施

🌐 Mitigation

我们已发布了包含此漏洞修复的新版本 Electron:3.0.0-beta.72.0.81.8.81.7.16。我们强烈建议所有 Electron 开发者立即将他们的应用更新到最新的稳定版本。

🌐 We've published new versions of Electron which include fixes for this vulnerability: 3.0.0-beta.7, 2.0.8, 1.8.8, and 1.7.16. We urge all Electron developers to update their apps to the latest stable version immediately.

如果由于某种原因你无法升级 Electron 版本,你可以通过在所有 webContents 上的 new-window 事件上统一调用 event.preventDefault() 来保护你的应用。如果你根本不使用 window.open 或任何子窗口,那么这对你的应用来说也是一种有效的缓解措施。

🌐 If for some reason you are unable to upgrade your Electron version, you can protect your app by blanket-calling event.preventDefault() on the new-window event for all webContents'. If you don't use window.open or any child windows at all then this is also a valid mitigation for your app.

mainWindow.webContents.on('new-window', (e) => e.preventDefault());

如果你依赖于子窗口创建孙窗口的功能,那么第三种缓解策略是在顶层窗口中使用以下代码:

🌐 If you rely on the ability of your child windows to make grandchild windows, then a third mitigation strategy is to use the following code on your top level window:

const enforceInheritance = (topWebContents) => {
const handle = (webContents) => {
webContents.on(
'new-window',
(event, url, frameName, disposition, options) => {
if (!options.webPreferences) {
options.webPreferences = {};
}
Object.assign(
options.webPreferences,
topWebContents.getLastWebPreferences(),
);
if (options.webContents) {
handle(options.webContents);
}
},
);
};
handle(topWebContents);
};

enforceInheritance(mainWindow.webContents);

这段代码将手动强制将顶层窗口 webPreferences 应用到所有子窗口,深度无限。

🌐 This code will manually enforce that the top level windows webPreferences is manually applied to all child windows infinitely deep.

更多信息

🌐 Further Information

这个漏洞由 Contrast SecurityMatt Austin 发现并负责任地报告给 Electron 项目。

🌐 This vulnerability was found and reported responsibly to the Electron project by Matt Austin of Contrast Security.

要了解有关保持你的 Electron 应用安全的最佳做法的更多信息,请参阅我们的[安全教程]。

🌐 To learn more about best practices for keeping your Electron apps secure, see our security tutorial.

如果你希望报告 Electron 中的漏洞,请提交 [GitHub 安全咨询]。

🌐 Please file a GitHub Security Advisory if you wish to report a vulnerability in Electron.

搜索

· 9 min read

Electron 网站有了一个新的搜索引擎,可以即时显示 API 文档、教程、与 Electron 相关的 npm 包等的搜索结果。

🌐 The Electron website has a new search engine that delivers instant results for API docs, tutorials, Electron-related npm packages, and more.

Electron Search Screenshot


学习像 Electron 这样的新技术或框架可能让人感到畏惧。一旦你度过了[快速入门]阶段,学习最佳实践、找到合适的 API 或发现能帮助你构建理想应用的工具可能会变得困难。我们希望 Electron 网站能成为一个更好的工具,让你更快、更轻松地找到构建应用所需的资源。

🌐 Learning a new technology or framework like Electron can be intimidating. Once you get past the quick-start phase, it can be difficult to learn best practices, find the right APIs, or discover the tools that will help you build the app of your dreams. We want the Electron website to be a better tool for finding the resources you need to build apps faster and more easily.

访问 electronjs.org 的任意页面,你都会在页面顶部看到新的搜索输入框。

🌐 Visit any page on electronjs.org and you'll find the new search input at the top of the page.

搜索引擎

🌐 The Search Engine

当我们最初开始给网站添加搜索功能时,我们使用 GraphQL 作为后端自己开发了搜索引擎。使用 GraphQL 非常有趣,搜索引擎的性能也不错,但我们很快意识到,构建搜索引擎不是一件简单的事情。像多词搜索和拼写错误检测这样的功能需要大量工作才能实现正确。与其重复造轮子,我们决定使用现有的搜索解决方案:Algolia

🌐 When we first set about adding search to the website, we rolled our own search engine using GraphQL as a backend. GraphQL was fun to work with and the search engine was performant, but we quickly realized that building a search engine is not a trivial task. Things like multi-word search and typo detection require a lot of work to get right. Rather than reinventing the wheel, we decided to use an existing search solution: Algolia.

Algolia 是一项托管搜索服务,已迅速成为流行开源项目(如 React、Vue、Bootstrap、Yarn 以及许多其他)的首选搜索引擎。

🌐 Algolia is a hosted search service that has quickly become the search engine of choice among popular open source projects like React, Vue, Bootstrap, Yarn, and many others.

以下是一些使 Algolia 非常适合 Electron 项目的功能:

🌐 Here are some of the features that made Algolia a good fit for the Electron project:

  • InstantSearch.js 在你输入时提供结果,通常大约在1毫秒内。
  • 容错拼写 意味着即使你输入 widnow,仍然可以获得结果。
  • 高级查询语法 使 "exact quoted matches"-exclusion 成为可能。
  • API 客户端 是开源的并且有良好的文档。
  • 分析 告诉我们人们最常搜索的内容,以及他们在搜索但找不到的内容。这将为我们提供有关如何改进 Electron 文档的宝贵见解。
  • Algolia 对开源项目是免费的 链接

API 文档

🌐 API Docs

有时候你知道自己想要完成的目标,但不清楚具体的操作方法。Electron 有超过 750 个 API 方法、事件和属性。没有人能轻松记住它们所有,但计算机在这方面很擅长。通过使用 Electron 的 JSON API 文档,我们将所有数据整理到 Algolia 中,现在你可以轻松找到你所需要的准确 API。

🌐 Sometimes you know what you want to accomplish, but you don't know exactly how to do it. Electron has over 750 API methods, events, and properties. No human can easily remember all of them, but computers are good at this stuff. Using Electron's JSON API docs, we indexed all of this data in Algolia, and now you can easily find the exact API you're looking for.

想调整窗口大小吗?搜索 resize 并直接跳到你需要的方法。

🌐 Trying to resize a window? Search for resize and jump straight to the method you need.

教程

🌐 Tutorials

Electron 拥有不断增长的教程集合,以补充其 API 文档。现在,你可以更轻松地在相关 API 文档旁边找到特定主题的教程。

🌐 Electron has an ever-growing collection of tutorials to complement its API documentation. Now you can more easily find tutorials on a given topic, right alongside related API documentation.

在寻找安全最佳实践吗?请搜索 security

🌐 Looking for security best practices? Search for security.

npm 软件包

🌐 npm Packages

目前 npm 注册表中已有超过 70 万个软件包,要找到你需要的那个并不总是容易的。为了更方便地发现这些模块,我们创建了 electron-npm-packages,这是一个包含注册表中 3400 多个专门为 Electron 使用而构建的模块的集合。

🌐 There are now over 700,000 packages in the npm registry and it's not always easy to find the one you need. To make it easier to discover these modules, we've created electron-npm-packages, a collection of the 3400+ modules in the registry that are built specifically for use with Electron.

Libraries.io 的团队创建了 SourceRank,一个基于代码、社区、文档和使用等多种指标来评分软件项目的系统。我们创建了一个 sourceranks 模块,其中包含 npm 注册表中每个模块的评分,并且我们使用这些评分来对包的结果进行排序。

🌐 The folks at Libraries.io have created SourceRank, a system for scoring software projects based on a combination of metrics like code, community, documentation, and usage. We created a sourceranks module that includes the score of every module in the npm registry, and we use these scores to sort the package results.

想要 Electron 内置 IPC 模块的替代方案吗?搜索 is:package ipc

🌐 Want alternatives to Electron's built-in IPC modules? Search for is:package ipc.

Electron 应用

🌐 Electron Apps

使用 Algolia 索引数据很容易,因此我们从 electron/apps 添加了现有的应用列表。

🌐 It's easy to index data with Algolia, so we added the existing apps list from electron/apps.

尝试搜索 musichomebrew

🌐 Try a search for music or homebrew.

过滤结果

🌐 Filtering Results

如果你以前使用过 GitHub 的代码搜索,你可能已经了解它的以冒号分隔的键值过滤器,例如 extension:jsuser:defunkt。我们认为这种过滤技术非常强大,因此我们在 Electron 的搜索中添加了一个 is: 关键字,可以让你只显示单一类型的结果:

🌐 If you've used GitHub's code search before, you're probably aware of its colon-separated key-value filters like extension:js or user:defunkt. We think this filtering technique is pretty powerful, so we've added an is: keyword to Electron's search that lets you filter results to only show a single type:

键盘导航

🌐 Keyboard Navigation

人们喜爱键盘快捷键!新的搜索功能可以在不离开键盘的情况下使用:

🌐 People love keyboard shortcuts! The new search can be used without taking your fingers off the keyboard:

  • / 聚焦搜索输入
  • esc 聚焦搜索输入框并清除内容
  • 向下 移动到下一个结果
  • 向上 移动到上一个结果,或搜索输入
  • 回车 打开一个结果

我们还开源了模块,它可以实现这种键盘交互。它是为 Algolia InstantSearch 设计的,但已通用化,可兼容不同的搜索实现。

🌐 We also open-sourced the module that enables this keyboard interaction. It's designed for use with Algolia InstantSearch, but is generalized to enable compatibility with different search implementations.

我们期待你的反馈

🌐 We want your feedback

如果你在使用新的搜索工具时遇到任何问题,我们很乐意听取你的意见!

🌐 If you encounter any issues with the new search tool, we want to hear about it!

提交反馈的最佳方式是在 GitHub 的相应仓库中提交问题:

🌐 The best way to submit your feedback is by filing an issue on GitHub in the appropriate repository:

致谢

🌐 Thanks

特别感谢 Emily JordanVanessa Yuen 构建了这些新的搜索功能,感谢 Libraries.io 提供 SourceRank 分数,以及 Algolia 团队帮助我们启动项目。🍹

🌐 Special thanks to Emily Jordan and Vanessa Yuen for building these new search capabilities, to Libraries.io for providing SourceRank scores, and to the team at Algolia for helping us get started. 🍹

国际化更新

· 6 min read

自从新的国际化 Electron 网站上线以来,我们一直在努力,使 Electron 的开发体验对非英语国家的开发者更加易于访问。

🌐 Ever since the launch of the new internationalized Electron website, we have been working hard to make the Electron development experience even more accessible to developers outside of the English speaking world.

现在,我们带来了一些激动人心的国际化更新!

🌐 So here we are with some exciting i18n updates!


🌐 语言切换

🌐 🌐 Language Toggle

你知道吗,许多阅读翻译文档的人经常会参考原始的英文文档?他们这样做是为了熟悉英文文档,同时避免过时或不准确的翻译,这是国际化文档的一个注意事项。

🌐 Did you know that many people who read translated documentation often cross reference that with the original English documentation? They do this to familiarize themselves with English docs, and to avoid outdated or inaccurate translations, which is one caveat of internationalized documentations.

Language toggle on Electron documentation

为了让对英文文档的交叉引用更方便,我们最近推出了一个功能,允许你在 Electron 文档的某个部分在英文和你当前浏览网站时使用的语言之间无缝切换。只要你在网站上选择了非英文的语言,这个语言切换功能就会显示。

🌐 To make cross-referencing to English docs easier, we recently shipped a feature that allows you to seamlessly toggle a section of the Electron documentation between English and whatever language you're viewing the website in. The language toggle will show up as long as you have a non-English locale selected on the website.

⚡️ 快速访问翻译页面

🌐 ⚡️ Quick Access to Translation Page

New Electron documentation footer in Japanese

在阅读文档时发现拼写错误或翻译不正确?你不再需要登录 Crowdin,选择你的语言,找到需要修改的文件,等等。相反,你只需向下滚动到文档底部,点击“翻译此文档”(或你语言中的等效选项)。就这样!你会直接进入 Crowdin 翻译页面。现在开始发挥你的翻译魔法吧!

🌐 Notice a typo or an incorrect translation while you're reading the documentation? You no longer have to log in to Crowdin, pick your locale, find the file you'd like the fix, etc etc. Instead, you can just scroll down to the bottom of the said doc, and click "Translate this doc" (or the equivalent in your language). Voila! You are brought straight to the Crowdin translation page. Now apply your translation magic!

📈 一些统计数据

🌐 📈 Some Statistics

自从我们公开了 Electron 文档的国际化(i18n)工作以来,我们已经看到来自全球各地 Electron 社区成员的翻译贡献出现了 巨大 的增长。截至目前,我们已经 翻译了 1,719,029 条字符串,由 1,066 名社区翻译者完成,涵盖 25 种语言

🌐 Ever since we have publicized the Electron documentation i18n effort, we have seen huge growth in translation contributions from Electron community members from all around the world. To date, we have 1,719,029 strings translated, from 1,066 community translators, and in 25 languages.

Translation Forecast provided by Crowdin

以下是一个有趣的图表,显示了在保持现有进度(基于撰写本文时过去 14 天的项目活动)的情况下,将项目翻译成每种语言所需的大约时间。

🌐 Here is a fun graph showing the approximate amount of time needed to translate the project into each language if the existing tempo (based on the project activity during the last 14 days at the time of writing) is preserved.

📃 翻译员调查

🌐 📃 Translator Survey

我们想向每一位花时间帮助改进 Electron 的人表示衷心的 ❤️ 感谢 ❤️!为了妥善表彰我们翻译社区的辛勤工作,我们创建了一份调查问卷,以收集一些信息(即他们在 Crowdin 和 Github 的用户名对应关系)关于我们的翻译人员。

🌐 We would like to give a huge ❤️ thank you ❤️ to everyone who has contributed their time to help improving Electron! In order to properly acknowledge the hard work of our translator community, we have created a survey to collect some information (namely the mapping between their Crowdin and Github usernames) about our translators.

如果你是我们出色的翻译之一,请花几分钟填写此表格:https://goo.gl/forms/b46sjdcHmlpV0GKT2。

🌐 If you are one of our incredible translators, please take a few minutes to fill this out: https://goo.gl/forms/b46sjdcHmlpV0GKT2.

🙌 Node 的国际化努力

🌐 🙌 Node's Internationalization Effort

由于 Electron 的国际化(i18n)计划的成功,Node.js 决定以我们使用的模式来仿效他们重新设计的国际化努力!🎉 Node.js 国际化计划现已启动并获得了极大的发展势头,但你仍然可以在这里阅读其早期提案和背后的理由 here

🌐 Because of the success of Electron's i18n initiative, Node.js decided to model their revamped i18n effort after the pattern we use as well! 🎉 The Node.js i18n initiative has now been launched and gained great momentum, but you can stil read about the early proposal and reasoning behind it here.

🔦 贡献指南

🌐 🔦 Contributing Guide

如果你有兴趣加入我们,让 Electron 更加国际化,我们有一个方便的贡献指南可以帮助你入门。祝国际化愉快!📚

🌐 If you're interested in joining our effort to make Electron more international friendly, we have a handy-dandy contributing guide to help you get started. Happy internationalizing! 📚

Electron 2.0.0

· 8 min read

经过四个多月的开发、八个测试版本以及来自众多应用分阶段发布的全球范围测试,Electron 2.0.0 现已在 electronjs.org 上发布。

🌐 After more than four months of development, eight beta releases, and worldwide testing from many apps' staged rollouts, the release of Electron 2.0.0 is now available from electronjs.org.


发布进程

🌐 Release Process

从 2.0.0 版本开始,Electron 的发布将遵循语义化版本控制。这意味着主版本的更新频率会更高,通常会包含 Chromium 的重大更新。补丁版本应该更稳定,因为它们只包含高优先级的错误修复。

🌐 Starting with 2.0.0, Electron's releases will follow semantic versioning. This means the major version will bump more often and will usually be a major update to Chromium. Patch releases should be more stable because they will contain only high-priority bug fixes.

Electron 2.0.0 还改进了在重大版本发布前 Electron 的稳定性。几个大型 Electron 应用已经在分阶段推出中包含了 2.0.0 测试版,为 Electron 的测试版系列提供了有史以来最好的反馈循环。

🌐 Electron 2.0.0 also represents an improvement to how Electron is stabilized before a major release. Several large scale Electron apps have included 2.0.0 betas in staged rollouts, providing the best feedback loop Electron's ever had for a beta series.

变更/新功能

🌐 Changes / New Features

  • Electron 工具链的几个重要部分发生了重大变化,包括 Chrome 61、Node 8.9.3、V8 6.1.534.41、Linux 上的 GTK+ 3、更新的拼写检查器和 Squirrel。
  • MacOS 现在支持应用内购买#11292
  • 用于加载文件的新 API。#11565
  • 新的 API 用于启用/禁用窗口。#11832
  • 新的 API app.setLocale()。#11469
  • 新增对记录 IPC 消息的支持。#11880
  • 新菜单活动。 #11754
  • 向 powerMonitor 添加一个 shutdown 事件。 #11417
  • 为将多个 BrowserWindows 聚合到单个进程中添加 affinity 选项。#11501
  • 为 saveDialog 添加列出可用扩展名的功能。 #11873
  • 支持更多通知操作 #11647
  • 能够设置 macOS 通知关闭按钮的标题。 #11654
  • 为 menu.popup(window, callback) 添加条件语句。
  • 触控栏项目的内存改进。 #12527
  • 改进了安全建议清单。
  • 添加应用范围的安全范围书签。 #11711
  • 在渲染器进程中添加设置任意参数的能力。#11850
  • 为格式选择器添加附件视图。#11873
  • 修复了网络代理竞争条件问题。 #12053
  • 不再支持 Linux 上的 mips64el 架构。Electron 需要 C++14 工具链,但在发布时该架构上无法使用。我们希望将来能够重新添加支持。

重大 API 更改

🌐 Breaking API changes

  • 已移除已弃用的 API,包括:
    • 更改了 menu.popup 签名。 #11968
    • 已移除弃用的 crashReporter.setExtraParameter #11972
    • 已移除已弃用的 webContents.setZoomLevelLimitswebFrame.setZoomLevelLimits#11974
    • 已移除不推荐使用的 clipboard 方法。 #11973
    • 已移除对 tray.setHighlightMode 布尔参数的支持。 #11981

错误修复

🌐 Bug Fixes

  • 已更改以确保 webContents.isOffscreen() 始终可用。 #12531
  • 修复了在开发者工具未停靠且获得焦点时的 BrowserWindow.getFocusedWindow()#12554
  • 如果预加载路径包含特殊字符,则沙箱渲染中预加载无法加载已修复。 #12643
  • 根据文档更正 allowRunningInsecureContent 的默认值。#12629
  • 修复了 nativeImage 的透明度问题。#12683
  • 修复了 Menu.buildFromTemplate 的问题。 #12703
  • 已确认 menu.popup 选项是对象。 #12330
  • 已消除新进程创建与上下文释放之间的竞争条件。#12361
  • 在更改 BrowserView 时更新可拖动区域。#12370
  • 修复了在聚焦时菜单栏切换替代键的检测。#12235
  • 修复了 webview 中的不正确警告。 #12236
  • 修复了从父窗口继承 'show' 选项的问题。#122444
  • 确保 getLastCrashReport() 实际上是最后一个崩溃报告。#12255
  • 修复了网络共享路径上的 require。#12287
  • 修复了上下文菜单点击回调。#12170
  • 固定了弹出菜单的位置。 #12181
  • 改进了 libuv 循环清理。 #11465
  • 修复了透明颜色的 hexColorDWORDToRGBA#11557
  • 修复了使用 getWebPreferences API 时的空指针引用问题。#12245
  • 修复了菜单委托中的循环引用。 #11967
  • 修复了 net.request 的协议过滤。#11657
  • WebFrame.setVisualZoomLevelLimits 现在设置用户代理缩放限制 #12510
  • 为 WebView 选项设置适当的默认值。 #12292
  • 改进了鲜艳度支持。#12157 #12171 #11886
  • 修复了单例固件中的计时问题。
  • 修复了 NotifierSupportsActions() 中损坏的生产缓存问题。
  • 使 MenuItem 角色兼容 camelCase。 #11532
  • 改进了触控栏更新。#11812#11761
  • 已移除多余的菜单分隔符。#11827
  • 修复了蓝牙选择器的错误。关闭了 #11399
  • 修复 macOS 全屏切换菜单项标签。#11633
  • 当窗口失去激活时,改进了工具提示的隐藏。#11644
  • 迁移已弃用的 web-view 方法。 #11798
  • 修复了从浏览器视图打开的窗口无法关闭的问题。 #11799
  • 修复了蓝牙选择器的错误。 #11492
  • 已更新为使用任务计划程序来调用 app.getFileIcon API。#11595
  • 即使在屏幕外渲染也改为触发 console-message 事件。 #11921
  • 修复了使用 WebContents.downloadURL 从自定义协议下载的问题。 #11804
  • 修复了在开发者工具分离时透明窗口失去透明度的问题。 #11956
  • 修复了 Electron 应用取消重启或关机的问题。 #11625

macOS

  • 修复了触控栏项目重复使用时的事件泄漏问题。#12624
  • 修复夜间模式下托盘高亮显示。 #12398
  • 修复了异步对话框阻塞主进程的问题。 #12407
  • 修复了 setTitle 托盘崩溃问题。 #12356
  • 修复设置停靠菜单时的崩溃问题。#12087

Linux

  • 更好的 Linux 桌面通知。 #12229 #12216 #11965 #11980
  • 为菜单提供更好的 GTK+ 主题支持。 #12331
  • 在 Linux 上优雅地退出。 #12139
  • 将应用的名称用作托盘图标的默认工具提示。#12393

Windows

  • 增加了对 Visual Studio 2017 的支持。 #11656
  • 修复了将异常传递给系统崩溃处理程序的问题。#12259
  • 修复了最小化窗口时隐藏工具提示的问题。#11644
  • 修复了 desktopCapturer 以捕获正确的屏幕。 #11664
  • 修复了具有透明度的 disableHardwareAcceleration#11704

下一步计划

🌐 What's Next

Electron 团队正在努力支持更新版本的 Chromium、Node 和 v8。3.0.0-beta.1 版本即将推出!

🌐 The Electron team is hard at work to support newer versions of Chromium, Node, and v8. Expect 3.0.0-beta.1 soon!

开源应用更轻松的自动更新

· 5 min read

今天我们发布了一个免费的开源托管 更新网络服务 及其配套的 npm 包,以便为开源 Electron 应用实现轻松的自动更新。这是迈向让应用开发者更少关注部署、更多专注于为用户开发高质量体验的一步。

🌐 Today we're releasing a free, open-source, hosted updates webservice and companion npm package to enable easy automatic updates for open-source Electron apps. This is a step toward empowering app developers to think less about deployment and more about developing high-quality experiences for their users.


让生活更轻松

🌐 Making life easier

Electron 有一个 autoUpdater API,它使应用能够从远程端点获取元数据以检查更新,在后台下载更新,并自动安装它们。

🌐 Electron has an autoUpdater API that gives apps the ability to consume metadata from a remote endpoint to check for updates, download them in the background, and install them automatically.

对于许多 Electron 应用开发者来说,启用这些更新一直是部署进程中的一个繁琐步骤,因为它需要部署和维护一个网络服务器,仅仅为了提供应用版本历史的元数据。

🌐 Enabling these updates has been a cumbersome step in the deployment process for many Electron app developers because it requires a web server to be deployed and maintained just to serve app version history metadata.

今天我们宣布推出一项新的即插即用解决方案,用于自动应用更新。如果你的 Electron 应用位于公共 GitHub 仓库中,并且你使用 GitHub Releases 发布构建版本,你可以使用此服务向用户提供持续的应用更新。

🌐 Today we are announcing a new drop-in solution for automatic app updates. If your Electron app is in a public GitHub repository and you're using GitHub Releases to publish builds, you can use this service to deliver continuous app updates to your users.

使用新模块

🌐 Using the new module

为了尽量减少你的配置工作,我们创建了 update-electron-app,这是一个与新的 update.electronjs.org 网络服务集成的 npm 模块。

🌐 To minimize configuration on your part, we've created update-electron-app, an npm module which integrates with the new update.electronjs.org webservice.

安装模块:

🌐 Install the module:

npm install update-electron-app

可以在应用的任何位置调用它([主进程]):

🌐 Call it from anywhere in your app's main process:

require('update-electron-app')();

就是这样!该模块将在应用启动时检查更新,然后每十分钟检查一次。当发现更新时,它会在后台自动下载,并在更新准备好时显示一个对话框。

🌐 That's it! The module will check for updates at app startup, then every ten minutes. When an update is found it will download automatically in the background, and a dialog will be displayed when the update is ready.

迁移现有的应用

🌐 Migrating existing apps

已经使用 Electron 的 autoUpdater API 的应用也可以使用此服务。要使用它,你可以 自定义 update-electron-app 模块 或 直接与 update.electronjs.org 集成

🌐 Apps already using Electron's autoUpdater API can use this service too. To do so, you can customize the update-electron-app module or integrate directly with update.electronjs.org.

替代方案

🌐 Alternatives

如果你使用 electron-builder 打包你的应用,你可以使用它内置的更新器。详情请参见 electron.build/auto-update

🌐 If you're using electron-builder to package your app, you can use its built-in updater. For details, see electron.build/auto-update.

如果你的应用是私有的,你可能需要运行自己的更新服务器。有许多开源工具可以做到这一点,包括 Zeit 的 Hazel 和 Atlassian 的 Nucleus。有关更多信息,请参阅 [部署更新服务器] 教程。

🌐 If your app is private, you may need to run your own update server. There are a number of open-source tools for this, including Zeit's Hazel and Atlassian's Nucleus. See the Deploying an Update Server tutorial for more info.

致谢

🌐 Thanks

感谢 Julian Gruber 帮助设计和构建这个简单且可扩展的网络服务。感谢 Zeit 的团队提供开源的 Hazel 服务,我们从中获得了设计灵感。感谢 Samuel Attard 对代码的审查。感谢 Electron 社区帮助测试这个服务。

🌐 Thanks to Julian Gruber for helping design and build this simple and scalable web service. Thanks to the folks at Zeit for their open-source Hazel service, from which we drew design inspiration. Thanks to Samuel Attard for the code reviews. Thanks to the Electron community for helping test this service.

🌲 祝 Electron 应用拥有一个常青的未来!

Electron 2 新功能:应用内购买

· 4 min read

全新的 Electron 2.0 发行版本充满了新功能和修复。这个新主版本的亮点之一是为苹果的 Mac 应用商店提供的新 inAppPurchase API

🌐 The new Electron 2.0 release line is packed with new features and fixes. One of the highlights from this new major version is a new inAppPurchase API for Apple's Mac App Store.


应用内购买允许用户直接在应用内购买内容或订阅。这为开发者提供了一种轻松采用免费增值商业模式的方式,在这种模式下,用户免费下载应用,但可选择购买应用内提供的高级功能、额外内容或订阅服务。

🌐 In-app purchases enable content or subscriptions to be purchased directly from within apps. This gives developers an easy way to embrace the freemium business model, wherein users pay nothing to download an app and are offered optional in-app purchases for premium features, additional content, or subscriptions.

新的 API 由社区贡献者 Adrien Fery 添加到 Electron 中,以便在讲座和会议的注意应用 Amanote 中启用应用内购买。Amanote 可以免费下载,并允许在 PDF 中添加清晰且结构化的注意,并提供数学公式、绘图、音频录制等功能。

🌐 The new API was added to Electron by community contributor Adrien Fery to enable in-app purchases in Amanote, a note-taking Electron app for lectures and conferences. Amanote is free to download and allows clear and structured notes to be added to PDFs, with features like mathematical formulae, drawings, audio recording, and more.

自从在 Amanote 的 Mac 版本中添加了应用内购买支持后,Adrien 注意到销量增加了 40%

🌐 Since adding in-app purchase support to the Mac version of Amanote, Adrien has noted a 40% increase in sales!

入门

🌐 Getting Started

新的 inAppPurchase API 已经在最新的 Electron 测试版中发布:

🌐 The new inAppPurchase API has already landed in the latest Electron beta:

npm i -D electron@beta

API 的文档可以在 GitHub 上找到,Adrien 也非常乐意写了一篇关于如何使用 API 的教程。要开始在你的应用中添加应用内购买,请查看教程

🌐 The docs for the API can be found on GitHub, and Adrien has been kind enough to write a tutorial on how to use the API. To get started adding in-app purchases to your app, see the tutorial.

更多 API 改进 正在进行中,并将很快在即将发布的 Electron 测试版中推出。

🌐 More improvements to the API are in the works, and will soon be landing in an upcoming Electron beta release.

Windows 可能是下一个

🌐 Windows Could Be Next

接下来,Adrien 希望通过在 Electron 中增加对 Microsoft Store 应用内购买的支持,为 Amanote 开辟新的收入渠道。敬请关注相关进展!

🌐 Up next, Adrien is hoping to open a new revenue channel for Amanote by adding support for Microsoft Store in-app purchases in Electron. Stay tuned for developments on that!

Webview 漏洞修复

· 3 min read

发现了一个漏洞,该漏洞允许在某些禁用 Node.js 集成的 Electron 应用中重新启用 Node.js 集成。该漏洞已被分配 CVE 标识符 CVE-2018-1000136

🌐 A vulnerability has been discovered which allows Node.js integration to be re-enabled in some Electron applications that disable it. This vulnerability has been assigned the CVE identifier CVE-2018-1000136.


受影响的应用

🌐 Affected Applications

如果以下所有情况都成立,则应用会受到影响:

🌐 An application is affected if all of the following are true:

  1. 可在 Electron 1.7、1.8 或 2.0.0-beta 版本上运行
  2. 允许执行任意远程代码
  3. 禁用 Node.js 集成
  4. 在其 webPreferences 中未明确声明 webviewTag: false
  5. 未启用 nativeWindowOption 选项
  6. 不会拦截 new-window 事件,并且在不使用提供的 options 标签的情况下手动覆盖 event.newGuest

虽然这似乎只存在于少数 Electron 应用中,但我们建议所有应用升级以防万一。

🌐 Although this appears to be a minority of Electron applicatons, we encourage all applications to be upgraded as a precaution.

缓解措施

🌐 Mitigation

此漏洞已在今天发布的 1.7.131.8.42.0.0-beta.5 版本中修复。

🌐 This vulnerability is fixed in today's 1.7.13, 1.8.4, and 2.0.0-beta.5 releases.

无法升级应用 Electron 版本的开发者可以使用以下代码缓解此漏洞:

🌐 Developers who are unable to upgrade their application's Electron version can mitigate the vulnerability with the following code:

app.on('web-contents-created', (event, win) => {
win.on(
'new-window',
(event, newURL, frameName, disposition, options, additionalFeatures) => {
if (!options.webPreferences) options.webPreferences = {};
options.webPreferences.nodeIntegration = false;
options.webPreferences.nodeIntegrationInWorker = false;
options.webPreferences.webviewTag = false;
delete options.webPreferences.preload;
},
);
});

// and *IF* you don't use WebViews at all,
// you might also want
app.on('web-contents-created', (event, win) => {
win.on('will-attach-webview', (event, webPreferences, params) => {
event.preventDefault();
});
});

更多信息

🌐 Further Information

这个漏洞是由 Trustwave SpiderLabs 的 Brendan Scarvell 发现并负责任地报告给 Electron 项目的。

🌐 This vulnerability was found and reported responsibly to the Electron project by Brendan Scarvell of Trustwave SpiderLabs.

要了解有关保持 Electron 应用安全的最佳实践的更多信息,请参阅我们的 安全教程

🌐 To learn more about best practices for keeping your Electron apps secure, see our security tutorial.

如果你希望报告 Electron 中的漏洞,请提交 [GitHub 安全咨询]。

🌐 Please file a GitHub Security Advisory if you wish to report a vulnerability in Electron.

请加入我们的email list以接收有关版本发布和安全更新的通知。

🌐 Please join our email list to receive updates about releases and security updates.

网站故障

· 3 min read

上周,electronjs.org 网站有几分钟的停机。如果你受到这些短暂中断的影响,我们对此带来的不便表示歉意。经过今天的一些调查,我们已经诊断出根本原因,并部署了一个修复

🌐 Last week the electronjs.org site had a few minutes of downtime. If you were affected by these brief outages, we're sorry for the inconvenience. After a bit of investigation today, we've diagnosed the root cause and have deployed a fix.


为了防止将来出现这种停机情况,我们已经在我们的应用上启用了Heroku 阈值警报。每当我们的 Web 服务器累积的失败请求或响应缓慢超过某个阈值时,我们的团队将会收到通知,以便我们能够快速解决问题。

🌐 To prevent this kind of downtime in the future, we've enabled Heroku threshold alerts on our app. Any time our web server accumulates failed requests or slow responses beyond a certain threshold, our team will be notified so we can address the problem quickly.

所有语言的离线文档

🌐 Offline Docs in Every Language

下次当你在飞机上或地下咖啡馆开发 Electron 应用时,可能会希望拥有一份离线文档以供参考。幸运的是,Electron 的文档以 Markdown 文件形式提供,并且有超过 20 种语言版本。

🌐 The next time you're developing an Electron app on a plane or in a subterranean coffee shop, you might want to have a copy of the docs for offline reference. Fortunately, Electron's docs are available as Markdown files in over 20 languages.

git clone https://github.com/electron/electron-i18n
ls electron-i18n/content

带有图形用户界面的离线文档

🌐 Offline Docs with a GUI

devdocs.io/electron 是一个方便的网站,提供离线文档,不仅仅适用于 Electron,还包括许多其他项目,如 JavaScript、TypeScript、Node.js、React、Angular 等等。当然,也有针对它的 Electron 应用。
可以查看 devdocs-app 在 Electron 网站上的信息。

devdocs-app

如果你想在不使用鼠标或触控板的情况下安装应用,可以尝试使用 Electron Forgeinstall 命令:

🌐 If you like to install apps without using your mouse or trackpad, give Electron Forge's install command a try:

npx electron-forge install egoist/devdocs-app