From 2152f32b8f20b41336990598d77f42548566de8d Mon Sep 17 00:00:00 2001 From: Quentin Decaunes Date: Sat, 17 Aug 2019 17:48:58 +0200 Subject: [PATCH] fix: Ensure preset exist when applying. This fix an issue where you could apply a preset on ac status change after deleting it. --- js/preset.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/js/preset.js b/js/preset.js index 7af6af2..1b62f21 100644 --- a/js/preset.js +++ b/js/preset.js @@ -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();