You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2019/01/29 05:42:02 UTC
[cordova-electron] branch master updated: Create CDV Electron
Settings JSON (#8)
This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-electron.git
The following commit(s) were added to refs/heads/master by this push:
new dacce37 Create CDV Electron Settings JSON (#8)
dacce37 is described below
commit dacce3760f4c4c6af711638b4600db23803be1d0
Author: Gedas Gardauskas <ge...@gmail.com>
AuthorDate: Tue Jan 29 14:41:56 2019 +0900
Create CDV Electron Settings JSON (#8)
---
bin/lib/create.js | 3 +++
bin/templates/cordova/lib/prepare.js | 24 ++++++++++++++++++++++++
bin/templates/project/cdv-electron-settings.json | 3 +++
bin/templates/project/main.js | 6 +++++-
4 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/bin/lib/create.js b/bin/lib/create.js
index 46e5abe..0122f6d 100644
--- a/bin/lib/create.js
+++ b/bin/lib/create.js
@@ -77,5 +77,8 @@ module.exports.createProject = (project_path, package_name, project_name, option
// copy main.js
fs.copySync(path.join(ROOT, 'bin/templates/project/main.js'), path.join(platform_www, 'main.js'), { overwrite: false });
+ // copy cdv-electron-settings.json
+ fs.copySync(path.join(ROOT, 'bin/templates/project/cdv-electron-settings.json'), path.join(platform_www, 'cdv-electron-settings.json'), { overwrite: false });
+
return Promise.resolve();
};
diff --git a/bin/templates/cordova/lib/prepare.js b/bin/templates/cordova/lib/prepare.js
index 22df8b8..b6b78bd 100644
--- a/bin/templates/cordova/lib/prepare.js
+++ b/bin/templates/cordova/lib/prepare.js
@@ -69,10 +69,34 @@ module.exports.prepare = function (cordovaProject, options) {
.configure(this.config)
.write();
+ // update Electron settings in .json file
+ (new SettingJson(this.locations.www))
+ .configure(options.options)
+ .write();
+
// update project according to config.xml changes.
return this.parser.update_project(this.config, options);
};
+class SettingJson {
+ constructor (wwwDir) {
+ this.path = path.join(wwwDir, 'cdv-electron-settings.json');
+ this.package = require(this.path);
+ }
+
+ configure (config) {
+ if (config) {
+ this.package.isRelease = (typeof (config.release) !== 'undefined') ? config.release : false;
+ }
+
+ return this;
+ }
+
+ write () {
+ fs.writeFileSync(this.path, JSON.stringify(this.package, null, 2), 'utf8');
+ }
+}
+
class PackageJson {
constructor (wwwDir) {
this.path = path.join(wwwDir, 'package.json');
diff --git a/bin/templates/project/cdv-electron-settings.json b/bin/templates/project/cdv-electron-settings.json
new file mode 100644
index 0000000..cd5b813
--- /dev/null
+++ b/bin/templates/project/cdv-electron-settings.json
@@ -0,0 +1,3 @@
+{
+ "isRelease": false
+}
\ No newline at end of file
diff --git a/bin/templates/project/main.js b/bin/templates/project/main.js
index 8eb6441..d3f8b36 100644
--- a/bin/templates/project/main.js
+++ b/bin/templates/project/main.js
@@ -22,6 +22,8 @@ const electron = require('electron');
const app = electron.app;
// Module to create native browser window.
const BrowserWindow = electron.BrowserWindow;
+// Electron settings from .json file.
+const cdvElectronSettings = require('./cdv-electron-settings.json');
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
@@ -39,7 +41,9 @@ function createWindow () {
});
// Open the DevTools.
- mainWindow.webContents.openDevTools();
+ if (!cdvElectronSettings.isRelease) {
+ mainWindow.webContents.openDevTools();
+ }
// Emitted when the window is closed.
mainWindow.on('closed', () => {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org