Auto load latest applied settings.

This commit is contained in:
Quentin Decaunes 2019-02-28 18:23:05 +01:00
parent d7416706fc
commit 1336779a6a
3 changed files with 39 additions and 2 deletions

View File

@ -20,7 +20,7 @@
<ul class="uk-switcher uk-margin"> <ul class="uk-switcher uk-margin">
<li class="uk-container"> <li class="uk-container" id="controller-tab">
<h3>STAPM Limit (W)</h3> <h3>STAPM Limit (W)</h3>
<div class="uk-grid-small" uk-grid> <div class="uk-grid-small" uk-grid>
<div class="uk-width-1-4@s"> <div class="uk-width-1-4@s">

View File

@ -2,6 +2,7 @@ ready(function(){
registerRepeaterForAllInput(); registerRepeaterForAllInput();
checkForAdminRights(); checkForAdminRights();
preFillSettings(); preFillSettings();
loadLatestUsedSettings();
}); });
/** /**
@ -55,6 +56,7 @@ function applyRyzenSettings(e) {
} }
else if (output) { else if (output) {
notification('success', 'Ryzenadj output:<br/>' + output); notification('success', 'Ryzenadj output:<br/>' + output);
saveLatestUsedSettings();
} }
}); });

View File

@ -150,3 +150,38 @@ function appendLog(message) {
log_area.value += message + "\n"; log_area.value += message + "\n";
console.log(message); console.log(message);
} }
/**
* Will save the latest used settings.
*/
function saveLatestUsedSettings() {
var inputs = document.querySelectorAll('#controller-tab input');
var latest_controller_tabs_settings = {};
inputs.forEach(element => {
let id = element.id;
let value = element.value;
latest_controller_tabs_settings[id] = value;
});
const settings = require('electron-settings');
let ret = settings.set("latest_controller_tabs_settings", latest_controller_tabs_settings);
appendLog(`saveLatestUsedSettings(): ${JSON.stringify(latest_controller_tabs_settings)}`);
appendLog(`saveLatestUsedSettings(): ${JSON.stringify(ret)}`);
}
/**
* Will load the latest settings and refresh the controller tab's values.
*/
function loadLatestUsedSettings() {
const settings = require('electron-settings');
var latest_controller_tabs_settings = settings.get("latest_controller_tabs_settings");
appendLog(`loadLatestUsedSettings(): ${JSON.stringify(latest_controller_tabs_settings)}`);
for (const id in latest_controller_tabs_settings) {
if (latest_controller_tabs_settings.hasOwnProperty(id)) {
const value = latest_controller_tabs_settings[id];
let input = document.getElementById(id);
if (input) {
input.value = value;
}
}
}
}