diff --git a/index.html b/index.html index 77a01b3..eddc958 100644 --- a/index.html +++ b/index.html @@ -16,7 +16,9 @@
  • Presets
  • Logs
  • - + +
    + - + + diff --git a/js/settings.js b/js/app.js similarity index 57% rename from js/settings.js rename to js/app.js index 3f577fd..ffcaac1 100644 --- a/js/settings.js +++ b/js/app.js @@ -1,36 +1,12 @@ -function ready(fn) { - if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){ - fn(); - } else { - document.addEventListener('DOMContentLoaded', fn); - } -} ready(function(){ - var ranges = document.querySelectorAll('[repeat]'); - for (const range in ranges) { - if (ranges.hasOwnProperty(range)) { - const element = ranges[range]; - element.addEventListener('change', function(event) { - var repeater = document.getElementById(event.target.attributes.repeat.value); - repeater.value = event.target.value; - }); - } - } + registerRepeaterForAllInput(); + checkForAdminRights(); }); -function getCurrentWorkingDirectory() { - return require('electron').remote.app.getAppPath(); -} - -function decimalToHexString(number) { - if (number < 0) - { - number = 0xFFFFFFFF + number + 1; - } - - return number.toString(16).toUpperCase(); -} - +/** + * Will create and handle ryzenadj.exe execution. + * @param {Event} e The event triggered. + */ function applyRyzenSettings(e) { const settings = { "--stapm-limit=": document.getElementById('stapm_limit_w').value, @@ -39,7 +15,6 @@ function applyRyzenSettings(e) { "--tctl-temp=": document.getElementById('temperature_limit_c').value, "--vrmmax-current=": document.getElementById('vrm_current_m_a').value, }; - console.log(settings); const child = require('child_process').execFile; const executablePath = getCurrentWorkingDirectory() + "\\bin\\ryzenadj.exe"; @@ -73,8 +48,13 @@ function applyRyzenSettings(e) { } child(executablePath, parameters, function(err, data) { - console.log(err) - console.log(data.toString()); + var output = data.toString(); + if (err) { + notification('danger', err + '
    ' + output); + } + else if (output) { + notification('success', 'Ryzenadj output:
    ' + output); + } }); } diff --git a/js/methods.js b/js/methods.js new file mode 100644 index 0000000..bca320c --- /dev/null +++ b/js/methods.js @@ -0,0 +1,91 @@ +/** + * Will create a nodes from an html string. + * @param {string} str An html string + */ +function parseHTML(str) { + var tmp = document.implementation.createHTMLDocument(); + tmp.body.innerHTML = str; + return tmp.body.children; +}; + +/** + * Return the current working directory. + */ +function getCurrentWorkingDirectory() { + return require('electron').remote.app.getAppPath(); +} + +/** + * Conversion from int to hex. + * @param {int} number A number. + */ +function decimalToHexString(number) { + if (number < 0) + { + number = 0xFFFFFFFF + number + 1; + } + + return number.toString(16).toUpperCase(); +} + +/** + * Will execute the given callback once document is ready. + * @param {function} fn A callback to be executed. + */ +function ready(fn) { + if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){ + fn(); + } else { + document.addEventListener('DOMContentLoaded', fn); + } +} + +/** + * Will make sure inputs are repeated when needed. + * + * Use the "repeat" html attribute to define where the current value must be repeated. + */ +function registerRepeaterForAllInput() { + var ranges = document.querySelectorAll('[repeat]'); + for (const range in ranges) { + if (ranges.hasOwnProperty(range)) { + const element = ranges[range]; + element.addEventListener('change', function(event) { + var repeater = document.getElementById(event.target.attributes.repeat.value); + repeater.value = event.target.value; + }); + } + } +} + +/** + * Check that the app is running with admin right. + * + * Will display a warning if not. + */ +function checkForAdminRights() { + var exec = require('child_process').exec; + exec('NET SESSION', function(err,so,se) { + if (se.length !== 0) { + notification('warning', + `Warning: you should launch this app as administrator, + ryzenadj.exe doesn't seems to work correctly without administrator rights. + `); + } + }); +} + +/** + * Will display a notification in ".notification-zone". + * @param {string} type "primary", "warning", "danger" or "success". + * @param {string} message The message to be displayed, new line will be replaced by
    . + */ +function notification(type, message) { + var element = parseHTML(` +
    + +

    ${(''+message).replace(/(?:\r\n|\r|\n)/g, '
    ')}

    +
    `); + var notifZone = document.getElementById('notification-zone'); + notifZone.appendChild(element[0]); +} \ No newline at end of file