Skip to content

Commit 3dd8243

Browse files
committed
implement a serial component is optional in electron version
1 parent 54698f3 commit 3dd8243

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

app/server.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@ var fs = require('fs');
1010
var formidable = require('formidable');
1111
var pjson = require('../package.json');
1212
var pio = require('./pio');
13-
var serial = require('./console');
1413
var http = require('http');
1514
var ua = require('universal-analytics');
1615
var promisify = require('./helpers').promisify;
1716

1817
var port = 3000;
1918
var server = http.Server(app);
2019
var visitor = ua('UA-99239389-1');
20+
var isElectron=module.parent&&module.parent.filename.indexOf('index.js')>=0;
21+
22+
var serial;
23+
var serial_enabled = !isElectron||process.platform=='linux';
24+
if (serial_enabled)
25+
serial = require('./console');
2126

2227
app.use('/', express.static(path.join(__dirname,'..', 'static')));
2328
app.use('/libs', express.static(path.join(__dirname,'..', 'node_modules')));
@@ -52,7 +57,9 @@ function serial_init(){
5257
})
5358
}).catch(a=>console.error(a));
5459
}
55-
app.get('/ports', function (req, res,next) {
60+
app.get('/ports', function (req, res) {
61+
if(!serial_enabled)
62+
return res.status(403).end()
5663
req.socket.setTimeout(Number.MAX_SAFE_INTEGER);
5764
console.log('SSE conected');
5865
res.writeHead(200, {
@@ -72,13 +79,17 @@ app.get('/ports', function (req, res,next) {
7279
});
7380

7481
app.get('/port/:port/:speed', function (req, res) {
82+
if(!serial_enabled)
83+
return res.status(404)
7584
serial.init(server,req.params.port,req.params.speed)
7685
.then(data=>{
7786
res.send(data);
7887
})
7988
.catch(a=>res.status(403).send(a))
8089
});
8190
app.get('/port-close/:port', function (req, res) {
91+
if(!serial_enabled)
92+
return res.status(404)
8293
serial.close(req.params.port)
8394
.then(data=>{
8495
res.send(data);
@@ -163,7 +174,7 @@ app.get('/pio-flash/:port', function (req, res) {
163174
params.push(port)
164175
close=true;
165176
}
166-
(close?serial.close(port):Promise.resolve(true))
177+
(close&&serial_enabled?serial.close(port):Promise.resolve(true))
167178
.then(a=>git.root())
168179
.then(root=>{
169180
console.log(root);
@@ -268,7 +279,7 @@ function main(noOpn){
268279
console.error(e);
269280
throw e;
270281
})
271-
.then(serial_init)
282+
.then(serial_enabled?serial_init:a=>a)
272283
// .catch(a=>console.error('serial failed'))
273284
.then(()=>getPort(3000))
274285
.then(port =>new Promise((done,fail)=>{

bin/mctd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ nodemon({
88
script: path.resolve(__dirname, '..','app','server.js'),
99
watch: path.resolve(__dirname, '..'),
1010
ext: 'js json',
11-
ignore: ['tools.js'],
11+
ignore: ['tools.js','dist','build'],
1212
});
1313

1414
nodemon.on('start', function () {

package.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
{
22
"name": "marlin-conf",
3-
"version": "2.6.0",
3+
"version": "2.6.1",
44
"description": "configuration tool for Marlin project",
55
"main": "./index.js",
66
"scripts": {
77
"start": "electron . -G ~/TEST",
88
"build": "build --dir",
99
"dist": "build -wl --x64 --ia32",
10-
"distt": "build -l --x64",
10+
"distt": "build -w --x64",
1111
"distm": "build -m --x64",
1212
"test": "echo \"Error: no test specified\" && exit 1",
1313
"postinstall-": "bower install",
1414
"lint": "eslint .",
15-
"coveralls": "nyc report --reporter=text-lcov",
1615
"rebuild": "npm rebuild serialport --update-binary",
1716
"prepublish": "./node_modules/.bin/json -I -f package.json -e 'if(this.devDependencies)this.devDependenciesOff=this.devDependencies;this.devDependencies=undefined'",
1817
"postpublish": "./node_modules/.bin/json -I -f package.json -e 'if(this.devDependenciesOff)this.devDependencies=this.devDependenciesOff;this.devDependenciesOff=undefined'",
1918
"prebuild-": "sudo apt install icnsutils graphicsmagick"
2019
},
21-
"config": {
22-
"production": true
23-
},
2420
"build": {
2521
"appId": "com.akajes.marlin.conf",
2622
"linux": {
2723
"target": [
24+
"deb",
2825
"AppImage"
2926
]
3027
},
3128
"win": {
29+
"target": [
30+
"nsis"
31+
],
3232
"icon": "build/icons/icon_256x256.png"
3333
},
3434
"nsis": {},
@@ -75,12 +75,10 @@
7575
"which": "^1.2.14"
7676
},
7777
"devDependencies": {
78-
"coveralls": "^2.13.1",
7978
"electron": "^1.6.10",
8079
"electron-builder": "^18.1.0",
8180
"eslint": "^3.19.0",
8281
"json": "^9.0.6",
83-
"nodemon": "^1.11.0",
84-
"nyc": "^10.3.2"
82+
"nodemon": "^1.11.0"
8583
}
8684
}

static/main.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,14 @@ $(function(){
578578
createPort(p)
579579
});
580580
});
581+
source.addEventListener('error', function(event) {
582+
$('.mct-consoles').attr('disabled','')
583+
$('.mct-ports a').addClass('disabled')
584+
});
585+
source.addEventListener('open', function(event) {
586+
$('.mct-consoles').removeAttr('disabled')
587+
$('.mct-ports a').removeClass('disabled')
588+
});
581589
source.addEventListener('created', function(event) {
582590
var port= JSON.parse(event.data);
583591
createPort(port);

0 commit comments

Comments
 (0)