mirror of
https://gitlab.com/ryzen-controller-team/ryzen-controller.git
synced 2024-12-22 10:03:28 +07:00
Cleaned basecode and added notifications management.
This commit is contained in:
parent
43fed585ab
commit
db745b344d
@ -16,7 +16,9 @@
|
|||||||
<li><a href="#">Presets</a></li>
|
<li><a href="#">Presets</a></li>
|
||||||
<li><a href="#">Logs</a></li>
|
<li><a href="#">Logs</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
<div class="uk-container" id="notification-zone"></div>
|
||||||
|
|
||||||
<ul class="uk-switcher uk-margin">
|
<ul class="uk-switcher uk-margin">
|
||||||
|
|
||||||
|
|
||||||
@ -97,6 +99,7 @@
|
|||||||
<li class="uk-container">Will be available soon!</li>
|
<li class="uk-container">Will be available soon!</li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
<script type="text/javascript" src="./js/settings.js"></script>
|
<script type="text/javascript" src="./js/methods.js"></script>
|
||||||
|
<script type="text/javascript" src="./js/app.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -1,36 +1,12 @@
|
|||||||
function ready(fn) {
|
|
||||||
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading"){
|
|
||||||
fn();
|
|
||||||
} else {
|
|
||||||
document.addEventListener('DOMContentLoaded', fn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ready(function(){
|
ready(function(){
|
||||||
var ranges = document.querySelectorAll('[repeat]');
|
registerRepeaterForAllInput();
|
||||||
for (const range in ranges) {
|
checkForAdminRights();
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function getCurrentWorkingDirectory() {
|
/**
|
||||||
return require('electron').remote.app.getAppPath();
|
* Will create and handle ryzenadj.exe execution.
|
||||||
}
|
* @param {Event} e The event triggered.
|
||||||
|
*/
|
||||||
function decimalToHexString(number) {
|
|
||||||
if (number < 0)
|
|
||||||
{
|
|
||||||
number = 0xFFFFFFFF + number + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return number.toString(16).toUpperCase();
|
|
||||||
}
|
|
||||||
|
|
||||||
function applyRyzenSettings(e) {
|
function applyRyzenSettings(e) {
|
||||||
const settings = {
|
const settings = {
|
||||||
"--stapm-limit=": document.getElementById('stapm_limit_w').value,
|
"--stapm-limit=": document.getElementById('stapm_limit_w').value,
|
||||||
@ -39,7 +15,6 @@ function applyRyzenSettings(e) {
|
|||||||
"--tctl-temp=": document.getElementById('temperature_limit_c').value,
|
"--tctl-temp=": document.getElementById('temperature_limit_c').value,
|
||||||
"--vrmmax-current=": document.getElementById('vrm_current_m_a').value,
|
"--vrmmax-current=": document.getElementById('vrm_current_m_a').value,
|
||||||
};
|
};
|
||||||
console.log(settings);
|
|
||||||
|
|
||||||
const child = require('child_process').execFile;
|
const child = require('child_process').execFile;
|
||||||
const executablePath = getCurrentWorkingDirectory() + "\\bin\\ryzenadj.exe";
|
const executablePath = getCurrentWorkingDirectory() + "\\bin\\ryzenadj.exe";
|
||||||
@ -73,8 +48,13 @@ function applyRyzenSettings(e) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
child(executablePath, parameters, function(err, data) {
|
child(executablePath, parameters, function(err, data) {
|
||||||
console.log(err)
|
var output = data.toString();
|
||||||
console.log(data.toString());
|
if (err) {
|
||||||
|
notification('danger', err + '<br/>' + output);
|
||||||
|
}
|
||||||
|
else if (output) {
|
||||||
|
notification('success', 'Ryzenadj output:<br/>' + output);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
91
js/methods.js
Normal file
91
js/methods.js
Normal file
@ -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 <br/>.
|
||||||
|
*/
|
||||||
|
function notification(type, message) {
|
||||||
|
var element = parseHTML(`
|
||||||
|
<div class="uk-alert-${type}" uk-alert>
|
||||||
|
<a class="uk-alert-close" uk-close></a>
|
||||||
|
<p>${(''+message).replace(/(?:\r\n|\r|\n)/g, '<br/>')}</p>
|
||||||
|
</div>`);
|
||||||
|
var notifZone = document.getElementById('notification-zone');
|
||||||
|
notifZone.appendChild(element[0]);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user