fix: #43 Stop trying to apply settings when ryzenadj has not been set.

This commit is contained in:
Quentin “Storm1er” Decaunes 2019-08-14 17:33:52 +02:00
parent 9d01b070d3
commit ef35ffe128
2 changed files with 26 additions and 8 deletions

View File

@ -6,6 +6,7 @@ ready(function(){
fixPath(); fixPath();
displayOptions(); displayOptions();
preFillSettings(); preFillSettings();
isRyzenAdjPathValid();
loadLatestUsedSettings(); loadLatestUsedSettings();
registerRepeaterForAllInput(); registerRepeaterForAllInput();
registerEventListenerForSettingsInput(); registerEventListenerForSettingsInput();
@ -40,6 +41,10 @@ function applyRyzenSettings() {
const child = require('child_process').execFile; const child = require('child_process').execFile;
const executablePath = getRyzenAdjExecutablePath(); const executablePath = getRyzenAdjExecutablePath();
if (!isRyzenAdjPathValid()) {
return;
}
const options_data = require('./js/options_data.json'); const options_data = require('./js/options_data.json');
const ryzenAdjConvert = { const ryzenAdjConvert = {
"toHex": function (value) { return '0x' + decimalToHexString(value * 1000); }, "toHex": function (value) { return '0x' + decimalToHexString(value * 1000); },

View File

@ -246,13 +246,10 @@ function getRyzenAdjExecutablePath() {
* Will fill settings page on render with saved data. * Will fill settings page on render with saved data.
*/ */
function preFillSettings() { function preFillSettings() {
var ryzen_adj_path = document.getElementById('ryzen_adj_path'); const ryzen_adj_path = document.getElementById('ryzen_adj_path');
var fs = require('fs');
ryzen_adj_path.value = getRyzenAdjExecutablePath();
if (!fs.existsSync(ryzen_adj_path.value)) {
notification('danger', "Path to ryzenadj.exe is wrong, please fix it in settings tab.");
}
const settings = require('electron-settings'); const settings = require('electron-settings');
ryzen_adj_path.value = getRyzenAdjExecutablePath();
document.getElementById('start_at_boot').checked = !!settings.get('settings.start_at_boot'); document.getElementById('start_at_boot').checked = !!settings.get('settings.start_at_boot');
document.getElementById('apply_last_settings_on_launch').checked = !!settings.get('settings.apply_last_settings_on_launch'); document.getElementById('apply_last_settings_on_launch').checked = !!settings.get('settings.apply_last_settings_on_launch');
document.getElementById('minimize_to_tray').checked = !!settings.get('settings.minimize_to_tray'); document.getElementById('minimize_to_tray').checked = !!settings.get('settings.minimize_to_tray');
@ -264,6 +261,22 @@ function preFillSettings() {
document.getElementById('reapply_periodically_range').value = seconds; document.getElementById('reapply_periodically_range').value = seconds;
} }
/**
* Check if ryzenadj executable has been registered and is valid.
* Will display a notification if not.
*
* @return {Boolean} True if ryzenadj executable exists.
*/
function isRyzenAdjPathValid() {
var fs = require('fs');
if (!fs.existsSync(getRyzenAdjExecutablePath())) {
notification('danger', "Path to ryzenadj.exe is wrong, please fix it in settings tab.");
return false;
}
return true;
}
/** /**
* Will open a dialog to let user choose where is ryzenadj.exe. * Will open a dialog to let user choose where is ryzenadj.exe.
*/ */