From 877d3a7eee0b6af7513684ef7553eb0cedfa3e07 Mon Sep 17 00:00:00 2001 From: Kubat <mael.martin31@gmail.com> Date: Thu, 11 Feb 2021 18:21:35 +0100 Subject: [PATCH] Edit the config from amadeus, need a restart to apply --- common/config.js | 20 ++++++++++++++++++++ instance/index.html | 8 ++++---- instance/main.js | 20 +++++++++++++++++++- main.js | 17 +++++++++++++++++ 4 files changed, 60 insertions(+), 5 deletions(-) diff --git a/common/config.js b/common/config.js index 21ca9c8..18263cb 100644 --- a/common/config.js +++ b/common/config.js @@ -37,10 +37,30 @@ var config = { this.database = __config.database.path; this.host = __config.lektord.host; this.port = __config.lektord.port; + this.attachmode = __config.lektord.attach; this.loglevel = __config.log.level; this.loglektord = __config.log.lektord; fs.writeFileSync(__configFile, ini.stringify(__config)); + + this.flush(); + }, + flush() { + const __config = { + database: { + path: this.database, + }, + lektord: { + host: this.host, + port: this.port, + attach: this.attachmode, + }, + log: { + level: this.loglevel, + lektord: this.loglektord, + }, + }; + fs.writeFileSync(__configFile, ini.stringify(__config)); }, }; diff --git a/instance/index.html b/instance/index.html index 0470155..cfc848e 100644 --- a/instance/index.html +++ b/instance/index.html @@ -67,7 +67,7 @@ <fieldset class="form-group"> <div class="row"> <legend class="col-form-label col-sm-2 pt-0">Log level</legend> - <div class="col-sm-10"> + <div class="col-sm-10" id="inputLogLevel"> <div class="form-check"> <input class="form-check-input" @@ -84,10 +84,10 @@ class="form-check-input" type="radio" name="gridRadios" - id="logWARNINGS" - value="WARNINGS" + id="logWARNING" + value="WARNING" /> - <label class="form-check-label" for="logWARNINGS">Warnings</label> + <label class="form-check-label" for="logWARNING">Warning</label> </div> <div class="form-check"> <input diff --git a/instance/main.js b/instance/main.js index cd163b1..8b0dc0e 100644 --- a/instance/main.js +++ b/instance/main.js @@ -43,10 +43,27 @@ function autoFillSettings() { $('#inputPort').val(config.port); $('#inputAttachMode').prop('checked', true); $('#inputDbPath').val(config.database); - $('#inputLogLektord').val(config.loglektord); + $('#inputLogLektord').prop('checked', config.loglektord); $(`#log${config.loglevel.toUpperCase()}`).prop('checked', true); } +function flushFillSettings() { + const set = { + host: $('#inputHost').val(), + port: $('#inputPort').val(), + attachmode: $('#inputAttachMode').prop('checked'), + db: $('#inputDbPath').val(), + loglektord: $('#inputLogLektord').prop('checked'), + loglevel: { + ERROR: $('#logERROR').prop('checked'), + WARNING: $('#logWARNING').prop('checked'), + INFO: $('#logINFO').prop('checked'), + DEBUG: $('#logDEBUG').prop('checked'), + }, + }; + ipcRenderer.send('set-settings', set); +} + window.onload = () => { createButtonList(buttonList); @@ -151,6 +168,7 @@ function createButtonList(list) { span.onclick = function () { modal.style.display = 'none'; + flushFillSettings(); }; window.onclick = function (event) { diff --git a/main.js b/main.js index 7cd3f73..68b997f 100644 --- a/main.js +++ b/main.js @@ -252,3 +252,20 @@ ipcMain.on('get-song-time-data', (event, arg) => { }); } }); + +ipcMain.on('set-settings', (event, arg) => { + logger.info('main', `Settings are now: ${JSON.stringify(arg)}`); + config.host = arg.host; + config.port = arg.port; + config.database = arg.db; + config.loglektord = arg.loglektord; + config.attachmode = arg.attachmode; + + /* prettier-ignore */ + config.loglevel = arg.loglevel.ERROR ? 'error' + : arg.loglevel.WARNING ? 'warning' + : arg.loglevel.INFO ? 'info' + : 'debug'; + + config.flush(); +}); -- GitLab