2019-02-28 05:02:10 +07:00
|
|
|
/**
|
|
|
|
* 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() {
|
2019-03-01 00:03:51 +07:00
|
|
|
const cwd = require('electron').remote.app.getAppPath()
|
|
|
|
appendLog(`getCurrentWorkingDirectory(): ${cwd}`);
|
|
|
|
return cwd;
|
2019-02-28 05:02:10 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Conversion from int to hex.
|
|
|
|
* @param {int} number A number.
|
|
|
|
*/
|
|
|
|
function decimalToHexString(number) {
|
|
|
|
if (number < 0)
|
|
|
|
{
|
|
|
|
number = 0xFFFFFFFF + number + 1;
|
|
|
|
}
|
2019-03-01 21:38:59 +07:00
|
|
|
|
2019-02-28 05:02:10 +07:00
|
|
|
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.
|
2019-03-01 21:38:59 +07:00
|
|
|
*
|
2019-02-28 05:02:10 +07:00
|
|
|
* 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.
|
2019-03-01 21:38:59 +07:00
|
|
|
*
|
2019-02-28 05:02:10 +07:00
|
|
|
* Will display a warning if not.
|
|
|
|
*/
|
|
|
|
function checkForAdminRights() {
|
2019-03-01 21:38:59 +07:00
|
|
|
var exec = require('child_process').exec;
|
2019-02-28 05:02:10 +07:00
|
|
|
exec('NET SESSION', function(err,so,se) {
|
|
|
|
if (se.length !== 0) {
|
|
|
|
notification('warning',
|
2019-03-01 00:03:51 +07:00
|
|
|
`Warning: you should launch this app as administrator,`
|
|
|
|
+ `ryzenadj.exe doesn't seems to work correctly without administrator rights.`
|
|
|
|
);
|
2019-02-28 05:02:10 +07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2019-03-01 00:03:51 +07:00
|
|
|
appendLog(`notification(): ${type}\n${message}`);
|
2019-02-28 14:07:57 +07:00
|
|
|
UIkit.notification({
|
|
|
|
message: (''+message).replace(/(?:\r\n|\r|\n)/g, '<br/>'),
|
|
|
|
status: type,
|
|
|
|
pos: 'top-right',
|
|
|
|
timeout: 5000
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-02-28 14:11:03 +07:00
|
|
|
/**
|
|
|
|
* Will return the ryzenadj.exe path registered, or default one if not provided.
|
|
|
|
*/
|
|
|
|
function getRyzenAdjExecutablePath() {
|
|
|
|
const settings = require('electron-settings');
|
|
|
|
var ryzen_adj_path = settings.get('settings.ryzen_adj_path');
|
|
|
|
if (!ryzen_adj_path) {
|
|
|
|
ryzen_adj_path = getCurrentWorkingDirectory() + "\\bin\\ryzenadj.exe";
|
|
|
|
}
|
2019-03-01 00:03:51 +07:00
|
|
|
appendLog(`getRyzenAdjExecutablePath(): ${ryzen_adj_path}`);
|
2019-02-28 14:11:03 +07:00
|
|
|
return ryzen_adj_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will fill settings page on render with saved data.
|
|
|
|
*/
|
|
|
|
function preFillSettings() {
|
|
|
|
var ryzen_adj_path = document.getElementById('ryzen_adj_path');
|
2019-03-01 21:38:59 +07:00
|
|
|
var fs = require('fs');
|
2019-02-28 14:11:03 +07:00
|
|
|
ryzen_adj_path.value = getRyzenAdjExecutablePath();
|
2019-03-01 21:38:59 +07:00
|
|
|
if (!fs.existsSync(ryzen_adj_path.value)) {
|
2019-02-28 14:11:03 +07:00
|
|
|
notification('danger', "Path to ryzenadj.exe is wrong, please fix it in settings tab.");
|
|
|
|
}
|
2019-03-01 00:40:42 +07:00
|
|
|
const settings = require('electron-settings');
|
2019-03-01 23:28:08 +07:00
|
|
|
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');
|
|
|
|
|
|
|
|
seconds = parseInt(settings.get('settings.reapply_periodically'));
|
|
|
|
seconds = seconds >= 0 ? seconds : 0;
|
|
|
|
document.getElementById('reapply_periodically').value = seconds;
|
|
|
|
document.getElementById('reapply_periodically_range').value = seconds;
|
2019-02-28 14:11:03 +07:00
|
|
|
}
|
|
|
|
|
2019-03-01 00:21:55 +07:00
|
|
|
/**
|
|
|
|
* Will open a dialog to let user choose where is ryzenadj.exe.
|
|
|
|
*/
|
2019-02-28 14:11:03 +07:00
|
|
|
function askingForRyzenAdjExecutablePath() {
|
|
|
|
var remote = require('electron').remote;
|
|
|
|
var dialog = remote.require('electron').dialog;
|
2019-03-01 21:38:59 +07:00
|
|
|
|
2019-02-28 14:11:03 +07:00
|
|
|
var path = dialog.showOpenDialog({
|
2019-03-01 00:03:51 +07:00
|
|
|
properties: ['openFile']
|
2019-02-28 14:11:03 +07:00
|
|
|
}, function (filePaths) {
|
|
|
|
if (typeof filePaths[0] !== 'undefined') {
|
|
|
|
const settings = require('electron-settings');
|
|
|
|
settings.set("settings", {
|
2019-03-01 00:40:22 +07:00
|
|
|
...settings.get('settings'),
|
2019-02-28 14:11:03 +07:00
|
|
|
ryzen_adj_path: filePaths[0]
|
|
|
|
});
|
|
|
|
notification('primary', 'Path to ryzenAdj.exe has been saved.');
|
2019-03-01 00:03:51 +07:00
|
|
|
appendLog(`askingForRyzenAdjExecutablePath(): ${filePaths[0]}`);
|
2019-02-28 14:11:03 +07:00
|
|
|
} else {
|
|
|
|
notification('warning', 'No path given, nothing changed.');
|
|
|
|
}
|
|
|
|
preFillSettings();
|
|
|
|
});
|
|
|
|
}
|
2019-03-01 00:03:51 +07:00
|
|
|
|
2019-03-01 00:21:55 +07:00
|
|
|
/**
|
|
|
|
* Will append logs to the logs tab.
|
|
|
|
* @param {string} message The message to be logged.
|
|
|
|
*/
|
2019-03-01 00:03:51 +07:00
|
|
|
function appendLog(message) {
|
|
|
|
var log_area = document.getElementById('logs');
|
|
|
|
log_area.value += message + "\n";
|
2019-03-01 00:22:19 +07:00
|
|
|
console.log(message);
|
2019-03-01 00:23:05 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will save the latest used settings.
|
|
|
|
*/
|
|
|
|
function saveLatestUsedSettings() {
|
|
|
|
var inputs = document.querySelectorAll('#controller-tab input');
|
|
|
|
var latest_controller_tabs_settings = {};
|
|
|
|
inputs.forEach(element => {
|
|
|
|
let id = element.id;
|
|
|
|
let value = element.value;
|
|
|
|
latest_controller_tabs_settings[id] = value;
|
|
|
|
});
|
|
|
|
const settings = require('electron-settings');
|
|
|
|
let ret = settings.set("latest_controller_tabs_settings", latest_controller_tabs_settings);
|
|
|
|
appendLog(`saveLatestUsedSettings(): ${JSON.stringify(latest_controller_tabs_settings)}`);
|
|
|
|
appendLog(`saveLatestUsedSettings(): ${JSON.stringify(ret)}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Will load the latest settings and refresh the controller tab's values.
|
2019-03-01 21:38:59 +07:00
|
|
|
*
|
2019-03-01 00:40:42 +07:00
|
|
|
* Will also apply latest settings if settings.apply_last_settings_on_launch is true.
|
2019-03-01 00:23:05 +07:00
|
|
|
*/
|
|
|
|
function loadLatestUsedSettings() {
|
|
|
|
const settings = require('electron-settings');
|
|
|
|
var latest_controller_tabs_settings = settings.get("latest_controller_tabs_settings");
|
|
|
|
appendLog(`loadLatestUsedSettings(): ${JSON.stringify(latest_controller_tabs_settings)}`);
|
|
|
|
for (const id in latest_controller_tabs_settings) {
|
|
|
|
if (latest_controller_tabs_settings.hasOwnProperty(id)) {
|
|
|
|
const value = latest_controller_tabs_settings[id];
|
|
|
|
let input = document.getElementById(id);
|
|
|
|
if (input) {
|
|
|
|
input.value = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-01 00:40:42 +07:00
|
|
|
if (settings.get('settings.apply_last_settings_on_launch')) {
|
|
|
|
applyRyzenSettings();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-01 22:26:34 +07:00
|
|
|
/**
|
|
|
|
* Listen settings tab inputs to save their values.
|
|
|
|
*/
|
2019-03-01 00:40:42 +07:00
|
|
|
function registerEventListenerForSettingsInput() {
|
|
|
|
const settings = require('electron-settings');
|
|
|
|
|
|
|
|
var apply_last_settings_on_launch = document.getElementById('apply_last_settings_on_launch');
|
|
|
|
apply_last_settings_on_launch.addEventListener('change', function() {
|
|
|
|
settings.set('settings', {
|
|
|
|
...settings.get('settings'),
|
|
|
|
apply_last_settings_on_launch: !!apply_last_settings_on_launch.checked
|
|
|
|
});
|
|
|
|
});
|
2019-03-01 22:24:43 +07:00
|
|
|
var minimize_to_tray = document.getElementById('minimize_to_tray');
|
|
|
|
minimize_to_tray.addEventListener('change', function() {
|
|
|
|
settings.set('settings', {
|
|
|
|
...settings.get('settings'),
|
|
|
|
minimize_to_tray: !!minimize_to_tray.checked
|
|
|
|
});
|
|
|
|
});
|
2019-03-01 23:12:05 +07:00
|
|
|
var reapply_periodically = document.getElementById('reapply_periodically');
|
|
|
|
reapply_periodically.addEventListener('change', function() {
|
|
|
|
reApplyPeriodically(reapply_periodically.value);
|
|
|
|
settings.set('settings', {
|
|
|
|
...settings.get('settings'),
|
|
|
|
reapply_periodically: reapply_periodically.value
|
|
|
|
});
|
|
|
|
});
|
2019-03-01 00:23:05 +07:00
|
|
|
}
|
2019-03-01 21:38:59 +07:00
|
|
|
|
2019-03-01 22:26:34 +07:00
|
|
|
/**
|
|
|
|
* Simply display version in appropriate zone.
|
|
|
|
*/
|
2019-03-01 21:38:59 +07:00
|
|
|
function displayVersion() {
|
|
|
|
const pjson = require('./package.json');
|
|
|
|
document.getElementById('version').innerHTML = `v${pjson.version}`;
|
|
|
|
}
|
2019-03-01 23:12:05 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Re-apply flow for "reapply_periodically" settings.
|
|
|
|
* @param {number} seconds Interval in seconds between each apply.
|
|
|
|
*/
|
|
|
|
function reApplyPeriodically(seconds) {
|
2019-03-01 23:24:39 +07:00
|
|
|
seconds = parseInt(seconds) >= 0 ? parseInt(seconds) : 0;
|
2019-03-01 23:12:05 +07:00
|
|
|
appendLog(`reApplyPeriodically(): seconds = ${seconds}`);
|
|
|
|
appendLog(`reApplyPeriodically(): document.reapplyLoop = ${document.reapplyLoop}`);
|
|
|
|
clearInterval(document.reapplyLoop);
|
|
|
|
document.reapplyLoop = false;
|
|
|
|
|
|
|
|
if (seconds <= 0) {
|
|
|
|
if (!document.isStarting) {
|
|
|
|
notification('primary', "Ryzen Controller no more will re-apply ryzenadj periodically.");
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.reapplyLoop = setInterval(applyRyzenSettings, seconds * 1000);
|
|
|
|
}
|
2019-03-02 22:09:06 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Display tooltip on each options.
|
|
|
|
*/
|
|
|
|
function displayOptionDescription() {
|
|
|
|
appendLog("displayOptionDescription():");
|
|
|
|
const options_description = require('./js/options_description.json');
|
|
|
|
for (const option in options_description) {
|
|
|
|
if (options_description.hasOwnProperty(option)) {
|
|
|
|
appendLog(`- option: ${option}`);
|
|
|
|
const description = options_description[option];
|
|
|
|
const node = document.getElementById(option).parentElement.parentElement;
|
|
|
|
node.setAttribute('uk-tooltip', description);
|
|
|
|
UIkit.tooltip(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|