Skip to content

Commit 307d06d

Browse files
author
Dave Conway-Jones
committed
move some options to package.json section
1 parent 578cf32 commit 307d06d

4 files changed

Lines changed: 40 additions & 23 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ node_modules
1515
*.backup
1616
logs
1717
*.log
18+
yarn.lock

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ This is an Electron template to embed [Node-RED](https://nodered.org) with a Das
77

88
This is not intended to be a useful tool as-is, but as a base for you to create your own versions. You will need to edit the `main.js` to suit your application and update the `package.json` file to include your own required nodes and dependencies.
99

10-
At the top of `main.js` are a couple of flags you can switch to turn off editing, allow loading of a different flow file (and save as), and add the worldmap to the menu. Again these are only there to show you possibilities. Have fun.
10+
There are several simple switches that can be set in the `NRelectron` section of
11+
the `package.json` file. More significant modifications will require modification
12+
of the `main.js` file. Have fun.
1113

1214
## Configuring the project for building
1315

@@ -65,7 +67,7 @@ These can be changed by editing the build section of the `package.json` file, se
6567
Electron-builder has a pre-configured Docker image that can help you build cross platform
6668
images if you like Docker - again read [their docs](https://www.electron.build/multi-platform-build#build-electron-app-using-docker-on-a-local-machine).
6769

68-
This is very useful if you need to build for Windows on a Mac as the electron-builder invokes wine which is only 32-bit and so can't be run under Catalina.
70+
This is very useful if you need to build for Windows on a Mac as the electron-builder invokes **wine** which is only 32-bit and so can't be run under Catalina.
6971

7072
## Developing and Testing - Running locally
7173

main.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11

22
'use strict';
3+
const pkg = require('./package.json');
4+
let options;
5+
if (pkg.hasOwnProperty("NRelectron")) { options = pkg["NRelectron"] }
36

4-
// Some settings you can edit easily
5-
6-
const editable = true; // set this to false to create a run only application - no editor/no console
7-
const allowLoadSave = false; // set to true to allow import and export of flow file
8-
const showMap = false; // set to true to add Worldmap to the menu
9-
const kioskMode = false; // set to true to start in kiosk mode
7+
// Some settings you can edit if you don't set them in package.json
8+
console.log(options)
9+
const editable = options.editable || true; // set this to false to create a run only application - no editor/no console
10+
const allowLoadSave = options.allowLoadSave || false; // set to true to allow import and export of flow file
11+
const showMap = options.showMap || false; // set to true to add Worldmap to the menu
12+
const kioskMode = options.kioskMode || false; // set to true to start in kiosk mode
13+
let flowfile = options.flowFile || 'electronflow.json'; // default Flows file name - loaded at start
1014

11-
let flowfile = 'electronflow.json'; // default Flows file name - loaded at start
1215
const urldash = "/ui/#/0"; // url for the dashboard page
1316
const urledit = "/red"; // url for the editor page
1417
const urlconsole = "/console.htm"; // url for the console page
1518
const urlmap = "/worldmap"; // url for the worldmap
1619
const nrIcon = "nodered.png" // Icon for the app in root dir (usually 256x256)
17-
const urlStart = urldash; // Start on this page
20+
let urlStart; // Start on this page
21+
if (options.start.toLowerCase() === "editor") { urlStart = urledit; }
22+
else if (options.start.toLowerCase() === "map") { urlStart = urlmap; }
23+
else { urlStart = urldash; }
1824

1925
// TCP port to use
2026
//const listenPort = "18880"; // fix it if you like
2127
const listenPort = parseInt(Math.random()*16383+49152) // or random ephemeral port
2228

23-
const pkg = require('./package.json');
2429
const os = require('os');
2530
const fs = require('fs');
2631
const url = require('url');
@@ -208,7 +213,7 @@ if (!allowLoadSave) { template[0].submenu.splice(0,2); }
208213
// Top and tail menu on Mac
209214
if (process.platform === 'darwin') {
210215
template[0].submenu.unshift({ type: 'separator' });
211-
template[0].submenu.unshift({ label: "About Node-RED", selector: "orderFrontStandardAboutPanel:" });
216+
template[0].submenu.unshift({ label: "About "+options.productName||"Node-RED Electron", selector: "orderFrontStandardAboutPanel:" });
212217
template[0].submenu.unshift({ type: 'separator' });
213218
template[0].submenu.unshift({ type: 'separator' });
214219
}
@@ -337,15 +342,15 @@ function createWindow() {
337342
// console.log("FINISHED LOAD",a);
338343
// });
339344

340-
mainWindow.webContents.on("new-window", function(e, url, frameName, disposition, options) {
345+
mainWindow.webContents.on("new-window", function(e, url, frameName, disposition, option) {
341346
// if a child window opens... modify any other options such as width/height, etc
342347
// in this case make the child overlap the parent exactly...
343348
//console.log("NEW WINDOW",url);
344349
var w = mainWindow.getBounds();
345-
options.x = w.x;
346-
options.y = w.y;
347-
options.width = w.width;
348-
options.height = w.height;
350+
option.x = w.x;
351+
option.y = w.y;
352+
option.width = w.width;
353+
option.height = w.height;
349354
})
350355

351356
mainWindow.on('closed', () => {
@@ -374,22 +379,22 @@ app.on('activate', function() {
374379
// dock icon is clicked and there are no other windows open.
375380
if (mainWindow === null) {
376381
createWindow();
377-
mainWindow.loadURL("http://localhost:"+listenPort+urldash);
382+
mainWindow.loadURL("http://localhost:"+listenPort+urlStart);
378383
}
379384
});
380385

381386
if (process.platform === 'darwin') {
382387
app.setAboutPanelOptions({
383-
applicationName: pkg.productName,
384-
version: pkg.version,
385-
copyright: "Copyright © 2019, D Conway-Jones.",
388+
applicationVersion: pkg.version,
389+
version: pkg.dependencies["node-red"],
390+
copyright: "Copyright © 2019, "+pkg.author.name,
386391
credits: "Node-RED and other components are copyright the JS Foundation and other contributors."
387392
});
388393
}
389394

390395
// Start the Node-RED runtime, then load the inital dashboard page
391396
RED.start().then(function() {
392397
server.listen(listenPort,"localhost",function() {
393-
mainWindow.loadURL("http://localhost:"+listenPort+urldash);
398+
mainWindow.loadURL("http://localhost:"+listenPort+urlStart);
394399
});
395400
});

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,19 @@
4545
"electron": "^7.1.1",
4646
"electron-builder": "^22.1.0"
4747
},
48+
"NRelectron": {
49+
"productName": "Node-RED Electron",
50+
"editable": true,
51+
"allowLoadSave": false,
52+
"showMap": false,
53+
"kioskMode": false,
54+
"flowFile": "electronflow.json",
55+
"start": "dashboard"
56+
},
4857
"build": {
4958
"npmRebuild": false,
5059
"appId": "com.electron.node-red",
51-
"productName": "Node-RED",
60+
"productName": "Node-RED Electron",
5261
"copyright": "Copyright © 2019 D.Conway-Jones",
5362
"mac": {
5463
"category": "public.app-category.developer-tools",

0 commit comments

Comments
 (0)