cordova-electron
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -80,4 +80,4 @@ #!/usr/bin/env node | ||
// copy main.js | ||
fs.copySync(path.join(ROOT, 'bin/templates/project/main.js'), path.join(platform_www, 'main.js'), { overwrite: false }); | ||
// copy cdv-electron-main.js | ||
fs.copySync(path.join(ROOT, 'bin/templates/project/cdv-electron-main.js'), path.join(platform_www, 'cdv-electron-main.js'), { overwrite: false }); | ||
@@ -84,0 +84,0 @@ // copy cdv-electron-settings.json |
@@ -23,17 +23,4 @@ /* | ||
const events = require('cordova-common').events; | ||
const { deepMerge } = require('./util'); | ||
function deepMerge (mergeTo, mergeWith) { | ||
for (const property in mergeWith) { | ||
if (Object.prototype.toString.call(mergeWith[property]) === '[object Object]') { | ||
mergeTo[property] = deepMerge((mergeTo[property] || {}), mergeWith[property]); | ||
} else if (Object.prototype.toString.call(mergeWith[property]) === '[object Array]') { | ||
mergeTo[property] = [].concat((mergeTo[property] || []), mergeWith[property]); | ||
} else { | ||
mergeTo[property] = mergeWith[property]; | ||
} | ||
} | ||
return mergeTo; | ||
} | ||
const PLATFORM_MAPPING = { | ||
@@ -43,3 +30,3 @@ linux: 'linux', | ||
windows: 'win32', | ||
win: 'win' | ||
win: 'win32' | ||
}; | ||
@@ -88,3 +75,3 @@ | ||
if (!this.__validateUserPlatformBuildSettings(platformConfigs)) { | ||
throw `The platform "${platform}" contains an invalid property. Valid properties are: package, arch, signing`; | ||
throw Error(`The platform "${platform}" contains an invalid property. Valid properties are: package, arch, signing`); | ||
} | ||
@@ -282,3 +269,3 @@ | ||
if (!fs.existsSync(platformFile)) { | ||
throw `Your platform "${platform}" is not supported as a default target platform for Electron.`; | ||
throw Error(`Your platform "${platform}" is not supported as a default target platform for Electron.`); | ||
} | ||
@@ -285,0 +272,0 @@ |
@@ -28,3 +28,3 @@ /* | ||
this.package = { | ||
main: 'main.js' | ||
main: 'cdv-electron-main.js' | ||
}; | ||
@@ -31,0 +31,0 @@ } |
@@ -78,5 +78,10 @@ /* | ||
const userElectronSettings = cordovaProject.projectConfig.getPlatformPreference('ElectronSettingsFilePath', 'electron'); | ||
const userElectronSettingsPath = userElectronSettings && fs.existsSync(path.resolve(cordovaProject.root, userElectronSettings)) | ||
? path.resolve(cordovaProject.root, userElectronSettings) | ||
: undefined; | ||
// update Electron settings in .json file | ||
(new SettingJsonParser(this.locations.www)) | ||
.configure(options.options) | ||
.configure(options.options, userElectronSettingsPath) | ||
.write(); | ||
@@ -83,0 +88,0 @@ |
@@ -25,3 +25,4 @@ /* | ||
module.exports.run = (args) => { | ||
const child = proc.spawn(electron, ['./platforms/electron/www/main.js']); | ||
const pathToMain = path.resolve(__dirname, '..', '..', 'www', 'cdv-electron-main.js'); | ||
const child = proc.spawn(electron, [pathToMain]); | ||
@@ -28,0 +29,0 @@ child.on('close', (code) => { |
@@ -22,2 +22,3 @@ /* | ||
const path = require('path'); | ||
const { deepMerge } = require('./util'); | ||
@@ -30,5 +31,11 @@ class SettingJsonParser { | ||
configure (config) { | ||
configure (config, userElectronSettingsPath) { | ||
// Apply user settings ontop of defaults. | ||
if (userElectronSettingsPath) { | ||
const userElectronSettings = require(userElectronSettingsPath); | ||
this.package = deepMerge(this.package, userElectronSettings); | ||
} | ||
if (config) { | ||
this.package.isRelease = (typeof (config.release) !== 'undefined') ? config.release : false; | ||
this.package.browserWindow.webPreferences.devTools = !config.release; | ||
} | ||
@@ -35,0 +42,0 @@ |
{ | ||
"isRelease": false | ||
"browserWindow": { | ||
"height": 600, | ||
"webPreferences":{ | ||
"devTools": true, | ||
"nodeIntegration": false | ||
}, | ||
"width": 800 | ||
} | ||
} |
@@ -22,3 +22,3 @@ // Platform: electron | ||
;(function() { | ||
var PLATFORM_VERSION_BUILD_LABEL = '1.0.1'; | ||
var PLATFORM_VERSION_BUILD_LABEL = '1.0.2'; | ||
// file: src/scripts/require.js | ||
@@ -25,0 +25,0 @@ |
@@ -34,8 +34,9 @@ <!-- | ||
- [Customizing the Application's Icon](#customizing-the-applications-icon) | ||
- [Customizing the Application's Main Process](#customizing-the-applications-main-process) | ||
- [Window Appearance (BrowserWindow)](#window-appearance-browserwindow) | ||
- [How to set the window default size?](#how-to-set-the-window-default-size) | ||
- [How to make the window not resizable?](#how-to-make-the-window-not-resizable) | ||
- [How to make my window fullscreen?](#how-to-make-my-window-fullscreen) | ||
- [DevTools](#devtools) | ||
- [Customizing the Application's Window Options](#customizing-the-applications-window-options) | ||
- [How to set the window's default size?](#how-to-set-the-windows-default-size) | ||
- [How to make the window not resizable?](#how-to-make-the-window-not-resizable) | ||
- [How to make my window fullscreen?](#how-to-make-my-window-fullscreen) | ||
- [How to support Node.js and Electron APIs?](#how-to-support-nodejs-and-electron-apis) | ||
- [Customizing the Electron's Main Process](#customizing-the-electrons-main-process) | ||
- [DevTools](#devtools) | ||
- [Build Configurations](#build-configurations) | ||
@@ -89,8 +90,15 @@ - [Default Build Configurations](#default-build-configurations) | ||
_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 | ||
``` | ||
### Preview a Project | ||
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 `--no-build` flag to disable the build process when previewing. | ||
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 --no-build | ||
$ cordova run electron --nobuild | ||
``` | ||
@@ -156,44 +164,97 @@ | ||
## Customizing the Application's Main Process | ||
## Customizing the Application's Window Options | ||
In the `{PROJECT_ROOT_DIR}/platform/electron/platform_www/` directory, the file `main.js` defines the application's main process. We can customize the application's window appearance as well as defining or enabling additional features in this file. | ||
Electron provides many options to manipulate the [`BrowserWindow`](https://electronjs.org/docs/api/browser-window). 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](https://electronjs.org/docs/api/browser-window#new-browserwindowoptions). | ||
### Window Appearance (BrowserWindow) | ||
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. | ||
Electron provides many options to manipulate the BrowserWindow. This section covers only a few basic options. For a full list of options, please see the [Electron's Docs - BrowserWindow Options](https://electronjs.org/docs/api/browser-window#new-browserwindowoptions). | ||
**Example `config.xml`:** | ||
Electron provides many optional options that can manipulate the BrowserWindow. This section will cover a few of these options that many uses. A full list of these options can be found on the | ||
```xml | ||
<platform name="electron"> | ||
<preference name="ElectronSettingsFilePath" value="res/electron/settings.json" /> | ||
</platform> | ||
``` | ||
#### How to set the window default size? | ||
To override or set any BrowserWindow options, in this file the options are added to the `browserWindow` property. | ||
Using the `width` and `height` option, you can define starting default window size. | ||
**Example `res/electron/settings.json`:** | ||
```json | ||
{ | ||
"browserWindow": { ... } | ||
} | ||
``` | ||
mainWindow = new BrowserWindow({ | ||
width: 800, | ||
height: 600 | ||
}); | ||
### How to set the window's default size? | ||
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:** | ||
```json | ||
{ | ||
"browserWindow": { | ||
"width": 1024, | ||
"height": 768 | ||
} | ||
} | ||
``` | ||
#### How to make the window not resizable? | ||
### How to make the window not resizable? | ||
Using the `resizable` flag option, you can disable the user's ability to resize your application's window. | ||
Setting the `resizable` flag property, you can disable the user's ability to resize your application's window. | ||
**Example:** | ||
```json | ||
{ | ||
"browserWindow": { | ||
"resizable": false | ||
} | ||
} | ||
``` | ||
mainWindow = new BrowserWindow({ resizable: false }); | ||
### How to make my window fullscreen? | ||
Using the `fullscreen` flag property, you can force the application to launch in fullscreen. | ||
**Example:** | ||
```json | ||
{ | ||
"browserWindow": { | ||
"fullscreen": true | ||
} | ||
} | ||
``` | ||
#### How to make my window fullscreen? | ||
### How to support Node.js and Electron APIs? | ||
Using the `fullscreen` flag option, you can force the application to launch in fullscreen. | ||
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 | ||
](https://electronjs.org/docs/faq#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron). | ||
**Example:** | ||
```json | ||
{ | ||
"browserWindow": { | ||
"nodeIntegration": true | ||
} | ||
} | ||
``` | ||
mainWindow = new BrowserWindow({ fullscreen: true }); | ||
``` | ||
### DevTools | ||
## Customizing the Electron's Main Process | ||
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. | ||
> :warning: 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. | ||
## DevTools | ||
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 still can be closed or opened manually._ | ||
> Note: DevTools can be closed or opened manually with the debug build. | ||
@@ -325,3 +386,3 @@ ## Build Configurations | ||
The example above will generate a `x64` `dmg` package. | ||
The example above will generate an `x64` `dmg` package. | ||
@@ -477,4 +538,4 @@ ``` | ||
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. | ||
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 from 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. | ||
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. |
{ | ||
"name": "cordova-electron", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "electron apps as a target for cordova developers", | ||
@@ -5,0 +5,0 @@ "main": "bin/templates/cordova/Api.js", |
@@ -22,2 +22,17 @@ <!-- | ||
### 1.0.2 (Mar 15, 2019) | ||
* [GH-40](https://github.com/apache/cordova-electron/pull/40) Remove `temp` Dir After `create.spec.js` Test | ||
* [GH-39](https://github.com/apache/cordova-electron/pull/39) Added Missing License Header in `util.js` | ||
* [GH-38](https://github.com/apache/cordova-electron/pull/38) Support User Defined **Electron** Settings | ||
* [GH-37](https://github.com/apache/cordova-electron/pull/37) Remove `nodeIntegration` Warning by Setting Default to `false` | ||
* [GH-36](https://github.com/apache/cordova-electron/pull/36) Rename **Electron** Main Entry File | ||
* [GH-35](https://github.com/apache/cordova-electron/pull/35) Refactor `build.js` and Include Test Coverage | ||
* [GH-32](https://github.com/apache/cordova-electron/pull/32) Improve `temp` Folder Cleanup in `Api.spec.js` | ||
* [GH-33](https://github.com/apache/cordova-electron/pull/33) Update `cordova run` to Work with Pre-Cordova 9.x CLI | ||
### 1.0.1 (Mar 04, 2019) | ||
Version bump with no change. | ||
### 1.0.0 (Feb 25, 2019) | ||
@@ -24,0 +39,0 @@ |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
344831
54
3303
28