¥When people use GitHub in their job or OSS activities, they tend to receive many notifications on a daily basis. As a way to subscribe to the notifications, GitHub provides email and web notifications. I used these for a couple of years, but I faced the following problems:
我很容易忽略别人提到我、我评论过或我正在关注的问题。
¥It's easy to overlook issues where I was mentioned, I commented, or I am watching.
我把一些问题记在脑子里,以便以后检查,但有时我会忘记它们。
¥I put some issues in a corner of my head to check later, but I sometimes forget about them.
为了避免忘记问题,我会在浏览器中保持多个标签页打开。
¥To not forget issues, I keep many tabs open in my browser.
很难检查所有与我相关的问题。
¥It's hard to check all issues that are related to me.
¥I was spending a lot of time and energy trying to prevent those problems, so I decided to make an issue reader for GitHub to solve these problems efficiently, and started developing Jasper.
¥Jasper is used by developers, designers, and managers in several companies that are using GitHub.
Of course, some OSS developers also are using it.
And it is also used by some people at GitHub!
¥This "stream" is the core feature of Jasper. For example, if you want to see "issues that are assigned to @zeke in the electron/electron repository", you create the following stream:
repo:electron/electron assignee:zeke is:issue
创建流并等待几秒钟后,你可以看到符合条件的问题。
¥After creating the stream and waiting for a few seconds, you can see the issues that meet the conditions.
¥As you may have noticed by looking at these, streams can use GitHub's search queries.
For details on how to use streams and search queries, see the following URLs.
¥Jasper also has features for unread issue management, unread comment management, marking stars, notification updating, filtering issues, keyboard shortcuts, etc.
¥These features enable rapid and simple desktop application development. It is awesome! If you have any product idea, you should consider using Electron by all means.
¥What are some challenges you've faced while developing Jasper?
我费了好大劲才弄清楚 "stream" 的概念。起初我考虑使用 GitHub 的 通知 API。但是我注意到它不支持某些用例。之后,除了通知 API 之外,我还考虑使用 问题 API 和 拉取请求 API。但它从未达到我的预期。然后,在思考各种方法时,我意识到轮询 GitHub 的 搜索 API 将提供最大的灵活性。我花了大约一个月的时间进行实验才达到这个目标,然后我用两天时间实现了一个带有流概念的 Jasper 原型。
¥I had a hard time figuring out the "stream" concept. At first I considered using GitHub's Notifications API. However I noticed that it does not support certain use cases. After that I considered using the Issues API and Pull Requests API, in addition to the Notification API. But it never became what I wanted. Then while thinking about various methods, I realized that polling GitHub's Search API would offer the most flexibility. It took about a month of experimentation to get to this point, then I implemented a prototype of Jasper with the stream concept in two days.
注意:轮询次数最多限制为每 10 秒一次。这对于 GitHub API 的限制来说已经足够了。
¥Note: The polling is limited to once every 10 seconds at most. This is acceptable enough for the restriction of GitHub API.
本周,我们采访了 @feross 和 @dcposch,一起探讨了 WebTorrent。这是一款基于 Web 的种子客户端,它将用户连接在一起,形成一个分布式、去中心化的浏览器到浏览器网络。
¥This week we caught up with @feross and @dcposch to talk about WebTorrent, the web-powered torrent client that connects users together to form a distributed, decentralized browser-to-browser network.
¥WebTorrent is the first torrent client that works in the browser. It's written completely in JavaScript and it can use WebRTC for peer-to-peer transport. No browser plugin, extension, or installation is required.
WebTorrent 使用开放的 Web 标准,将网站用户连接在一起,形成一个分布式、去中心化的浏览器到浏览器网络,以实现高效的文件传输。
¥Using open web standards, WebTorrent connects website users together to form a distributed, decentralized browser-to-browser network for efficient file transfer.
¥Imagine a video site like YouTube, but where visitors help to host the site's content. The more people that use a WebTorrent-powered website, the faster and more resilient it becomes.
浏览器之间的通信省去了中间人,让人们可以按照自己的方式进行交流。不再使用客户端/服务器模式 - 只创建一个对等网络,所有对等网络均平等。WebTorrent 是重新去中心化 Web 之旅的第一步。
¥Browser-to-browser communication cuts out the middle-man and lets people communicate on their own terms. No more client/server – just a network of peers, all equal. WebTorrent is the first step in the journey to re-decentralize the Web.
¥In the early days, BitTorrent used TCP as its transport protocol. Later, uTP came along promising better performance and additional advantages over TCP. Every mainstream torrent client eventually adopted uTP, and today you can use BitTorrent over either protocol. The WebRTC protocol is the next logical step. It brings the promise of interoperability with web browsers – one giant P2P network made up of all desktop BitTorrent clients and millions of web browsers.
¥“Web peers” (torrent peers that run in a web browser) make the BitTorrent network stronger by adding millions of new peers, and spreading BitTorrent to dozens of new use cases. WebTorrent follows the BitTorrent spec as closely as possible, to make it easy for existing BitTorrent clients to add support for WebTorrent.
一些种子应用(例如 Vuze)已经支持 Web 端,但我们不想等待其他应用添加支持。所以,WebTorrent Desktop 基本上是我们加速 WebTorrent 协议普及的一种方式。通过制作一款人们真正想要使用的优秀 torrent 应用,我们增加了网络中可以与 Web 用户(即网站上的用户)共享 torrent 的对等体数量。
¥Some torrent apps like Vuze already support web peers, but we didn't want to wait around for the rest to add support. So basically, WebTorrent Desktop was our way to speed up the adoption of the WebTorrent protocol. By making an awesome torrent app that people really want to use, we increase the number of peers in the network that can share torrents with web peers (i.e. users on websites).
¥One of the most exciting uses for WebTorrent is peer-assisted delivery. Non-profit projects like Wikipedia and the Internet Archive could reduce bandwidth and hosting costs by letting visitors chip in. Popular content can be served browser-to-browser, quickly and cheaply. Rarely-accessed content can be served reliably over HTTP from the origin server.
¥The Internet Archive actually already updated their torrent files so they work great with WebTorrent. So if you want to embed Internet Archive content on your site, you can do it in a way that reduces hosting costs for the Archive, allowing them to devote more money to actually archiving the web!
还有一些令人兴奋的商业用例,从 CDN 到通过 P2P 交付应用。
¥There are also exciting business use cases, from CDNs to app delivery over P2P.
¥What are some of your favorite projects that use WebTorrent?
毫无疑问,用 WebTorrent 构建的最酷的东西可能是 Gaia 3D 星图。它是一个流畅的银河系 3D 交互式模拟。数据直接从浏览器中的 torrent 加载。飞越我们的星系,意识到我们人类与浩瀚的宇宙相比是多么渺小,这令人惊叹。
¥The coolest thing built with WebTorrent, hands down, is probably Gaia 3D Star Map. It's a slick 3D interactive simulation of the Milky Way. The data loads from a torrent, right in your browser. It's awe-inspiring to fly through our star system and realize just how little we humans are compared to the vastness of our universe.
¥You can read about how this was made in Torrenting The Galaxy, a blog post where the author, Charlie Hoey, explains how he built the star map with WebGL and WebTorrent.
¥We're also huge fans of Brave. Brave is a browser that automatically blocks ads and trackers to make the web faster and safer. Brave recently added torrent support, so you can view traditional torrents without using a separate app. That feature is powered by WebTorrent.
因此,就像大多数浏览器可以渲染 PDF 文件一样,Brave 也可以渲染磁力链接和种子文件。它们只是浏览器原生支持的另一种内容类型。
¥So, just like how most browsers can render PDF files, Brave can render magnet links and torrent files. They're just another type of content that the browser natively supports.
¥One of the co-founders of Brave is actually Brendan Eich, the creator of JavaScript, the language we wrote WebTorrent in, so we think it's pretty cool that Brave chose to integrate WebTorrent.
¥Why did you choose to build WebTorrent Desktop on Electron?
有种说法是 Electron 应用是 "bloated",因为它们在每个应用中都包含完整的 Chrome 内容模块。在某些情况下,这部分正确(Electron 应用安装程序通常约为 40MB,而特定于操作系统的应用安装程序通常约为 20MB)。
¥There is a meme that Electron apps are "bloated" because they include the entire Chrome content module in every app. In some cases, this is partially true (an Electron app installer is usually ~40MB, where an OS-specific app installer is usually ~20MB).
然而,就 WebTorrent 桌面版而言,我们在正常运行过程中几乎使用了所有 Electron 功能以及数十项 Chrome 功能。如果我们想为每个平台从头开始实现这些功能,那么构建我们的应用将需要数月甚至数年的时间,或者我们只能为单个平台发布应用。
¥However, in the case of WebTorrent Desktop, we use nearly every Electron feature, and many dozens of Chrome features in the course of normal operation. If we wanted to implement these features from scratch for each platform, it would have taken months or years longer to build our app, or we would have only been able to release for a single platform.
为了便于理解,我们使用了 Electron 的 Dock 集成(用于显示下载进度)、菜单栏集成(用于在后台运行)、协议处理程序注册(用于打开磁力链接)、省电阻止程序(用于防止视频播放期间进入睡眠状态)和 自动更新程序。至于 Chrome 特性,我们大量使用了以下特性:<video> 标签(用于播放多种不同的视频格式)、<track> 标签(用于支持隐藏字幕)、拖放支持以及 WebRTC(在原生应用中使用起来并不简单)。
¥Just to get an idea, we use Electron's dock integration (to show download progress), menu bar integration (to run in the background), protocol handler registration (to open magnet links), power save blocker (to prevent sleep during video playback), and automatic updater. As for Chrome features, we use plenty: the <video> tag (to play many different video formats), the <track> tag (for closed captions support), drag-and-drop support, and WebRTC (which is non-trivial to use in a native app).
¥Not to mention: our torrent engine is written in JavaScript and assumes the existence of lots of Node APIs, but especially require('net') and require('dgram') for TCP and UDP socket support.
¥The WebTorrent library has been in development as an open source side project for two years. We made WebTorrent Desktop in four weeks. Electron is the primary reason that we were able to build and ship our app so quickly.
¥Just as Node.js made server programming accessible to a generation of jQuery-using front-end programmers, Electron makes native app development accessible to anyone familiar with Web or Node.js development. Electron is extremely empowering.
¥Yes, the webtorrent npm package works in Node.js, in the browser, and in Electron. The exact same code can run in all environments – this is the beauty of JavaScript. It's today's universal runtime. Java Applets promised "Write Once, Run Anywhere" apps, but that vision never really materialized for a number of reasons. Electron, more than any other platform, actually gets pretty darn close to that ideal.
¥In early versions of the app, we struggled to make the UI performant. We put the torrent engine in the same renderer process that draws the main app window which, predictably, led to slowness anytime there was intense CPU activity from the torrent engine (like verifying the torrent pieces received from peers).
¥We fixed this by moving the torrent engine to a second, invisible renderer process that we communicate with over IPC. This way, if that process briefly uses a lot of CPU, the UI thread will be unaffected. Buttery-smooth scrolling and animations are so satisfying.
¥Note: we had to put the torrent engine in a renderer process, instead of a "main" process, because we need access to WebRTC (which is only available in the renderer.)
¥One thing we'd love to see is better documentation about how to build and ship production-ready apps, especially around tricky subjects like code signing and auto-updating. We had to learn about best practices by digging into source code and asking around on Twitter!
¥We think the current version of WebTorrent Desktop is excellent, but there's always room for improvement. We're currently working on improving polish, performance, subtitle support, and video codec support.
¥Feross, one of the WebTorrent Desktop contributors, recently gave a talk "Real world Electron: Building Cross-platform desktop apps with JavaScript" at NodeConf Argentina that contains useful tips for releasing a polished Electron app. The talk is especially useful if you're at the stage where you have a basic working app and you're trying to take it to the next level of polish and professionalism.
DC 是另一位 WebTorrent 贡献者,他编写了 一份你可以执行的操作清单,旨在让你的应用更加精致,更具原生体验。它附带代码示例,涵盖了 macOS 停靠栏集成、拖放、桌面通知以及确保应用快速加载等功能。
¥DC, another WebTorrent contributor, wrote a checklist of things you can do to make your app feel polished and native. It comes with code examples and covers things like macOS dock integration, drag-and-drop, desktop notifications, and making sure your app loads quickly.
¥The Electron 1.6.3 beta release contains initial support for the macOS Touch Bar.
新的 Touch Bar API 允许你添加按钮、标签、弹出窗口、颜色选择器、滑块和间隔符。这些元素可以动态更新,并且在与它们交互时会触发事件。
¥The new Touch Bar API allows you to add buttons, labels, popovers, color
pickers, sliders, and spacers. These elements can be dynamically updated and
also emit events when they are interacted with.
这是该 API 的第一个版本,因此它将在接下来的几个 Electron 版本中不断发展。请查看发行说明以获取更多更新,并打开 issues 以查找任何问题或缺失的功能。
¥This is the first release of this API so it will be evolving over the next
few Electron releases. Please check out the release notes for further updates
and open issues for any problems
or missing functionality.
你可以通过 npm install electron@beta 安装此版本,并在 TouchBar 和 BrowserWindow Electron 文档中了解更多信息。
¥You can install this version via npm install electron@beta and learn
more about it in the TouchBar
and BrowserWindow
Electron docs.
¥Below is an example of creating a simple slot machine game in the touch bar.
It demonstrates how to create a touch bar, style the items, associate it with a
window, handle button click events, and update the labels dynamically.
const{ app,BrowserWindow,TouchBar}=require('electron'); const{TouchBarButton,TouchBarLabel,TouchBarSpacer}=TouchBar; let spinning =false; // Reel labels const reel1 =newTouchBarLabel(); const reel2 =newTouchBarLabel(); const reel3 =newTouchBarLabel(); // Spin result label const result =newTouchBarLabel(); // Spin button const spin =newTouchBarButton({ label:'🎰 Spin', backgroundColor:'#7851A9', click:()=>{ // Ignore clicks if already spinning if(spinning){ return; } spinning =true; result.label=''; let timeout =10; const spinLength =4*1000;// 4 seconds const startTime =Date.now(); constspinReels=()=>{ updateReels(); if(Date.now()- startTime >= spinLength){ finishSpin(); }else{ // Slow down a bit on each spin timeout *=1.1; setTimeout(spinReels, timeout); } }; spinReels(); }, }); constgetRandomValue=()=>{ const values =['🍒','💎','7️⃣','🍊','🔔','⭐','🍇','🍀']; return values[Math.floor(Math.random()* values.length)]; }; constupdateReels=()=>{ reel1.label=getRandomValue(); reel2.label=getRandomValue(); reel3.label=getRandomValue(); }; constfinishSpin=()=>{ const uniqueValues =newSet([reel1.label, reel2.label, reel3.label]).size; if(uniqueValues ===1){ // All 3 values are the same result.label='💰 Jackpot!'; result.textColor='#FDFF00'; }elseif(uniqueValues ===2){ // 2 values are the same result.label='😍 Winner!'; result.textColor='#FDFF00'; }else{ // No values are the same result.label='🙁 Spin Again'; result.textColor=null; } spinning =false; }; const touchBar =newTouchBar([ spin, newTouchBarSpacer({size:'large'}), reel1, newTouchBarSpacer({size:'small'}), reel2, newTouchBarSpacer({size:'small'}), reel3, newTouchBarSpacer({size:'large'}), result, ]); letwindow; app.once('ready',()=>{ window=newBrowserWindow({ frame:false, titleBarStyle:'hidden-inset', width:200, height:200, backgroundColor:'#000', }); window.loadURL('about:blank'); window.setTouchBar(touchBar); });
¥Voltra is a music player for people who want to own their music. It’s also a store where you can discover and buy new music based on what you already own. It’s ad-free, cross-platform for desktop and mobile. It also doesn’t spy on you.
¥Radio has has always had a big share of listeners. It’s moving off the airwaves and onto the Internet. Now you can rent music on demand — it’s a radio revival! A lot of new products and services have emerged because of this, but streaming radio still leaves someone else in control of your music and how you experience it.
¥We wanted a product that was entirely focused on music you own. Something that made it easy to discover and buy new music directly from artists or labels.
¥Since the app is free, we may open source it later on. Right now we don’t have the bandwidth to manage that. We also have very specific ideas for features and the direction we want to take things. We have an active beta community and we take our feedback to heart.
¥Our Voltra Audio Archive is a cloud-backup service designed specifically for music. We don’t compress or share data blocks. Your music collection is physically backed up for you.
¥For artists and labels, our Pro Membership offers tools to help them reach more relevant audiences, such as analytics and professional artist webpages.
¥Design and usability are incredibly important to us. We want to give listeners a distraction-free listening experience! There are a some interesting music players and stores out there. But many of them are more advanced and harder to use than their creators realize. We want to make Voltra accessible to as many people as possible.
¥We also don't take a cut from the artist or the label. That’s a key differentiator for us. It’s really important because it lowers the barrier for artists to get their music to market.
¥What are some design & technical decisions you made?
在设计 Voltra 时,我们考虑了原生应用和 Web 的 UI 惯例,也仔细考虑了可以移除的内容。我们有一个活跃的私有 Beta 测试小组,在过去几个月里,他们给了我们很多重要的反馈。
¥While designing Voltra, we considered UI conventions from native apps and the web, we also thought a lot about what we could remove. We have an active private beta group who have given us critical feedback over the last few months.
¥We found that album art and photography are really important to people. Many players are just lists of files. One of the cool things about owning physical albums is the album art, and we wanted to put emphasis on this in the Voltra desktop app.
¥We also made sure not to mess with people's files. We use file watching so you can put your files wherever you want, and we don't rename them or move them for you. We have an embedded database to track the state of the watched directories so that we can track what's new, even when the process isn't running.
¥We spend a lot of time focused on performance. We started with frameworks but moved to vanilla Javascript. In our experience, the generalized abstractions they provide outweigh the performance penalties and ceremony that they introduce.
目前,我们可以很好地处理非常大的集合。大型集合意味着可能包含数以万计的图片!在渲染过程中直接使用 Node.js 的文件系统模块,可以非常轻松地基于 DOM 事件快速延迟加载和卸载大量图片。
¥We handle very large collections pretty well at this point. Large collections means possibly tens of thousands of images! Having Node.js’ file system module directly available from the render process made it really easy to lazy load and unload lots of images super quickly based on DOM events.
¥In general setImmediate and requestIdleCallback have been super important tools for performing lots of processing while keeping the UI responsive. More specifically, distributing CPU-bound tasks into separate processes really helps to keep the user interface responsive. For example, we moved the actual audio context into a separate process, communicating with it over IPC to avoid potential interruptions from a busy UI.
浏览器的沙盒对我们的应用而言限制过多。但我们也在开发一个 Web 播放器。因此,我们可以在两种实现之间共享几乎 100% 的代码,这是一个巨大的优势。
¥The browser’s sandbox is too restricted for our app. But we are also developing a web player. So it’s a huge win that we can share almost 100% of the code between the two implementations.
我们实际上是从使用 Swift 构建原生应用开始的。我们发现的主要问题是我们在重复很多事情。Web 拥有世界上最大的开源生态系统。因此,我们很快就转向了 Electron。
¥We actually started by building a native app with Swift. The main problem we found was that we were reinventing a lot of things. The web has the world’s largest open source eco-system. So we pretty quickly switched to Electron.
此外,最重要的是,使用 Electron,你只需开发一次,它就可以在所有主流平台上正常工作™。虽然不能保证,但为每个平台进行原生编码的成本绝对超过了 Electron 带来的任何其他成本。
¥Also, and most importantly, with Electron you develop once and it should Just Work™ on all the major platforms. It’s not guaranteed, but the cost of coding natively for each platform definitely outweighs any other costs that electron introduces.
¥GTD!: Having Node.js’ networking stack and Chromium’s presentation layer packaged together is a recipe for getting things done.
权限:这只是一个 Web 栈,所以实际上我们整个团队都参与了产品的构建。
¥Competency: It’s just the web stack, so literally our whole team is involved in actually building the product.
社区:Electron 社区组织严密,善于沟通!我们很高兴能获得这样的支持。
¥Community: There is a highly organized community that knows how to communicate really well! We feel pretty great about developing with support like that.
我们希望 Electron 能够支持单一的打包工具。打包程序对 Electron 的重要性,就如同软件包管理器对 Node 一样重要。用户空间中有多个打包器,每个打包器都具有有趣的功能,但也存在一些 bug。社区的共识将有助于引导贡献者投入的精力。
¥We would like to see Electron endorse a single packager. The packager is as important to Electron what the package manager is to Node. There are multiple packagers in user-land, each with interesting features but each with bugs. Consensus by the community would help to direct the energy being spent by contributors.
¥We‘re currently developing a mobile app, and working with artists and labels to add their music to the Voltra shop. Hey! If you’re an artist or label, sign up now! We plan on opening up the shop when we reach our goal of 10 million tracks.
Electron 基于 Google 的开源 Chromium 项目,该项目的设计目的并非供其他项目使用。本文介绍了如何将 Chromium 构建为 Electron 使用的库,以及构建系统多年来的发展历程。
¥Electron is based on Google's open-source Chromium, a project that is not
necessarily designed to be used by other projects. This post introduces
how Chromium is built as a library for Electron's use, and how the build
system has evolved over the years.
¥The Chromium Embedded Framework (CEF) is a project that turns Chromium into
a library, and provides stable APIs based on Chromium's codebase. Very
early versions of Atom editor and NW.js used CEF.
¥To maintain a stable API, CEF hides all the details of Chromium
and wraps Chromium's APIs with its own interface. So when we needed to
access underlying Chromium APIs, like integrating Node.js into web pages, the
advantages of CEF became blockers.
因此,最终 Electron 和 NW.js 都切换到直接使用 Chromium 的 API。
¥So in the end both Electron and NW.js switched to using Chromium's APIs
directly.
¥Even though Chromium does not officially support outside projects, the codebase
is modular and it is easy to build a minimal browser based on Chromium. The core
module providing the browser interface is called Content Module.
¥To develop a project with Content Module, the easiest way is to build the
project as part of Chromium. This can be done by first checking out Chromium's
source code, and then adding the project to Chromium's DEPS file.
NW.js 和 Electron 的早期版本都使用这种方式进行构建。
¥NW.js and very early versions of Electron are using this way for building.
¥The downside is, Chromium is a very large codebase and requires very powerful
machines to build. For normal laptops, that can take more than 5 hours.
So this greatly impacts the number of developers that can contribute to the
project, and it also makes development slower.
作为内容模块的用户,Electron 在大多数情况下不需要修改 Chromium 的代码,因此改进 Electron 构建的一个显而易见的方法是将 Chromium 构建为共享库,然后在 Electron 中链接它。这样,开发者在为 Electron 做贡献时,就不再需要完全依赖 Chromium 进行构建。
¥As a user of Content Module, Electron does not need to modify Chromium's code
under most cases, so an obvious way to improve the building of Electron is to
build Chromium as a shared library, and then link with it in Electron. In this
way developers no longer need to build all off Chromium when contributing to
Electron.
¥The libchromiumcontent project was created by
@aroben for this purpose. It builds the Content
Module of Chromium as a shared library, and then provides Chromium's headers
and prebuilt binaries for download. The code of the initial version of
libchromiumcontent can be found in this link.
¥By using libchromiumcontent and brightray together, developers can
quickly build a browser without getting into the details of building Chromium.
And it removes the requirement of a fast network and powerful machine for building
the project.
除了 Electron 之外,还有其他基于 Chromium 的项目以这种方式构建,例如 浏览器漏洞。
¥Apart from Electron, there were also other Chromium-based projects built in this
way, like the Breach browser.
在 Windows 上,一个共享库可以导出的符号数量存在限制。随着 Chromium 代码库的增长,libchromiumcontent 中导出的符号数量很快就超出了限制。
¥On Windows there is a limitation of how many symbols one shared library can
export. As the codebase of Chromium grew, the number of symbols exported in
libchromiumcontent soon exceeded the limitation.
¥By taking this approach, though Chromium kept adding new exported symbols,
libchromiumcontent could still generate shared library files by stripping more
symbols.
¥As a huge project, the linking step takes very long in Chromium when building.
Normally when a developer makes a small change, it can take 10 minutes to see the
final output. To solve this, Chromium introduced component build, which builds
each module in Chromium as separated shared libraries, so the time spent in the
final linking step becomes unnoticeable.
¥With Chromium continuing to grow, there were so many exported symbols in
Chromium that even the symbols of Content Module and Webkit were more than the
limitation. It was impossible to generate a usable shared library by simply
stripping symbols.
¥As introduced earlier there are two build modes in Chromium. As a result of
shipping raw binaries, we have to ship two different distributions of binaries
in libchromiumcontent. One is called static_library build, which includes
all static libraries of each module generated by the normal build of Chromium.
The other is shared_library, which includes all shared libraries of each
module generated by the component build.
¥In Electron, the Debug version is linked with the shared_library version of
libchromiumcontent, because it is small to download and takes little time
when linking the final executable. And the Release version of Electron is
linked with the static_library version of libchromiumcontent, so the compiler
can generate full symbols which are important for debugging, and the linker
can do much better optimization since it knows which object files are needed
and which are not.
¥So for normal development, developers only need to build the Debug version,
which does not require a good network or powerful machine. Though the Release
version then requires much better hardware to build, it can generate better
optimized binaries.
¥Being one of the largest projects in the world, most normal systems are not
suitable for building Chromium, and the Chromium team develops their own build
tools.
早期版本的 Chromium 使用 gyp 作为构建系统,但它速度慢,而且其配置文件对于复杂项目来说难以理解。经过多年的开发,Chromium 已改用 gn 作为构建系统,它速度更快,架构更清晰。
¥Earlier versions of Chromium were using gyp as a build system, but it suffers
from being slow, and its configuration file becomes hard to understand for complex
projects. After years of development, Chromium switched to gn as a
build system, which is much faster and has a clear architecture.
¥One of the improvements of gn is to introduce source_set, which represents
a group of object files. In gyp, each module was represented by either
static_library or shared_library, and for the normal build of Chromium,
each module generated a static library and they were linked together in the
final executable. By using gn, each module now only generates a bunch of
object files, and the final executable just links all the object files together,
so the intermediate static library files are no longer generated.
¥This improvement however made great trouble to libchromiumcontent, because
the intermediate static library files were actually needed by libchromiumcontent.
第二次尝试是由 @alespergl 到 从目标文件列表生成自定义静态库 进行的。它使用了一个技巧,首先运行一个虚拟构建来收集生成的目标文件列表,然后通过将列表提供给 gn 来实际构建静态库。它只对 Chromium 的源代码进行了微小的更改,并保留了 Electron 的构建架构。
¥The second try was made by @alespergl to
produce custom static libraries from the list of object files.
It used a trick to first run a dummy build to collect a list of generated
object files, and then actually build the static libraries by feeding
gn with the list. It only made minimal changes to Chromium's source
code, and kept Electron's building architecture still.
如你所见,与将 Electron 构建为 Chromium 的一部分相比,将 Chromium 构建为库需要付出更多努力,并且需要持续维护。但是后者消除了构建 Electron 对强大硬件的要求,从而使更多开发者能够构建 Electron 并为其做出贡献。这些努力完全值得。
¥As you can see, compared to building Electron as part of Chromium, building
Chromium as a library takes greater efforts and requires continuous
maintenance. However the latter removes the requirement of powerful hardware
to build Electron, thus enabling a much larger range of developers to build and
contribute to Electron. The effort is totally worth it.
¥The WordPress.com Desktop app provides a seamless cross-platform experience that allows you to focus on your content and design with no browser tabs to distract you — or to keep your sites sidelined but accessible. In combination with our browser support and mobile app you can build your site anywhere, in whatever way helps you get your work done.
¥Why build a Desktop app for managing WordPress sites? Couldn't it all be web-based?
它实际上使用的技术与你在浏览器中访问 WordPress.com 时使用的技术完全相同。然而,它全部在本地托管,因此加载时间极短。借助原生功能(例如在 Dock 中显示、通知等),你可以真正专注于 WordPress 网站和博客。
¥It's actually using exactly the same technology you get when visiting WordPress.com in your browser. However, it's all locally hosted, so it has minimal load times. With the benefit of native features such as being in your dock, notifications, etc., you really can focus on your WordPress sites and blogging.
¥At the end of 2015 we rebuilt much of WordPress.com in the form of Calypso, an open-source modern JavaScript app using React. We started looking at Electron and with some changes to Calypso were able to get it running locally. It was a compelling experience and we thought there was a lot of value in developing it further.
¥We had several teams working on Calypso. To make a full multi-platform GUI client that matched this using traditional desktop technologies would have taken more work. By using Electron, a small team of 2-4 of us were able to leverage the other team’s efforts and build the Desktop app in a couple of months.
¥What are some challenges you've faced while building WordPress Desktop?
我们很快就让该应用的初始版本运行起来,但将其调整为桌面应用的最佳运行方式则花费了更多时间。该应用的一大挑战是你实际上是在自己的机器上运行 Calypso 的副本。 - 它纯粹是一个由 API 驱动的 UI。这其中涉及大量的衔接工作,并将更改反馈给了 Calypso 本身。
¥We got an initial version of the app running very quickly, but tuning it to behave optimally as a desktop app took a lot more time. One big challenge with the app is that you're actually running a copy of Calypso on your own machine - it’s purely an API driven UI. There was a lot of bridging work involved in this, and changes were fed back to Calypso itself.
此外,我们投入了大量精力为不同平台打包应用。 - 我们提供 Windows、macOS 和 Linux 版本 - 并且存在足够的差异,使得这个问题变得棘手。
¥Additionally a lot of effort was spent packaging the app for different platforms - we provide Windows, macOS, and Linux versions - and there are sufficient differences to make this tricky.
当时 Electron 相对较新,我们不断遇到一些问题,这些问题很快就得到了解决(有时甚至当天就能解决!)。
¥At the time Electron was relatively new and we kept running into issues that were shortly fixed (sometimes the same day!)
Electron 已经提供了我们桌面应用所需的大部分功能,并且自我们开始使用它以来,它一直在快速发展。话虽如此,桌面应用中有些功能是理所当然的,例如拼写检查和查找/替换,在 Electron 中很难照搬。
¥Electron already provides most of what we need for the Desktop app, and it's progressed rapidly since we started using it. That said, there are some areas that are taken for granted in a desktop app, such as spell checking and find/replace, that are harder to replicate with Electron as-is.
我们也希望看到一些较新的 Chrome 技术也能融入到 Electron 中。我们尤其热衷于尝试 WebVR。
¥We’d also love to see some of the newer Chrome technologies filtering down into Electron too. We’re particularly keen on experimenting with WebVR.
我们选择 Electron 的主要原因,也是它最大的优势,是其非常活跃和开放的社区。Automattic 始终坚信开源。这是我们的核心原则之一,Electron 项目和社区也遵循许多非常开放和积极的核心信念。
¥The main reason we chose Electron, and it's biggest strength, is the very active and open community. Automattic has always believed in open source. It is one of our core tenets, and the Electron project and community follows a lot of the core beliefs of being very open and positive.
¥The great thing about our model is that the Desktop app benefits from any new Calypso feature - there are constant improvements. We’re hoping we can add additional features to the app such as offline support, which would really take the app into native territory, and better system notifications.
¥Are there any teams at Automattic working on other Electron apps?
是的,在我们努力开发桌面应用之后,Simplenote 团队决定使用 Electron 构建适用于 Windows 和 Linux 的桌面应用(原生 Mac 客户端已存在)。Simplenote Electron 应用 也是开源的,可在 Github 上获取。
¥Yes, after our efforts on the Desktop app, the Simplenote team decided to use Electron to build desktop apps for Windows and Linux (a native Mac client already exists). The Simplenote Electron app is also open source and available on Github.
我们还即将推出使用 Electron 的 Raspberry Pi 集成。
¥We've also got an upcoming Raspberry Pi integration that uses Electron.
¥Any Electron tips that might be useful to other developers?
发布已签名桌面软件的过程对我们来说相对较新,尤其是在 Windows 平台上。我们为 Windows 应用代码签名 撰写了一篇文章,其中包含了整个过程以及我们为了做好这项工作所遇到的一些困难。
¥The process of shipping signed desktop software is relatively new to us, especially for Windows. we wrote up an article for Code Signing a Windows App which includes the process and a few of the hurdles we went through to do it right.
¥This week's featured project is Dat, a
grant-funded, open source, decentralized tool
for distributing data sets. Dat is built and maintained by a
geodistributed team, many of whom helped
write this post.
¥We wanted to bring the best parts of peer to peer and distributed systems to data sharing. We started with scientific data sharing and then began branching out into research institutions, government, public service, and open source teams as well.
另一种思考方式是将其想象成一个同步和上传应用,例如 Dropbox 或 BitTorrent Sync,只不过 Dat 是 开源。我们的目标是成为一款功能强大、开源、非盈利的数据共享软件,适用于大数据、小型数据、中型数据、小批量数据和大批量数据。
¥Another way to think about it is a sync and upload app like Dropbox or BitTorrent Sync, except Dat is open source. Our goal is to be a a powerful, open source, non-profit data sharing software for big, small, medium, small-batch and big-batch data.
要使用 dat CLI 工具,你只需输入以下内容:
¥To use the dat CLI tool, all you have to type is:
dat share path/to/my/folder
dat 将创建一个链接,你可以使用该链接将该文件夹发送给其他人 - 任何中央服务器或第三方都无法访问你的数据。与 BitTorrent 不同,它也无法嗅探谁在共享什么内容 (查看 Dat Paper 草稿了解更多详情)。
¥And dat will create a link that you can use to send that folder to someone else -- no central servers or third parties get access to your data. Unlike BitTorrent, it's also impossible to sniff who is sharing what (see the Dat Paper draft for more details).
¥Now we know what Dat is. How does Dat Desktop fit in?
Dat 桌面 是一种让无法或不愿使用命令行的人也能访问 Dat 的方法。你可以在你的机器上托管多个数据,并通过网络提供数据。
¥Dat Desktop is a way to make Dat accessible to people who can't or don't want to use the command line. You can host multiple dats on your machine and serve the data over your network.
我们正在开发一个代号为 Svalbard 项目 的项目,它与 DataRefuge 相关,DataRefuge 是一个致力于备份濒临消失的政府气候数据的小组。“斯瓦尔巴群岛”以位于北极的斯瓦尔巴全球种子库命名,该种子库拥有一个大型地下植物 DNA 备份库。我们的版本是一个大型的公共科学数据集的版本控制集合。一旦我们了解并信任元数据,我们就可以构建其他很酷的项目,例如 分布式志愿者数据存储网络。
¥We're working on a thing codenamed Project Svalbard that is related to DataRefuge, a group working to back up government climate data at risk of disappearing. Svalbard is named after the Svalbard Global Seed Vault in the Arctic which has a big underground backup library of plant DNA. Our version of it is a big version controlled collection of public scientific datasets. Once we know and can trust the metadata, we can build other cool projects like a distributed volunteer data storage network.
CACivicData 是一个开源档案库,提供从加州政治资金追踪数据库 CAL-ACCESS 的每日下载。它们使用 每日发布,这意味着它们的 zip 文件中会包含大量重复数据。我们正在努力将他们的数据托管为 Dat 存储库,这将减少引用特定版本或更新到新版本所需的麻烦和带宽。
¥CACivicData is an open-source archive serving up daily downloads from CAL-ACCESS, California's database tracking money in politics. They do daily releases, which means hosting a lot of duplicate data across their zip files. We're working on hosting their data as a Dat repository which will reduce the amount of hassle and bandwidth needed to refer to specific version or update to a newer version.
这一点目前尚未具体化,但我们认为一个有趣的用例是将编译好的 Electron 应用放入 Dat 仓库中,然后使用 Electron 中的 Dat 客户端拉取构建应用二进制文件的最新增量版本,以节省下载时间,同时也降低服务器的带宽成本。
¥This one isn't concrete yet, but we think a fun use case would be putting a compiled Electron app in a Dat repository, then using a Dat client in Electron to pull the latest deltas of the built app binary, to save on download time but also to reduce bandwidth costs for the server.
¥Anyone who wants to share and update data over a p2p network. Data scientists, open data hackers, researchers, developers. We're super receptive to feedback if anyone has a cool use case we haven't thought of yet. You can drop by our Gitter Chat and ask us anything!
用户账户和元数据发布。我们正在开发一个 Dat 注册表 Web 应用,该应用将部署在 datproject.org,本质上相当于 '用于数据集的 NPM',但需要注意的是,我们只是将其作为元数据目录,数据可以存储在任何在线位置(这与 NPM 或 GitHub 不同,因为 NPM 或 GitHub 将所有数据都集中托管,因为源代码足够小,你可以将所有数据都放在一个系统中)。由于许多数据集非常庞大,我们需要一个联合注册表(类似于 BitTorrent 追踪器的工作方式)。我们希望人们能够轻松地使用 Dat Desktop 中的注册表查找或发布数据集,从而使数据共享过程顺畅无阻。
¥User accounts and metadata publishing. We are working on a Dat registry web app to be deployed at datproject.org which will basically be an 'NPM for datasets', except the caveat being we are just going to be a metadata directory and the data can live anywhere online (as opposed to NPM or GitHub where all the data is centrally hosted, because source code is small enough you can fit it all in one system). Since many datasets are huge, we need a federated registry (similar to how BitTorrent trackers work). We want to make it easy for people to find or publish datasets with the registry from Dat Desktop, to make the data sharing process frictionless.
¥Another feature is multi-writer/collaborative folders. We have big plans to do collaborative workflows, maybe with branches, similar to git, except designed around dataset collaboration. But we're still working on overall stability and standardizing our protocols right now!
¥Why did you choose to build Dat Desktop on Electron?
Dat 使用 Node.js 构建,因此非常适合我们的集成。除此之外,由于科学家、研究人员和政府官员可能被迫为其机构使用某些设置,因此我们的用户使用各种各样的机器 - 这意味着我们需要能够针对 Windows、Linux 和 Mac 进行开发。Dat Desktop 让我们轻松实现了这一点。
¥Dat is built using Node.js, so it was a natural fit for our integration. Beyond this, our users use a variety of machines
since scientists, researchers and government officials may be forced to use certain setups for their institutions -- this means we need to be able to target Windows and Linux as well as Mac. Dat Desktop gives us that quite easily.
¥Figuring out what people want. We started with tabular datasets, but we realized that it was a bit of a complicated problem to solve and that most people don't use databases. So half way through the project, we redesigned everything from scratch to use a filesystem and haven't looked back.
我们也遇到了一些常见的 Electron 基础设施问题,包括:
¥We also ran into some general Electron infrastructure problems, including:
遥测 - 如何捕获匿名使用情况统计信息
¥Telemetry - how to capture anonymous usage statistics
更新 - 设置自动更新有点零碎,但很神奇。
¥Updates - It's kind of piecemeal and magic to set up automatic updates
¥We also use Browserify and some cool Browserify Transforms on the 'front end' code in Dat Desktop (which is kind of weird because we still bundle even though we have native require -- but it's because we want the Transforms). To better help manage our CSS we switched from Sass to using sheetify. It's greatly helped us modularize our CSS and made it easier to move our UI to a component oriented architecture with shared dependencies. For example dat-colors contains all of our colors and is shared between all our projects.
我们一直是标准和极简抽象的忠实拥护者。我们的整个界面使用常规 DOM 节点和一些辅助库构建。我们已经开始将其中一些组件迁移到 base-elements,这是一个底层可复用组件库。与我们的大多数技术一样,我们不断迭代,直到完美为止,但作为一个团队,我们感觉我们正朝着正确的方向前进。
¥We've always been a big fan of standards and minimal abstractions. Our whole interface is built using regular DOM nodes with just a few helper libraries. We've started to move some of these components into base-elements, a library of low-level reusable components. As with most of our technology we keep iterating on it until we get it right, but as a team we have a feeling we're heading in the right direction here.
我们认为最大的痛点是原生模块。必须使用 npm 为 Electron 重新构建模块会增加工作流程的复杂性。我们的团队开发了一个名为 prebuild 的模块,用于处理预构建的二进制文件,该模块在 Node 上运行良好,但 Electron 工作流程在安装后仍然需要自定义步骤,通常是 npm run rebuild。之前有点烦人。为了解决这个问题,我们最近改用了一种策略,将所有平台的所有编译二进制版本都打包到 npm tarball 中。这意味着 tarball 会变得更大(尽管可以使用 .so 文件(共享库)进行优化),这种方法避免了运行安装后脚本,也完全避免了 npm run rebuild 模式。这意味着 npm install 第一次就为 Electron 做了正确的事。
¥We think the biggest pain point is native modules. Having to rebuild your modules for Electron with npm adds complexity to the workflow. Our team developed a module called prebuild which handles pre-built binaries, which worked well for Node, but Electron workflows still required a custom step after installing, usually npm run rebuild. It was annoying. To address this we recently switched to a strategy where we bundle all compiled binary versions of all platforms inside the npm tarball. This means tarballs get larger (though this can be optimized with .so files - shared libraries), this approach avoids having to run post-install scripts and also avoids the npm run rebuild pattern completely. It means npm install does the right thing for Electron the first time.
这些 API 似乎经过深思熟虑,相对稳定,并且能够很好地与上游 Node 版本保持同步,除此之外,我们没什么可要求的了!
¥The APIs seem fairly well thought out, it's relatively stable, and it does a pretty good job at keeping up to date with upstream Node releases, not much else we can ask for!
¥This week we chatted with Felix Rieseberg, desktop engineer at Slack and maintainer of Ghost Desktop, an Electron client for the Ghost publishing platform.
¥Ghost is a fully open source, hackable platform for building and running a modern online publication. We power blogs, magazines and journalists from Zappos to Sky News.
¥Ghost was founded in April 2013, after a very successful Kickstarter campaign to create a new platform focused solely on professional publishing. Our mission is to create the best open source tools for independent journalists and writers across the world, and have a real impact on the future of online media. It offers a simpler, more focussed experience: Our editor is designed solely around providing the best possible writing experience.
¥Compared to the all-time classic WordPress, it offers a simpler, more streamlined experience - it is easier to setup and maintain, comes with all important features out-of-the-box, and is dramatically faster. Compared to other online platforms, Ghost gives writers full ownership and control over their content, allows full customization, and enables authors to build a business around their publication.
¥This one is important to us: Ghost is an independent non-profit organisation. We build publishing tools for modern journalism & blogging because we believe freedom of speech is important. Our software is released under a free open source license, our business model is completely transparent, and our legal structure means that 100% of the money we make is reinvested into making Ghost better.
¥Ghost Desktop allows writers to manage multiple blogs at once - and to focus on their writing. Simple things like common writing shortcuts can't be realized in a browser, but are available in our desktop app. It allows other applications to communicate directly with the blog via deeplinks.
¥This year we're very excited to be dedicating our entire 10 person full-time Ghost team to helping grow three independent publications, along with $45,000 in resources toward their efforts. We're calling it Ghost for Journalism.
¥We've been building Ghost as the web's next great platform for independent publishers for about three and half years now, and we've now reached a really interesting inflection point. We started this journey to create a simple, well designed blogging platform which could be used by just about anyone. That was always going to be step one.
¥Long term, we want Ghost to be an incredible platform for the world's best journalism, and that means we need to build features to attract exactly those people. This year we're making a very conscious decision to focus on just that.
¥Ghost uses JavaScript and Node.js on both the backend and frontend, so being able to utilize the same technology and skillset enables our team to move faster, build more, and ultimately deliver a better experience. In addition, being able to share more than 95% of code between the macOS, Windows, and Linux version of the app allows us to focus on building a great core user experience, without having to maintain one code base for each platform.
¥Spellchecking is likely still one of the most difficult services offered - we could easily utilize one of the many online services, but correctly spellchecking text in multiple languages while guarding the privacy and autonomy of our users is not an easy task.
我们希望 Electron 能够将操作系统原生的拼写检查功能引入到他们的应用中。我们梦想着 <input> 字段能够获得与 NSTextView 字段相同的服务,但我们也深知这有多么困难。
¥We would love to see Electron bring the operating system's native spellchecking capabilities to their apps. We're dreaming about a world in which an <input> field receives the same services as a NSTextView, but we are also intimately aware how difficult that is.
JavaScript 以其庞大的生态系统而闻名,涉及无数的工具和框架。 - 但它给我们带来的便利是无可厚非的。使用 Electron 构建应用仅比构建 Web 应用稍微难一点,这是一个了不起的成就。
¥JavaScript is famous for being a vast ecosystem, involving countless tools and frameworks - but the convenience it affords us is hard to overstate. Building an app with Electron is only slightly harder than building a web app, which is an amazing feat.
Ghost Desktop 也是一个正在进行的项目 - 我们离完成还很远。我们一直在讨论为用户提供完全离线模式,现在距离这个目标已经很近了。其他值得注意的工作字段包括扩展和与其他文本编辑应用(如 Word 或 Atom)的集成,最终允许人们使用他们喜欢的工具撰写文章。总体而言,一旦我们发布了离线模式功能,我们就会寻求与操作系统更深入的集成。如果你对此感兴趣,加入我们!
¥Ghost Desktop is also an ongoing project - we're pretty far from being done. We have been talking for a while about bringing a full offline mode to our users, and we're getting fairly close. Other notable work areas are the extension and integration with other text editing apps (like Word or Atom), ultimately allowing people to write posts using their favorite tools. In general, once we've shipped the offline mode feature, we're looking for deeper integration with the operating system. If that sounds interesting to you, join us!
本周,我们采访了 烧杯浏览器 的创建者 Paul Frazee。Beaker 是一款实验性的点对点网络浏览器,它使用 Dat 协议在用户的设备上托管网站。
¥This week we caught up with Paul Frazee, creator
of Beaker Browser. Beaker is an experimental
peer-to-peer web browser that uses the Dat protocol to host sites from users’
devices.
¥Beaker is a participatory browser. It's a browser for indie hackers.
Web 是闭源的。如果你想影响社交媒体的运作方式,你就必须在 Facebook 或 Twitter 上工作。搜索请见 Google。控制权掌握在公司手中,而不是用户自己。
¥The Web is closed source. If you want to influence how social media works, you have to work at Facebook or Twitter. For search, Google. Control is in the hands of companies, rather than the users themselves.
有了 Beaker,我们有了一个新的 Web 协议:去中心化归档传输。"日期。" 可以按需免费创建网站,然后从设备共享。无需服务器。这就是我们的创新。
¥With Beaker, we have a new Web protocol: the Decentralized Archive Transport. "Dat." It creates sites on demand, for free, and then shares them from the device. No servers required. That's our innovation.
当你在 Beaker 中访问 Dat 站点时,你会下载这些文件。网站永远属于你。你可以免费保存、分叉、修改和分享你的新版本。完全开源。
¥When you visit a Dat site in Beaker, you download the files. The site is yours, forever. You can save it, fork it, modify it, and share your new version for free. It's all open-source.
这就是它的意义所在:我们正在为开源网站开发一款浏览器。我们希望它成为社交黑客的工具包。
¥So that's what it's about: We're making a browser for open-source Websites. We want it to be a toolkit for social hacking.
$ bkr fork dat://0ff7d4c7644d0aa19914247dc5dbf502d6a02ea89a5145e7b178d57db00504cd/ ~/my-fork $ cd ~/my-fork $ echo "My fork has no regard for the previous index.html!" > index.html $ bkr publish
¥If you want a GUI, we have some basic tools built into the browser, but we're pushing those tools into userland. It's all going to be moddable user apps.
对于这个项目来说,这一点显而易见。如果我自己 fork Chrome,我现在就会写 C++ 了!没人愿意这样做。我了解 Web 技术栈,并且可以快速上手。这很简单。
¥It was obvious for this project. If I forked Chrome myself, I'd be writing C++ right now! Nobody wants to do that. I know the Web stack, and I can work quickly with it. It's a no-brainer.
事实上,如果没有 Electron,我不确定我能做到这些。这是一款很棒的软件。
¥The truth is, I'm not sure I could do any of this without Electron. It's a great piece of software.
¥Making the browser itself was pretty easy. Electron is practically a toolkit for making browsers. ...Except for the browser tabs; that took me forever to get right. I finally broke down and learned how to do SVGs. It's much better looking, but it took 3 or 4 iterations before I got that right.
¥We have lots of open issues. Don't be afraid to ping me. #beakerbrowser on freenode. We keep a page for contributors and we'll add you to it. And if you visit Austin, I'll buy you a beer.
¥Use the build tooling that's out there. You don't want to wrestle with your own solutions, trust me. Use electron-builder. Use a boilerplate repo.
如果你需要在 Electron 代码库中提交问题,请多加留意,以便轻松复现。你将更快地收到回复,团队将对此表示感谢。更好的是,尝试自行修复。看到它的内部结构其实很有趣。
¥If you need to open an issue in the Electron repo, go the extra mile to make it easy to reproduce. You'll get a response much more quickly, and the team will appreciate it. Even better, try fixing it yourself. It's actually pretty interesting to see the innards.
请至少通读一遍所有指南和高级文档。
¥Read through all the guides and advanced docs at least once.
Electron 社区正在快速发展,人们正在以惊人的速度创建强大的新应用和工具。为了庆祝这一创新势头,并让社区了解一些新项目,我们决定开设一个每周博客系列,介绍值得关注的 Electron 相关项目。
¥The Electron community is growing quickly, and people are creating powerful
new apps and tools at an astounding rate. To celebrate this creative momentum
and keep the community informed of some of these new projects, we've decided to
start a weekly blog series featuring noteworthy Electron-related projects.
¥This post is the first in the series, and features Kap,
an open-source screen recording app built by Wulkano,
a geodistributed team of freelance designers and developers.
Kap 是一款开源屏幕录像机 主要为设计师和开发者构建,方便他们轻松捕捉工作成果。人们使用它来分享动画原型、记录错误、创建有趣的 GIF 以及介于两者之间的一切。
¥Kap is an open-source screen recorder built primarily for designers and developers to easily capture their work. People use it to share animated prototypes, document bugs, create silly GIFs and everything in-between.
¥We've seen people of all ages and backgrounds use it in educational settings, screencasts, tutorials... the list goes on. Even to create production assets! We're completely blown away by how well received our little side project has been.
这个问题问得好,毕竟现在也不缺屏幕录像机!我们认为其他替代方案要么过于复杂、成本过高,要么功能过于有限。没有什么感觉恰到好处,可以满足我们的日常需求。我们也认为,我们工作中使用的工具开源是一件很棒的事情,这样每个人都可以帮助改进它们。构建 Kap 最终与我们没有做的事情一样重要。一切都在于细节,一些小改进的积累,最终形成了我们想要使用的工具的轮廓。
¥That's a very good question, it's not like there's a lack of screen recorders out there! We felt the alternatives were either too complex, too expensive or too limited. Nothing felt just right for our everyday needs. We also think it's great when the tools we use to do our work are open-source, that way everyone can help shape them. Building Kap ended up being just as much about what we didn't do. It's all in the details, an accumulation of small improvements that became the outline of a tool we wanted to use.
¥However, and maybe most importantly, Kap has become a place for us to leave our worries at the door and just have fun building something for ourselves and people like us. It's so important to create an environment where you get to just vent, try new thins and enjoy your craft. No requirements, no pressure, no expectations. Should designers and developers side project? Why, yes. Yes, they should.
¥The power and easily maintainable modularity of node_modules
跨平台可能性
¥Cross-platform possibilities
我们认为应用的未来在于浏览器,但我们还没有完全实现这一目标。Electron 是迈向未来的重要一步。它不仅使应用本身更易于访问,也使构建它们的代码更易于访问。一个有趣的想法是设想未来操作系统就是浏览器,而标签页本质上就是 Electron 应用。
¥We think the future of apps are in the browser, but we're not quite there yet. Electron is an important step in the journey towards that future. It not only makes the apps themselves more accessible, but also the code they're built with. An interesting thought is imagining a future where the OS is a browser, and the tabs are essentially Electron apps.
此外,作为 Web 开发者,我们非常欣赏 JavaScript 的同构特性,因为 JS 可以在客户端、服务器以及现在的桌面上运行。使用 Web 技术(HTML、CSS 和 JS),很多事情比原生技术简单得多:更快的原型设计,更少的代码,弹性框 > 自动布局(macOS/iOS)。
¥Additionally, being primarily web developers, we're big fans of the isomorphic nature of JavaScript, in that you can run JS on the client, server, and now the desktop. With web tech (HTML, CSS and JS), many things are much simpler than native: Faster prototyping, less code, flexbox > auto-layout (macOS/iOS).
¥What are some challenges you've faced while building Kap?
利用 Electron 可用的资源来录制屏幕是最大的挑战。它们的性能不足以满足我们的要求,在我们看来,这会使项目失败。虽然 Electron 本身没有问题,但在原生开发和使用 Web 技术构建桌面应用之间仍然存在差距。
¥Using the resources Electron has available to record the screen was the biggest challenge. They simply weren't performant enough to meet our requirements and would render the project a failure in our eyes. Though at no fault of Electron itself, there's still a gap between native development and building desktop apps with web tech.
我们花了大量时间尝试解决 getUserMedia API 性能不佳的问题,这个问题源于 Chromium。我们着手开发 Kap 时的主要目标之一是使用 Web 技术构建整个应用。在尝试了所有方法使其正常运行之后(最低要求是在 Retina 屏幕上达到 30 FPS),我们最终不得不寻找其他解决方案。
¥We spent a lot of time trying to work around the poor performance of the getUserMedia API, an issue originating in Chromium. One of our main goals when we set out to make Kap was to build the entire app with web tech. After trying everything we could to get it working (the minimum requirement being 30 FPS on a Retina screen), we eventually had to find another solution.
¥I see some Swift code in the repo. What's that about?
被迫寻找 getUserMedia 的替代方案,我们开始尝试 ffmpeg。除了是最好的音频和视频转换工具之一之外,它还具有在几乎所有操作系统中录制屏幕的功能,并且我们能够在 Retina 屏幕上录制出清晰的视频,满足我们最低 30 FPS 的要求。有问题吗?性能方面,"😩" 的 CPU 占用率一度飙升。因此,我们重新开始,讨论了各种方案,并意识到必须做出妥协。这促成了 Aperture 的诞生,这是我们用 Swift 编写的 macOS 屏幕录制库。
¥Being forced to look for alternatives to getUserMedia, we started experimenting with ffmpeg. Besides being one of the best tools for audio and video conversion it has the functionality of recording the screen in almost any OS, and we were able to record crispy video meeting our minimum requirement of 30 FPS on a Retina screen. Problem? The performance was "😩", the CPU usage was going haywire. So we went back to the drawing board, discussed our options and realised that we had to make a compromise. That resulted in Aperture, our own screen recording library for macOS written in Swift.
我们都知道 Electron 应用可能会占用大量内存,但这其实是 Chromium 的问题。这是它工作方式的一部分,实际上取决于你运行的是什么,例如 Kap 和 Hyper 通常占用不到 100MB 的内存。
¥We all know that Electron apps can have a thing for using RAM, but again, that's really a Chromium thing. It's part of how it works and it really depends on what you're running, for example Kap and Hyper typically use less than 100MB of memory.
我们看到的最大改进字段之一是负载,尤其是 Electron 分发 Chromium 的方式。一个想法是使用共享的 Electron 核心,并让应用安装程序检查它是否已存在于系统中。
¥One of the biggest areas of improvement that we see is payload, particularly how Electron distributes Chromium. One idea would be to have a shared Electron core and make app installers check if it's already present on the system.
创建跨平台 Electron 应用可能会提供更佳体验。目前,平台之间存在太多不一致、平台特定 API 以及功能缺失的问题,导致你的代码库充斥着 if-else 语句。例如,vibrancy 仅在 macOS 上受支持,自动更新程序在 macOS 和 Windows 上的运行方式不同,甚至在 Linux 上也不受支持。在 Linux 上,透明度有时好有时坏,通常都不好。
¥Creating cross-platform Electron apps could be a better experience. Right now there are too many inconsistencies, platform-specific APIs, and missing features between platforms, making your codebase littered with if-else statements. For example, vibrancy is only supported on macOS, the auto-updater works differently on macOS and Windows, and is not even supported on Linux. Transparency is a hit or miss on Linux, usually miss.
调用原生系统 API 也应该更容易。Electron 提供了一套非常优秀的 API,但有时你需要它未提供的功能。创建原生 Node.js 插件是一种选择,但使用起来很麻烦。理想情况下,Electron 应该附带一个良好的 FFI API,例如 fastcall。这样我们就可以用 JavaScript 编写 Swift 部分了。
¥It should also be easier to call native system APIs. Electron comes with a very good set of APIs, but sometimes you need functionality it doesn't provide. Creating a native Node.js addon is an option, but it's painful to work with. Ideally Electron would ship with a good FFI API, like fastcall. This would have enabled us to write the Swift part in JavaScript instead.
我们最喜欢的一点是,任何具备 Web 创作知识的人都可以构建并为多平台原生体验做出贡献。更不用说在其上进行开发的轻松和乐趣、优秀的文档和蓬勃发展的生态系统。
¥Our favorite thing is easily the fact that anyone with knowledge of creating for the web can build and contribute to multi-platform native experiences. Not to mention the ease and joy of developing on it, the excellent documentation and the thriving ecosystem.
从前端的角度来看,构建 Kap 与使用浏览器 API 构建一个简单的网站没有什么不同。Electron 在使应用开发与 Web 开发相似(基本相同)方面做得非常出色。实际上非常简单,我们不需要框架或类似的东西来帮助我们,只需要简洁且模块化的 JS 和 CSS。
¥From a front-end perspective, building Kap felt no different than building a simple website using browser APIs. Electron does a really great job of making app development similar (basically identical) to web development. So simple in fact that there was no need for frameworks or similar to help us, just clean and modular JS and CSS.
我们的下一步是审查该应用,为 2.0.0 里程碑版本做准备,该版本除了支持插件外,还包含 React 重写,允许开发者扩展 Kap 的功能!我们诚邀大家关注我们的 GitHub 代码库 项目并为其做出贡献。让我们知道如何让 Kap 成为最适合你的工具,我们倾听并希望听到尽可能多的你们的声音!
¥The next step for us is to review the app in preparation for our 2.0.0 milestone, which includes a React re-write in addition to support for plugins, allowing developers to extend the functionality of Kap! We invite everyone to follow to project and contribute on our GitHub repository. We're listening and want to hear from as many of you as possible, let us know how we can make Kap the best possible tool it can be for you!
Wulkano 是一个设计工作室和数字集体,由一群热爱远程工作的技术人员组成,他们既喜欢为客户工作,也喜欢在自己的项目上合作。我们是一个分散但紧密联系的群体,来自不同地方,拥有不同的背景。在我们的虚拟办公室(恰好是基于 Electron 的 Slack!),我们分享知识、想法、经验,但最重要的是分享一些搞笑的 GIF 和表情包。
¥Wulkano is a design studio and digital collective, a team of remote technologists who love working together on both client gigs and our own projects. We're a distributed but tight knit group of people from different places and backgrounds, sharing knowledge, ideas, experiences, but most importantly silly GIFs and memes, in our virtual office (which happens to be the Electron based Slack!).