Electron is a framework that uses web technologies (HTML, CSS, and JS) to build cross-platform desktop applications.
RedHat Build Support
brew install rpm
npm i -g cordova cordova create sampleApp cd sampleApp cordova platform add electron
Notice: If using Cordova CLI prior to version 9.x, you will need to use the cordova-electron
argument instead of electron
for any command that requires the platform's name. For example:
cordova platform add cordova-electron cordova run cordova-electron
It is not necessary to build the Electron application for previewing. Since the building process can be slow, it is recommended to pass in the --nobuild
flag to disable the build process when previewing.
cordova run electron --nobuild
Debug Builds
cordova build electron cordova build electron --debug
Release Builds
cordova build electron --release
Electron provides many options to manipulate the BrowserWindow
. This section will cover how to configure a few basic options. For a full list of options, please see the Electron's Docs - BrowserWindow Options.
Working with a Cordova project, it is recommended to create an Electron settings file within the project's root directory, and set its the relative path in the preference option ElectronSettingsFilePath
, in the config.xml
file.
Example config.xml
:
<platform name="electron"> <preference name="ElectronSettingsFilePath" value="res/electron/settings.json" /> </platform>
To override or set any BrowserWindow options, in this file the options are added to the browserWindow
property.
Example res/electron/settings.json
:
{ "browserWindow": { ... } }
By default, the width
is set to 800 and the height
set to 600. This can be overridden by setting the width
and height
property.
Example:
{ "browserWindow": { "width": 1024, "height": 768 } }
Setting the resizable
flag property, you can disable the user's ability to resize your application's window.
Example:
{ "browserWindow": { "resizable": false } }
Using the fullscreen
flag property, you can force the application to launch in fullscreen.
Example:
{ "browserWindow": { "fullscreen": true } }
Set the nodeIntegration
flag property to true
. By default, this property flag is set to false
to support popular libraries that insert symbols with the same names that Node.js and Electron already uses.
You can read more about this at Electron docs: I can not use jQuery/RequireJS/Meteor/AngularJS in Electron.
Example:
{ "browserWindow": { "webPreferences": { "nodeIntegration": false } } }
If it is necessary to customize the Electron's main process beyond the scope of the Electron's configuration settings, chances can be added directly to the cdv-electron-main.js
file located in {PROJECT_ROOT_DIR}/platform/electron/platform_www/
. This is the application's main process.
❗ However, it is not recommended to modify this file as the upgrade process for
cordova-electron
is to remove the old platform before adding the new version.
The --release
and --debug
flags control the visibility of the DevTools. DevTools are shown by default on Debug Builds (without a flag
or with --debug
). If you want to hide the DevTools pass in the --release
flag when building or running the application.
Note: DevTools can be closed or opened manually with the debug build.
By default, with no additional configuration, cordova build electron
will build default packages for the host operating system (OS) that triggers the command. Below, are the list of default packages for each OS.
Linux
Package | Arch |
---|---|
tar.gz | x64 |
Mac
Package | Arch |
---|---|
dmg | x64 |
zip | x64 |
Windows
Package | Arch |
---|---|
nsis | x64 |
If for any reason you would like to customize the build configurations, modifications are placed within the build.json
file located in the project's root directory. E.g. {PROJECT_ROOT_DIR}/build.json
. This file contains all build configurations for all platforms (Android, Electron, iOS, Windows).
Example Config Structure
{ "electron": {} }
Since the Electron framework is for creating cross-platform applications, multiple configurations are required for each OS build. The electron
node, in the build.json
file, contains three properties that separate the build configurations for each OS.
Example Config Structure with Each Platform
{ "electron": { "linux": {}, "mac": {}, "windows": {} } }
Each OS node contains properties that are used to identify what package to generate and how to sign.
OS Properties:
package
is an array of package formats that will be generated.arch
is an array of architectures that each package is built for.signing
is an object that contains signing information. See Signing Configurations for more information.Any properties that are undefined will fallback to default values.
package
The package
property is an array list of packages to be outputted. If the property is defined, the default packages are not used unless added. The order of the packages has no importance.
The configuration example below will generate tar.gz
, dmg
and zip
packages for macOS.
{ "electron": { "mac": { "package": [ "dmg", "tar.gz", "zip" ] } } }
Available Packages by Operating System
Package Type | Linux | macOS | Windows |
---|---|---|---|
default | - |
dmg zip
| - |
dmg | - | ✅ | - |
mas | - | ✅ | - |
mas-dev | ✅ | - | - |
pkg | - | ✅ | - |
7z | ✅ | ✅ | ✅ |
zip | ✅ | ✅ | ✅ |
tar.xz | ✅ | ✅ | ✅ |
tar.lz | ✅ | ✅ | ✅ |
tar.gz | ✅ | ✅ | ✅ |
tar.bz2 | ✅ | ✅ | ✅ |
dir | ✅ | ✅ | ✅ |
nsis | - | - | ✅ |
nsis-web | - | - | ✅ |
portable | - | - | ✅ |
appx | - | - | ✅ [1] |
msi | - | - | ✅ |
AppImage | ✅ | - | - |
snap | ✅ | - | - |
deb | ✅ | - | - |
rpm | ✅ | - | - |
freebsd | ✅ | - | - |
pacman | ✅ | - | - |
p5p | ✅ | - | - |
apk | ✅ | - | - |
arch
The arch
property is an array list of architectures that each package is built for. When the property is defined, the default arch is not used unless added.
❗ Not all architectures are available for every operating system. Please review the Electron Releases to identify valid combinations. For example, macOS (Darwin) only supports x64.
Available Arch
The example above will generate an x64
dmg
package.
{ "electron": { "mac": { "package": [ "dmg" ], "arch": [ "x64" ] } } }
❗ Not all platforms support this feature and may have limitations.
Building for multiple platforms on a single operating system may possible but has limitations. It is recommended that the builder's operating system (host OS) matches with the platform that is being built.
The matrix below shows each host OS and for which platforms they are capable of building applications.
Host [1] | Linux | Mac | Window |
---|---|---|---|
Linux | ✅ | ❗ [2] | |
Mac [3] | ✅ | ✅ | ❗ [2] |
Window | ✅ |
Limitations:
The example below enables multi-platform build for all OS and uses the default build configurations.
{ "electron": { "linux": {}, "mac": {}, "windows": {} } }
There are three types of signing targets. (debug
, release
, and store
). Each section has the following properties:
key | description |
---|---|
entitlements | String path value to entitlements file. |
entitlementsInherit | String path value to the entitlements file which inherits the security settings. |
identity | String value of the name of the certificate. |
requirements | String path value of requirements file. ❗ This is not available for the mas (store) signing configurations. |
provisioningProfile | String path value of the provisioning profile. |
Example Config:
{ "electron": { "mac": { "package": [ "dmg", "mas", "mas-dev" ], "signing": { "release": { "identity": "APACHE CORDOVA (TEAMID)", "provisioningProfile": "release.mobileprovision" } } } } }
For macOS signing, there are a few exceptions to how the signing information is used. By default, all packages with the exception of mas
and mas-dev
, use the debug
and release
signing configurations.
Using the example config above, let's go over some use cases to better understand the exceptions.
Use Case 1:
cordova build electron --debug
The command above will:
dmg
build and mas-dev
build using the debug
signing configurations.mas
target package.Use Case 2:
cordova build electron --release
The command above will:
dmg
build using the release
config.mas
build using the store
config.mas-dev
target package.The signing information is comprised of two types. (debug
, release
). Each section has the following properties:
key | description |
---|---|
certificateFile | String path to the certificate file. |
certificatePassword | String value of the certificate file's password. Alternative: The password can be set on the environment variable CSC_KEY_PASSWORD . |
certificateSubjectName | String value of the signing certificate's subject. ❗ Required for EV Code Signing and requires Windows |
certificateSha1 | String value of the SHA1 hash of the signing certificate. ❗ Requires Windows |
signingHashAlgorithms | Collection of singing algorithms to be used. (sha1 , sha256 )❗ AppX builds only support sha256
|
additionalCertificateFile | String path to the additional certificate files. |
Example Config:
{ "electron": { "windows": { "package": [ "nsis" ], "signing": { "release": { "certificateFile": "path_to_files", "certificatePassword": "password" } } } } }
There are not signing requirements for Linux builds.
All browser-based plugins are usable with the Electron platform.
When adding a plugin, if the plugin supports both the electron
and browser
platform, the electron
portion will be used. If the plugin misses electron
but contains the browser
implementation, it will fall back on the browser
implementation.
Internally, Electron is using Chromium (Chrome) as its web view. Some plugins may have conditions written specifically for each different browser. In this case, it may affect the behavior of what is intended. Since Electron may support feature that the browser does not, these plugins would possibly need to be updated for the electron
platform.
© 2012, 2013, 2015 The Apache Software Foundation
Licensed under the Apache License 2.0.
https://cordova.apache.org/docs/en/9.x/guide/platforms/electron/index.html