fix: Ensure preset exist when applying.

This fix an issue where you could apply a preset on ac status change after deleting it.
This commit is contained in:
Quentin Decaunes 2019-08-17 17:48:58 +02:00
parent 1a7fd0098a
commit 2152f32b8f

View File

@ -130,15 +130,32 @@ function preset_updateList() {
presetTab.innerHTML = content;
}
/**
* Will check if the preset exists.
*
* @param {String} name The preset name to look for.
*/
function preset_isExist(name) {
const preset = require('electron-settings').get(`presets`)[name];
return !!preset;
}
/**
* This will apply the preset you asked for.
* @param {string} presetName The preset name to be applied.
*/
function preset_apply(presetName) {
const presets = require('electron-settings').get(`presets`)[presetName];
appendLog(`preset_apply(): preset ${presetName}: ${JSON.stringify(presets)}`);
var ret = require('electron-settings').set("latest_controller_tabs_settings", presets);
if (!preset_isExist(presetName)) {
notification('danger', `Unable to apply unexisting preset "${presetName}".`);
return;
}
const preset = require('electron-settings').get(`presets`)[presetName];
appendLog(`preset_apply(): preset ${presetName}: ${JSON.stringify(preset)}`);
var ret = require('electron-settings').set("latest_controller_tabs_settings", preset);
appendLog(`preset_apply(): saved preset: ${JSON.stringify(ret)}`);
loadLatestUsedSettings();
applyRyzenSettings();
toggleOptionDisplayBasedOnApplyCheckbox();