Concise plain-speak about Electron.
Background |
---|
What is Electron? |
Why is this important? |
How, even? |
What is developing like? |
Development |
---|
Prereqs |
Two Processes |
Main Process |
Renderer Process |
Think of it like this |
Development Cont'd |
---|
Stay in touch |
Put it all together |
Quick start |
Packaging |
More resources |
Read this in Chinese Japanese.
Electron is a library you can use to build desktop applications with JavaScript, HTML and CSS. These applications can be packaged to run on Mac, Windows and Linux computers as well as be placed in the Mac and Windows app stores.
Next: Why is this important?
- JavaScript, HTML and CSS Are web languages, meaning they are the building blocks of websites and browsers like Chrome know how to turn this code into the visual graphics you see.
- Electron is a library Electron is code that you can re-use and not have to write yourself. You use it to build your project on top of.
- Apps built on Electron
- Electron API Demos (see what you can do with Electron)
Typically, desktop applications for each operating system are written in each's native language. That can mean having three teams writing three versions of your app. Electron enables you to write your app once and with web languages.
Next: How, even?
- native (operating system) language These are languages that the major operating systems are (mostly) built with: Mac, Objective C; Linux, C; Windows, C++.
Electron combines Chromium and Node.js with a set of custom APIs for native operating system functions like open file dialogs, notifications, icons and more.
Next: What is developing like?
- API Application Program Interface describes the set of functions made available for you to use a library with.
- Chromium Created by Google, this is the open source library used by Google's browser Chrome.
- Node.js (or Node) A tool for writing JavaScript on servers, accessing filesystems and networks (your computer is also a server!).
Developing with Electron is like building web pages that you can seamlessly use Node in—or building a Node app in which you can build an interface with HTML and CSS. And you only need to design for one browser, the latest Chrome.
Next: Prereqs
- Use Node in That's not all! In addition to the full Node API everywhere, you can make use of the over 300,000 modules already written and hosted on npm, a package manager for Node.
- One browser Not all browsers are the same and web designers and developers often have to go the extra mile to make one site look the same on each.
- Latest Chrome Use over 90% of ES2015, the latest updates to JavaScript, as well as cool features like CSS Variables.
- Can I Use? (see what each browser supports)
- Updates to Chrome (Chromium Blog)
- CSS Variables
Since Electron's two components are websites and JavaScript, you'll need experience in both of those before you begin. Check out some tutorials on HTML, CSS and JS and install Node on your computer.
- Let's be real, learning to make websites and write Node are not overnight things but hopefully the links below can get you started.
Next: Two Processes
- Install Node (chose the LTS version)
- NodeSchool Tutorials (try learnyounode)
- JS for Cats (by Max Ogden)
- Learn to Code HTML & CSS (by Shay Howe)
- CSS Tricks (learn CSS best practices and tips)
- Mozilla Developer Network (like a dictionary for websites and JavaScript)
Electron has two types of processes: Main and Renderer. There are modules that work on each or in both of the processes. The main process is more behind-the-scenes while the renderer process is each of the windows in your app.
- Modules Electron's APIs are grouped together based on what they do. For instance the
dialog
module has all the APIs for native dialogs like open file, save file and alerts.
Next: Main Process
The main process, commonly a file named main.js
, is the entry point to every Electron app. It controls the life of the app, from open to close. It also calls the native elements and creates each new renderer process in the app. The full Node API is built in.
- Calls the native elements Opening dialogs and other native operating system interactions are resource intensive so it's done in the main process, leaving the renderer process uninterrupted.
Next: Renderer Process
The renderer process is a browser window in your app. Unlike the main process, there can be multiple of these and each is independent. They can also be hidden. Usually one is named index.html
. They're like typical HTML files but in Electron you've got the whole Node API available here, too, unlike any web browser.
- Each is independent every renderer process is a separate process, meaning a crash in one won't affect another.
- Hidden You can set a window to be hidden and use it to just execute code in the background.
Next: Think of it like this
In Chrome (or another web browser) each tab and its web page is like a single renderer process in Electron. If you close all of the tabs, Chrome is still there, this is like your main process, and you can open a new window or quit the app.
Next: Stay in touch
The main and renderer processes need to be able to communicate since they're both responsible for different tasks. For that there's IPC, interprocess communication. Use it to pass messages between main and renderer processes.
- IPC The main process and renderer process each have an IPC module to use.
Next: Put it all together
Electron apps are like Node apps and use a package.json
file. It's there that you define which file is your main process and thus where Electron should start your app. Then that main process can create renderer processes and you'll use IPC to pass messages between the two.
package.json
file This is a common file in Node apps which contains metadata about the project and a list of dependencies.
Next: Quick start
The Electron Quick Start repository is a bare-bones Electron app with the package.json
, main.js
and index.html
you've learned about here—a great place to get started! Also, check out the boilerplates for templates with your framework of choice.
Next: Packaging
Once your app is built, you can package it with the command-line tool electron-packager
for Mac, Windows or Linux. Add scripts for this to your package.json
. Check out resources below for getting your app in the Mac and Windows app stores.
Next: More resources
- command-line tool This is a program that you interact with by passing commands to it in your terminal.
- electron-packager
- Electron API Demos packaging scripts
- Mac App Store Electron Guide
- Windows App Store Electron Guide
The concepts here will get you pretty far, but there is of course more so here are other resources.
- Full Electron docs
- Awesome Electron: tools, videos, components, meetups
- Spectron (Electron testing library)
- Devtron (Inspect your Electron app)