diff --git a/app/common.js b/app/common.js index 5fe8d8fd58..30038b83f4 100644 --- a/app/common.js +++ b/app/common.js @@ -39,9 +39,17 @@ const uploadFiles = files => } }) )) +const configFilesList = ['Configuration.h', 'Configuration_adv.h', '_Bootscreen.h', '_Statusscreen.h']; +const configFilesListUpload = configFilesList.slice(0, 2); -const configFiles = p => Promise.all( - ['Configuration.h', 'Configuration_adv.h', '_Bootscreen.h'] +const uploadCopyFiles = files => + uploadFiles(files.filter(file => configFilesListUpload.indexOf(file.name) >= 0)) + .then(a => git.root()) + .then(root => Promise.all( + files.filter(file => configFilesListUpload.indexOf(file.name) < 0).map(f => copyFile(f.path, path.join(root, 'Marlin', f.name))) + )) + +const configFiles = p => Promise.all(configFilesList .map(file => seek4File(file, p ? [p.replace(/\\/g, path.sep)] : ['Marlin', path.join('Marlin', 'src', 'config')]).catch(() => null)) ).then(files => files.filter(a => a)); @@ -56,7 +64,9 @@ const getThermistors = () => module.exports = { seek4File, copyFile, + uploadCopyFiles, uploadFiles, + configFilesList, configFiles, getBoards, getThermistors, diff --git a/app/mc-tool.js b/app/mc-tool.js index d6aebf5611..0bf0bd4814 100644 --- a/app/mc-tool.js +++ b/app/mc-tool.js @@ -32,7 +32,7 @@ var addNumber=a=>{ var killComments=a=>a.map(i=>(i.comment=null,i)) var killDublicated=a=>a.filter(i=>i.number==undefined||!i.disabled).map(i=>(i.number=undefined,i)) -const skips = ['CONFIGURATION_H_VERSION']; +const skips = ['CONFIGURATION_H_VERSION', 'CONFIGURATION_ADV_H_VERSION']; var setConfig=(target,file,root)=>a=>{ var map=remap(a); diff --git a/app/server.js b/app/server.js index d253446288..57571c6102 100644 --- a/app/server.js +++ b/app/server.js @@ -15,7 +15,7 @@ var http = require('http'); var https = require('https'); var ua = require('universal-analytics'); const {promisify, atob, walk, unique} = require('./helpers'); -const {seek4File, copyFile, uploadFiles, configFiles, getBoards, getThermistors} = require('./common'); +const {seek4File, copyFile, uploadCopyFiles, configFilesList, configFiles, getBoards, getThermistors} = require('./common'); var qr = require('qr-image'); var machineId = require('node-machine-id').machineId; @@ -73,6 +73,8 @@ var get_cfg=()=>{ var ex_dir = (rel) => seek4File('', [path.join('Marlin', 'example_configurations'), path.join('Marlin', 'src', 'config', 'examples')], rel) +const sortNCS = (a, b) => a.toLowerCase().localeCompare(b.toLowerCase()); + app.get('/examples', function (req, res) { var ex; return ex_dir() @@ -81,6 +83,7 @@ app.get('/examples', function (req, res) { .then(a=>a.filter(i=>/Configuration(_adv)?\.h/.test(i))) .then(a=>a.map(i=>path.parse(path.relative(ex,i)).dir)) .then(unique) + .then(a => a.sort(sortNCS)) .catch(e => []) .then(a=>(a.unshift('Marlin'),a)) .then(a => res.send({current: store.vars.baseCfg, list: a})) @@ -196,19 +199,16 @@ app.post('/upload', function(req, res){ done(files); }) }) - .then(files=>{ - files.map(file=>{ - if (['Configuration.h','Configuration_adv.h'].indexOf(file.name)<0) - throw 'Wrong file name! Allowed only Configuration.h and Configuration_adv.h'; - }) - return files; - }) + .then(files => Promise.all(files.map(file => + configFilesList.indexOf(file.name) >= 0 ? file : Promise.reject('Wrong file name! Allowed only files ' + configFilesList) + ))) // .then(a=>(console.log(a),a)) //process - .then(uploadFiles) + .then(uploadCopyFiles) .then(a=>res.send(a)) .catch(e=>res.status(403).send(e)) }); + app.post('/set/:file/:name/:prop/:value', function (req, res) { var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress; var name = req.params.name.split('.'); diff --git a/app/services/editor.js b/app/services/editor.js index 8a4a5d3183..30e29be23c 100644 --- a/app/services/editor.js +++ b/app/services/editor.js @@ -55,7 +55,7 @@ router.get('/tree', function(req, res) { children: stats.isDirectory(), type: stats.isDirectory() ? 'default' : "file", text: name, - id: path.join(dir, name), + id: path.join(dir, name).replace(/\\/g, '/'), // icon: stats.isDirectory() ? 'jstree-folder' : "jstree-file", })))) ) diff --git a/app/services/git.js b/app/services/git.js index 69805a7086..331f8b6603 100644 --- a/app/services/git.js +++ b/app/services/git.js @@ -1,7 +1,10 @@ +const path = require('path'); +const fs = require('fs'); const router = module.exports = require('express').Router(); const git = require('../git-tool'); const store = require('../store'); -const atob = require('../helpers').atob; +const {atob, promisify} = require('../helpers'); +const {seek4File, configFilesList, copyFile} = require('../common'); router.get('/tags', function (req, res) { git.Tags() @@ -32,17 +35,21 @@ router.get('/status', function (req, res) { router.get('/checkout-force', function (req, res) { var cp = () => git.root() .then(root => Promise.all( - ['Configuration.h', 'Configuration_adv.h', '_Bootscreen.h'] - .map(f=>new Promise((done,fail)=> - fs.createReadStream(path.join(root, store.vars.baseCfg, f)).on('error', fail) - .pipe(fs.createWriteStream(path.join(root, 'Marlin', f)).on('finish', done)) - ).catch(e => 'not found') + configFilesList + .map(f => + copyFile(path.join(root, store.vars.baseCfg, f), path.join(root, 'Marlin', f)) + .catch(e => 'not found') ) )) - var rm = () => - seek4File('_Bootscreen.h', [path.join('Marlin', 'src', 'config'), 'Marlin']) - .then(file => file && promisify(fs.unlink)(file)) - .catch(a=>a); + + var rm = () => Promise.all( + ['_Bootscreen.h', '_Statusscreen.h'] + .map(f => + seek4File(f, [path.join('Marlin', 'src', 'config'), 'Marlin']) + .then(file => file && promisify(fs.unlink)(file)) + .catch(a=>a) + ) + ); git.Checkout('--force') .then(rm) diff --git a/app/services/pub.js b/app/services/pub.js index 20df16c4ff..d95111683b 100644 --- a/app/services/pub.js +++ b/app/services/pub.js @@ -12,7 +12,7 @@ const FormData = require('form-data'); const git = require('../git-tool'); const store = require('../store'); const {promisify, atob, walk} = require('../helpers'); -const {seek4File, configFiles, getBoards, uploadFiles} = require('../common'); +const {seek4File, configFiles, getBoards, uploadCopyFiles} = require('../common'); var pubs = {}; @@ -110,7 +110,7 @@ router.get('/site/:Id', function (req, res) { .then(buf => promisify(yauzl.fromBuffer)(buf, {lazyEntries:true})) .then(readZip) .then(files => files.map(i => ({path: i.file, name: i.entry.fileName}))) - .then(uploadFiles) + .then(uploadCopyFiles) .then(a => (store.mods.sse.send('reload'),"page/application reloaded")) .then(a => res.send(a)) .catch(e => (console.error(e),res.status(403).send(e))) diff --git a/app/services/store.js b/app/services/store.js index a1889adaf4..64f1efdb3f 100644 --- a/app/services/store.js +++ b/app/services/store.js @@ -8,7 +8,7 @@ const yazl = require("yazl"); const git = require('../git-tool'); const {promisify, atob, walk, unique} = require('../helpers'); -const {seek4File, configFiles, getBoards, uploadFiles, copyFile} = require('../common'); +const {seek4File, configFiles, getBoards, uploadCopyFiles, copyFile} = require('../common'); const store = require('../store'); router.get('/save', function (req, res) { @@ -66,19 +66,7 @@ router.get('/restore/:path', function (req, res) { .then(root => path.join(root, store.config.store, p)) .then(dir=>promisify(fs.stat)(dir).catch(a=>{throw 'no files';}).then(a=>dir)) .then(walk) - .then(files=>{ - var up=files - .filter(i=>/Configuration(_adv)?\.h/.test(i)) - .map(f=>({path:f,name:path.parse(f).base})) - var cp=files - .filter(i=>/_Bootscreen\.h/.test(i)) - .map(f => - seek4File('', [path.join('Marlin', 'src', 'config'), 'Marlin']) - .then(dir => copyFile(f, path.join(dir, path.basename(f) ))) - ) - console.log(cp); - return uploadFiles(up).then(up=>Promise.all([...up,...cp])); - }) + .then(files => uploadCopyFiles(files.map(f => ({path: f, name: path.parse(f).base})))) .then(a=>res.send(a)) .catch(e=>res.status(403).send(e)) }); diff --git a/index.js b/index.js index 1437990e12..cbadc6dc62 100644 --- a/index.js +++ b/index.js @@ -137,4 +137,9 @@ app.on('ready', function() { dialog.showErrorBox('Error', e.message); app.quit(); }) -}); \ No newline at end of file +}); + +process.on('unhandledRejection', (reason, p) => { + console.error('Unhandled Rejection at: Promise', p, 'reason:', reason); + // application specific logging, throwing an error, or other logic here +}); diff --git a/package.json b/package.json index c423e53808..7e03a7e87d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "marlin-conf", - "version": "2.10.3", + "version": "2.10.4", "description": "configuration tool for Marlin project", "main": "./index.js", "scripts": { @@ -85,7 +85,7 @@ "platformio-node-helpers": "^0.5.2", "qr-image": "^3.2.0", "rtcmulticonnection-v3": "^3.4.4", - "serialport": "^6.2.0", + "serialport": "=6.2.1", "simple-git": "^1.95.1", "socket.io": "^2.1.1", "swig-templates": "^2.0.2", diff --git a/static/css/input-expand-group.css b/static/css/input-expand-group.css index 32f4a3a1db..bfd32d983a 100644 --- a/static/css/input-expand-group.css +++ b/static/css/input-expand-group.css @@ -27,11 +27,13 @@ width:100%; } -.input-expand-group:hover div div { +.input-expand-group:focus-within div div { opacity:1; -webkit-transition:opacity 0.5s ease-in-out; } -.input-expand-group:hover { +.input-expand-group.expanded, +.input-expand-group:hover, +.input-expand-group:focus-within { width:100%; -webkit-transition:width 0.5s ease-in-out; } diff --git a/static/index.html b/static/index.html index fcc0125d92..8951b96210 100644 --- a/static/index.html +++ b/static/index.html @@ -138,9 +138,10 @@ if (typeof require === 'function') { //commonJS from electron var ipc = require('electron').ipcRenderer; function found(val) { - $('.mct-search').focus().parent().find('span').text(val); + $('.mct-search').focus().parent().removeClass('expanded').find('span').text(val); } $('.mct-search').on('change', function() { + $(this).parent().addClass('expanded'); ipc.send('search-text', $(this).val()); !$(this).val().length && found(0) }) @@ -257,7 +258,8 @@
Current is:
Current is:
to apply files do `RESET` command after configuration selection