From 1914641b775242a37970dbc9ffd6cb1e9181c95a Mon Sep 17 00:00:00 2001 From: mmcw-dev Date: Sun, 2 Sep 2018 14:26:12 -0400 Subject: [PATCH] Updates after package updates --- app/css/app.css | 2 +- app/lib/settings/index.js | 62 +++++++++++++++++++++++++-------------- app/main.js | 2 +- app/package.json | 2 +- 4 files changed, 43 insertions(+), 25 deletions(-) diff --git a/app/css/app.css b/app/css/app.css index 1177039..1ac2729 100644 --- a/app/css/app.css +++ b/app/css/app.css @@ -239,7 +239,7 @@ button:focus { width: 7px; position: absolute; top: 0; - left: calc(22%); + left: calc(50% - (14px * 2)); } .dial-end { transform: rotateZ(0deg); diff --git a/app/lib/settings/index.js b/app/lib/settings/index.js index 408c58d..c607b4f 100644 --- a/app/lib/settings/index.js +++ b/app/lib/settings/index.js @@ -1,6 +1,6 @@ const os = require('os'); const path = require('path'); -const fs = require('fs'); +const fs = require('fs-extra'); const settings = {}; settings.file = path.join(os.homedir(), `/.mcopy/settings.json`); @@ -16,55 +16,73 @@ settings.state = { light : {} } -settings.checkDir = function () { - 'use strict' +settings.checkDir = async function () { + 'use strict'; const dir = path.join(os.homedir(), '.mcopy/'); - if (!fs.existsSync(dir)) { - fs.mkdirSync(dir); + const exists = await fs.exists(dir) + if (!exists) { + try { + await fs.mkdir(dir); + } catch (err) { + if (err.code === 'EEXIST') return true + console.error(err); + } } + return true } -settings.save = function () { - 'use strict' +settings.save = async function () { + 'use strict'; const str = JSON.stringify(settings.state, null, '\t'); settings.checkDir(); - fs.writeFile(settings.file, str, 'utf8', (err) => { - if (err) console.error(err); - }) + try { + await fs.writeFile(settings.file, str, 'utf8'); + } catch (err) { + console.error(err); + } } settings.update = function (key, val) { - 'use strict' + 'use strict'; settings.state[key] = val; } settings.get = function (key) { - 'use strict' + 'use strict'; return settings.state[key]; } settings.all = function () { - 'use strict' + 'use strict'; return settings.state; } -settings.restore = function () { - 'use strict' +settings.restore = async function () { + 'use strict'; + let exists; let str; + settings.checkDir(); - if (fs.existsSync(settings.file)) { - str = fs.readFileSync(settings.file, 'utf8') + exists = await fs.exists(settings.file); + + if (exists) { + str = await fs.readFile(settings.file, 'utf8'); settings.state = JSON.parse(str); } else { settings.save(); } } -settings.reset = function () { - 'use strict' - if (fs.existsSync(settings.file)) { - fs.unlinkSync(settings.file); +settings.reset = async function () { + 'use strict'; + const exists = await fs.exists(settings.file); + if (exists) { + try { + await fs.unlink(settings.file); + } catch (err) { + console.error(err); + } } settings.restore(); }; -module.exports = settings \ No newline at end of file +module.exports = settings; \ No newline at end of file diff --git a/app/main.js b/app/main.js index df645be..975a8a8 100644 --- a/app/main.js +++ b/app/main.js @@ -600,7 +600,7 @@ log.file = function () { return path.join(logPath, 'mcopy.log') } log.time = 'MM/DD/YY-HH:mm:ss' -log.transport = new (winston.Logger)({ +log.transport = winston.createLogger({ transports: [ new (winston.transports.Console)(), new (winston.transports.File)({ filename: log.file() }) diff --git a/app/package.json b/app/package.json index eea5ee1..bc9fe43 100644 --- a/app/package.json +++ b/app/package.json @@ -1,6 +1,6 @@ { "name": "mcopy-app", - "version": "1.0.3", + "version": "1.1.0", "description": "Small guage film optical printer platform", "main": "main.js", "scripts": {