Skip to content

Commit fa99f01

Browse files
committed
standalone version
1 parent a1ed141 commit fa99f01

File tree

9 files changed

+124
-38
lines changed

9 files changed

+124
-38
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ coverage
2525

2626
# Compiled binary addons (http://nodejs.org/api/addons.html)
2727
build/Release
28+
dist
2829

2930
# Dependency directories
3031
node_modules

app/git-tool.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ exports.clone=name=>new Promise((done,fail)=>{
6767
clearInterval(timer);
6868
console.log();
6969
if (code == 0)
70-
done();
70+
done(name);
7171
else
7272
fail();
7373
});

app/helpers.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
var fs = require('fs');
33
var path = require('path');
44

5+
Object.prototype.filter = function( predicate, obj ) {
6+
var result = { };
7+
obj = obj || this
8+
for (var key in obj) {
9+
if( obj.hasOwnProperty(key) && predicate( obj[key], key, obj ) ) {
10+
result[key] = obj[key];
11+
}
12+
}
13+
return result;
14+
};
15+
16+
517
function promisify(func) {
618
return function() {
719
return new Promise((resolve, reject) => {

app/mc-tool.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
var fs = require('fs');
33
var path = require('path');
44
var mc = require('./mc');
5+
var ht = require('./helpers');
56

67
//common
78
var inFile=name=>new Promise((done, fail) => fs.readFile( name, 'utf8', (err, data) => err ? fail( err ) : done( data ) ) )
@@ -11,17 +12,6 @@ var parseJson=a=>JSON.parse(a);
1112
var text2array=text=>text.split(/\r\n?|\n/);
1213
var array2text=(a,text)=>(text='',a.forEach(i=>text+=i+'\n'),text.slice(0,-1));
1314

14-
Object.prototype.filter = function( predicate, obj ) {
15-
var result = { };
16-
obj = obj || this
17-
for (var key in obj) {
18-
if( obj.hasOwnProperty(key) && predicate( obj[key], key, obj ) ) {
19-
result[key] = obj[key];
20-
}
21-
}
22-
return result;
23-
};
24-
2515
//workers
2616

2717
var onlyChanged=a=>a.filter(i=>i.changed);

app/server.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function SSEsend(event,data){
3535
});
3636
}
3737
function serial_init(){
38-
serial.changes().then(monitor=>{
38+
return serial.changes().then(monitor=>{
3939
monitor.on("created", function (f, stat) {
4040
SSEsend('created',f)
4141
// serial.list().then(a=>SSEsend('list',a));
@@ -134,7 +134,7 @@ app.get('/version/:screen', function (req, res) {
134134
.then(a=>{
135135
//console.log(a)
136136
var s=JSON.stringify(a);
137-
res.write(`var config={pio:${s},version:"${pjson.version}"}`);
137+
res.write(`var config={pio:${s},version:"${pjson.version}"};`);
138138
res.end();
139139
})
140140
});
@@ -146,7 +146,7 @@ app.get('/pio', function (req, res) {
146146
});
147147
});
148148
function atob(b64string){
149-
if (typeof Buffer.from === "function")
149+
if ( process.version<"v6.0.0" )
150150
// Node 5.10+
151151
return Buffer.from(b64string, 'base64');
152152
else
@@ -257,23 +257,31 @@ app.post('/set/:file/:name/:prop/:value', function (req, res) {
257257
.then(a=>res.send(req.params))
258258
.catch(a=>res.status(403).send(a))
259259
})
260-
function main(){
261-
serial_init();
262-
hints.init(1);
263-
git.root()
264-
.then(root=>{
265-
fs.stat(path.join(root,'Marlin'),(e,a)=>{
266-
if(!a)
267-
console.log('this git not look like Marlin repository');
268-
else
269-
getPort(3000).then(port => {
270-
server.listen(port, function () {
271-
console.log('Marlin config tool started on port http://localhost:'+port);
272-
});
273-
opn('http://localhost:'+port+'/');
274-
});
275-
})
260+
function main(noOpn){
261+
return Promise.resolve()
262+
.then(serial_init)
263+
.catch(a=>console.error('serial failed'))
264+
.then(()=>hints.init(1))
265+
.catch(a=>console.error('hints failed'))
266+
.then(()=>git.root())
267+
.then(root=>promisify(fs.stat)(path.join(root,'Marlin')))
268+
.catch(a=>{
269+
var e=('this git not look like Marlin repository');
270+
console.log(e);
271+
throw e;
276272
})
273+
.then(()=>getPort(3000))
274+
.then(port =>new Promise((done,fail)=>{
275+
server.on('error',function(e){
276+
fail(e)
277+
})
278+
server.listen(port, function () {
279+
var url='http://localhost:'+port+'/';
280+
console.log('Marlin config tool started on '+url);
281+
done(url);
282+
});
283+
}))
284+
.then(url=>(!noOpn&&opn(url),url));
277285
}
278286
module.exports.main=main;
279287
require.main===module && main();

index.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'use strict';
2+
const {app, BrowserWindow, Menu, dialog} = require('electron');
3+
console.log('Node',process.version);
4+
5+
var which=require('which');
6+
var path=require('path');
7+
var promisify = require('./app/helpers').promisify;
8+
var git = require('./app/git-tool');
9+
var server = require('./app/server');
10+
11+
var mainWindow = null;
12+
var getFolder=()=>new Promise((done,fail)=>
13+
dialog.showOpenDialog({
14+
title:'select folder with Marlin Firmware or empty folder to clone it',
15+
properties:['openDirectory'],
16+
},function(folders){
17+
console.log();
18+
if (!folders)
19+
return fail({type:'fatal',message:'no folder selected'});
20+
done(folders[0])
21+
})
22+
)
23+
app.on('ready', function() {
24+
var folder;
25+
promisify(which)('git')
26+
.catch(function(){
27+
dialog.showErrorBox('Dependecies','Application needs GIT to be installed!')
28+
throw {type:'fatal',message:'no Git installed'};
29+
})
30+
.then(function(){
31+
var is={'-G':0}
32+
.filter((v,key,o,p,i)=>(p=process.argv,i=p.indexOf(key),!v&&i>=0&&i+1<p.length&&(o[key]=p[i+1]),i>=0));
33+
if (!is['-G'])
34+
return getFolder();
35+
return is['-G'];
36+
})
37+
.then(f=>folder=f)
38+
.then(git.root)
39+
.catch(function(e){
40+
if (e&&e.type=="fatal")
41+
throw e;
42+
console.log('no repository found in this folder');
43+
return git.clone(path.join(folder,'Marlin'));
44+
})
45+
.catch(function(e){
46+
if (e&&e.type=="fatal")
47+
throw e;
48+
return git.root(path.join(folder,'Marlin'));
49+
})
50+
.then(()=>server.main(1))
51+
.then(function(url){
52+
mainWindow = new BrowserWindow({
53+
height: 600,
54+
width: 800
55+
});
56+
mainWindow.loadURL(url);
57+
return;
58+
dialog.showMessageBox({
59+
type:"info",
60+
title:"Git repository",
61+
message:folder
62+
})
63+
})
64+
.catch(function(e){
65+
console.error(e.message)
66+
app.quit();
67+
})
68+
});

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"name": "marlin-conf",
3-
"version": "2.5.6",
3+
"version": "2.6.0",
44
"description": "configuration tool for Marlin project",
5+
"main": "./index.js",
56
"scripts": {
7+
"start": "electron . -G /home/jes/TEST",
8+
"build": "build --dir",
9+
"distw": "build -w --ia32 --x64",
610
"test": "echo \"Error: no test specified\" && exit 1",
711
"postinstall-": "bower install"
812
},
@@ -41,6 +45,8 @@
4145
"which": "^1.2.14"
4246
},
4347
"devDependencies-": {
48+
"electron": "^1.6.10",
49+
"electron-builder": "^18.1.0",
4450
"nodemon": "^1.11.0"
4551
}
4652
}

start.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,22 @@ function main(){
8787
}
8888
function startWeb(){
8989
git.root()
90-
.then(root=>{
90+
.then(root=>new Promise((done,fail)=>{
9191
console.log('type: mct help if you need more information');
9292
if(root){
9393
var rl = getConsole();
9494
rl.question('press Enter to run web browser or ^C to exit', (answer) => {
9595
rl.close();
96-
server.main()
96+
server.main().then(done).catch(fail)
9797
});
9898
}
99-
})
99+
})).catch((e)=>{ console.log(e); })
100100
}
101101
function tryRun(){
102102
process.chdir('Marlin')
103103
console.log(process.cwd())
104-
git.root('Marlin').then(a=>{
105-
server.main();
106-
});
104+
git.root('Marlin')
105+
.then(server.main);
107106
}
108107
git.root()
109108
.then(startWeb)
@@ -149,4 +148,5 @@ commands:
149148
`);
150149
}
151150
module.exports.main=main;
151+
console.log('Node',process.version);
152152
require.main===module && main();

static/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<!-- Bootstrap -->
1010
<link href="libs/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
1111
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
12+
<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>
1213
<script src="libs/jquery/dist/jquery.min.js"></script>
1314
<!-- Include all compiled plugins (below), or include individual files as needed -->
1415
<script src="libs/tether/dist/js/tether.min.js"></script>

0 commit comments

Comments
 (0)