Catalog / Electron Cheat Sheet
Electron Cheat Sheet
A comprehensive cheat sheet for building cross-platform desktop applications with Electron.
Core Concepts
Electron Architecture
Electron combines Chromium and Node.js to create desktop applications using web technologies (HTML, CSS, JavaScript). It consists of two main processes: the Main Process and the Renderer Process. |
Main Process
Description: |
Controls the application lifecycle, creates and manages browser windows, and handles native OS interactions. |
Responsibilities: |
Creating menus, dialogs, registering global shortcuts. |
Entry Point: |
|
Modules: |
|
Renderer Process
Description: |
Handles the application’s UI. Each browser window runs in its own renderer process. |
Responsibilities: |
Rendering HTML, CSS, JavaScript. Interacting with the DOM. |
Modules: |
|
Inter-Process Communication (IPC)
Used for communication between the Main and Renderer processes. Example:
|
Essential Modules & APIs
App Module
|
Emitted when Electron has finished initializing and is ready to create browser windows. |
|
Quits the application. |
|
Gets a path to a special directory or file (e.g., ‘userData’, ‘temp’). |
|
Returns the application version from |
BrowserWindow Module
|
Creates a new browser window. |
|
Loads a URL into the window. |
|
Loads a local HTML file into the window. |
|
Opens the DevTools. |
|
Closes the window. |
Menu Module
|
Creates a menu from a template array. |
|
Sets the application menu. |
Menu Template |
Defines the structure of the menu (labels, roles, submenus). |
Working with Files and Dialogs
Dialog Module
|
Displays an open dialog to select files or directories. |
|
Displays a save dialog to choose a file path. |
|
Displays a message box. |
Options |
title, defaultPath, button labels, filters (for file types) |
File System Access
Use Node.js’s |
Example:
|
Context Menu
Context menus can be added with Example using electron-context-menu:
|
Packaging and Distribution
Electron Forge
A comprehensive tool for packaging and distributing Electron applications. Install:
Create a new project:
Package:
Make (create distributable):
|
Electron Builder
Another popular tool for packaging Electron applications. Install:
Configuration in
Package:
|
Code Signing
Important for distributing applications on macOS and Windows. Use appropriate certificates for each platform. |