electron-boilerplate
Most Electron apps have the same boilerplate code for their main process. This module is an attempt to provide reusable main process code via a plugin architecture.
For example, with the following code in your main Electron entry point:
const ElectronBoilerplate = ; ElectronBoilerplate ;
The standard configuration automatically:
- Looks in a couple of places for
index.html
if it wasn't provided - Sets the UserModelId from the
userModelId
property inpackage.json
or a reasonably sensible default - When not in dev mode, sets a minimal menu on macOS and removes the menu on Windows and Linux
- Persists the position and dimensions of BrowserWindows
- Ensures BrowserWindows are not created on displays that are have been disconnected since last run
- Ensures a single instance, caters for the Mac
open-file
event and notifies the renderer of new instances - Adds hooks so protocol client handlers and global keyboard shortcuts can be registered form the renderer
- Adds a hook so files can be dragged out of the renderer into Explorer/Finder
- Prevents Ctrl+Click (Cmd+Click on Mac) on links from opening new BrowserWindows
- Prevents Electron from opening files that are dropped into BrowserWindows
- Prevents keyboard/mouse/trackpad/touchscreen from zooming in BrowserWindows
- Starts the main BrowserWindow
- Offers a shortcut for opening modal BrowserWindows from the renderer or main process
Alternatively, you can selectively enable the built in features you require via use
or call standardConfiguration
and override the defaults using use
and remove
.
const ElectronBoilerplate BuiltIn = ; const ourMenu = ; ElectronBoilerplate // Use a specific menu // Specify default dimensions // Remove this plugin as want to allow zooming ; // Run optionally takes BrowserWindowOptions param
These features are built on a common API so you can create your own reusable plugins. See the base monorepository for details of the plugin API.
There are currently two additional plugins which can be installed separately:
- @electron-boilerplate/titlebar - Renders color titlebars on Windows and macOS
- @electron-boilerplate/sentry - JavaScript and native crash reporting using
elctron-sentry
When your renderer and UI framework have finished loading, the built in features can be accessed like this:
const ElectronBoilerplate = ElectronBoilerplate; ElectronBoilerplate; ElectronBoilerplate; // Start drag-out event for a specific file with an iconElectronBoilerplate; // Create a modal window and apply our defaultsElectronBoilerplate);
TODO
- Add CI build with Spectron tests