Save and restore settings, including profiles.

This commit is contained in:
mmcwilliams 2019-02-22 13:33:48 -05:00
parent b99491909b
commit 8bd505da36
5 changed files with 132 additions and 17 deletions

View File

@ -1,3 +1,5 @@
'use strict'
const os = require('os');
const path = require('path');
const fs = require('fs-extra');
@ -17,7 +19,6 @@ settings.state = {
}
settings.checkDir = async function () {
'use strict';
const dir = path.join(os.homedir(), '.mcopy/');
const exists = await fs.exists(dir)
if (!exists) {
@ -32,7 +33,6 @@ settings.checkDir = async function () {
}
settings.save = async function () {
'use strict';
const str = JSON.stringify(settings.state, null, '\t');
settings.checkDir();
try {
@ -42,22 +42,18 @@ settings.save = async function () {
}
}
settings.update = function (key, val) {
'use strict';
settings.state[key] = val;
}
settings.get = function (key) {
'use strict';
return settings.state[key];
}
settings.all = function () {
'use strict';
return settings.state;
}
settings.restore = async function () {
'use strict';
let exists;
let str;
@ -73,7 +69,6 @@ settings.restore = async function () {
}
settings.reset = async function () {
'use strict';
const exists = await fs.exists(settings.file);
if (exists) {
try {

View File

@ -1,14 +1,14 @@
var devices = {};
devices.init = function () {
'use strict';
devices.listen();;
devices.listen();
devices.profiles();
gui.overlay(true);
gui.spinner(true, 'Checking for connected devices...');
};
devices.profiles = function () {
'use strict';
const keys = Object.keys(mcopy.cfg.profiles);
const elem = $('#profile')
let opt;
@ -21,10 +21,10 @@ devices.profiles = function () {
}
elem.on('change', (t) => {
devices.profile($('#profile').val());
})
devices.profile(keys[0]);
});
};
devices.profile = function (profile) {
'use strict';
log.info(`Changed configuration profile to "${profile}"`, 'DEVICES', true, true);
const p = mcopy.cfg.profiles[profile];
const keys = Object.keys(p);

View File

@ -23,6 +23,7 @@ const Server = require('server')
const Intval = require('intval')
const delay = require('delay')
//Objects
const mcopy = {}
const log = {}
const proj = {}
@ -48,6 +49,12 @@ let ffprobe
mcopy.cfg = require('./data/cfg.json')
mcopy.settings = {}
/**
*
*
*
**/
dev.init = function () {
dev.listen()
}
@ -798,6 +805,9 @@ var init = async function () {
createWindow()
createMenu()
await settings.restore()
mcopy.settings = await settings.all()
log.init()
light.init()
proj.init()
@ -816,8 +826,7 @@ var init = async function () {
arduino = require('./lib/arduino')(mcopy.cfg, ee)
mscript = require('./lib/mscript')
settings.restore()
mcopy.settings = settings.all()
await delay(2000)
try {

118
app/package-lock.json generated
View File

@ -329,6 +329,14 @@
}
}
},
"argparse": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz",
"integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==",
"requires": {
"sprintf-js": "~1.0.2"
}
},
"argv-tools": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/argv-tools/-/argv-tools-0.1.1.tgz",
@ -656,8 +664,15 @@
"bluebird": {
"version": "3.5.3",
"resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.3.tgz",
"integrity": "sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw==",
"dev": true
"integrity": "sha512-/qKPUQlaW1OyR51WeCPBvRnAlnZFUJkCSG5HzGnuIqhgyJtF+T94lFnn33eiazjRm2LAHVy2guNnaq48X9SJuw=="
},
"bluebird-lst": {
"version": "1.0.6",
"resolved": "https://registry.npmjs.org/bluebird-lst/-/bluebird-lst-1.0.6.tgz",
"integrity": "sha512-CBWFoPuUPpcvMUxfyr8DKdI5d4kjxFl1h39+VbKxP3KJWJHEsLtuT4pPLkjpxCGU6Ask21tvbnftWXdqIxYldQ==",
"requires": {
"bluebird": "^3.5.2"
}
},
"bplist-creator": {
"version": "0.0.7",
@ -738,14 +753,34 @@
"buffer-from": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.1.tgz",
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A==",
"dev": true
"integrity": "sha512-MQcXEUbCKtEo7bhqEs6560Hyd4XaovZlO/k9V3hjVUF/zwW7KBVdSK4gIt/bzwS9MbR5qob+F5jusZsb0YQK2A=="
},
"buffers": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/buffers/-/buffers-0.1.1.tgz",
"integrity": "sha1-skV5w77U1tOWru5tmorn9Ugqt7s="
},
"builder-util-runtime": {
"version": "8.1.1",
"resolved": "https://registry.npmjs.org/builder-util-runtime/-/builder-util-runtime-8.1.1.tgz",
"integrity": "sha512-+ieS4PMB33vVE2S3ZNWBEQJ1zKmAs/agrBdh7XadE1lKLjrH4aXYuOh9OOGdxqIRldhlhNBaF+yKMMEFOdNVig==",
"requires": {
"bluebird-lst": "^1.0.6",
"debug": "^4.1.1",
"fs-extra-p": "^7.0.0",
"sax": "^1.2.4"
},
"dependencies": {
"debug": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz",
"integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==",
"requires": {
"ms": "^2.1.1"
}
}
}
},
"builtin-modules": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-1.1.1.tgz",
@ -1983,6 +2018,22 @@
}
}
},
"electron-updater": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/electron-updater/-/electron-updater-4.0.6.tgz",
"integrity": "sha512-JPGLME6fxJcHG8hX7HWFl6Aew6iVm0DkcrENreKa5SUJCHG+uUaAhxDGDt+YGcNkyx1uJ6eBGMvFxDTLUv67pg==",
"requires": {
"bluebird-lst": "^1.0.6",
"builder-util-runtime": "~8.1.0",
"fs-extra-p": "^7.0.0",
"js-yaml": "^3.12.0",
"lazy-val": "^1.0.3",
"lodash.isequal": "^4.5.0",
"pako": "^1.0.7",
"semver": "^5.6.0",
"source-map-support": "^0.5.9"
}
},
"electron-wix-msi": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/electron-wix-msi/-/electron-wix-msi-2.1.1.tgz",
@ -2082,6 +2133,11 @@
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
"dev": true
},
"esprima": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
"integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A=="
},
"exec": {
"version": "file:lib/exec"
},
@ -2596,6 +2652,15 @@
}
}
},
"fs-extra-p": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/fs-extra-p/-/fs-extra-p-7.0.0.tgz",
"integrity": "sha512-5tg5jBOd0xIXjwj4PDnafOXL5TyPVzjxLby4DPKev53wurEXp7IsojBaD4Lj5M5w7jxw0pbkEU0fFEPmcKoMnA==",
"requires": {
"bluebird-lst": "^1.0.6",
"fs-extra": "^7.0.0"
}
},
"fs-minipass": {
"version": "1.2.5",
"resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.5.tgz",
@ -3972,6 +4037,15 @@
"integrity": "sha1-+IxgjjJKM3OpW8xFrTBeXJecRZs=",
"dev": true
},
"js-yaml": {
"version": "3.12.1",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.12.1.tgz",
"integrity": "sha512-um46hB9wNOKlwkHgiuyEVAybXBjwFUV0Z/RaHJblRd9DXltue9FTYvzCr9ErQrK9Adz5MU4gHWVaNUfdmrC8qA==",
"requires": {
"argparse": "^1.0.7",
"esprima": "^4.0.0"
}
},
"js2xmlparser": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/js2xmlparser/-/js2xmlparser-3.0.0.tgz",
@ -4132,6 +4206,11 @@
"integrity": "sha1-odePw6UEdMuAhF07O24dpJpEbo4=",
"dev": true
},
"lazy-val": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/lazy-val/-/lazy-val-1.0.3.tgz",
"integrity": "sha512-pjCf3BYk+uv3ZcPzEVM0BFvO9Uw58TmlrU0oG5tTrr9Kcid3+kdKxapH8CjdYmVa2nO5wOoZn2rdvZx2PKj/xg=="
},
"lcid": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/lcid/-/lcid-2.0.0.tgz",
@ -4340,6 +4419,11 @@
"integrity": "sha1-eeTriMNqgSKvhvhEqpvNhRtfu1U=",
"dev": true
},
"lodash.isequal": {
"version": "4.5.0",
"resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
"integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA="
},
"lodash.keys": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/lodash.keys/-/lodash.keys-3.1.2.tgz",
@ -5304,6 +5388,11 @@
"integrity": "sha512-hMp0onDKIajHfIkdRk3P4CdCmErkYAxxDtP3Wx/4nZ3aGlau2VKh3mZpcuFkH27WQkL/3WBCPOktzA9ZOAnMQQ==",
"optional": true
},
"pako": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/pako/-/pako-1.0.8.tgz",
"integrity": "sha512-6i0HVbUfcKaTv+EG8ZTr75az7GFXcLYk9UyLEg7Notv/Ma+z/UG3TCoz6GiNeOrn1E/e63I0X/Hpw18jHOTUnA=="
},
"parse-author": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/parse-author/-/parse-author-2.0.0.tgz",
@ -6461,6 +6550,22 @@
"urix": "^0.1.0"
}
},
"source-map-support": {
"version": "0.5.10",
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.10.tgz",
"integrity": "sha512-YfQ3tQFTK/yzlGJuX8pTwa4tifQj4QS2Mj7UegOu8jAz59MqIiMGPXxQhVQiIMNzayuUSF/jEuVnfFF5JqybmQ==",
"requires": {
"buffer-from": "^1.0.0",
"source-map": "^0.6.0"
},
"dependencies": {
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
"integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g=="
}
}
},
"source-map-url": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz",
@ -6551,6 +6656,11 @@
"extend-shallow": "^3.0.0"
}
},
"sprintf-js": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz",
"integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw="
},
"sqlite3": {
"version": "4.0.4",
"resolved": "https://registry.npmjs.org/sqlite3/-/sqlite3-4.0.4.tgz",

View File

@ -43,6 +43,7 @@
"capture": "file:lib/capture",
"delay": "file:lib/delay",
"display": "file:lib/display",
"electron-updater": "^4.0.6",
"exec": "file:lib/exec",
"exit": "file:lib/exit",
"ffmpeg": "file:lib/ffmpeg",