fix: Better status scene, now displaying error messages.

This commit is contained in:
Torsten Simon 2021-09-19 09:01:55 +00:00 committed by Quentin “Storm1er” Decaunes
parent f8721ad229
commit 06c9d0d7c6
4 changed files with 46 additions and 7 deletions

View File

@ -230,9 +230,9 @@ export const ryzenAdjProcess = function(parameters: Array<string>): Promise<stri
console.log(`${executablePath} ${parameters.join(" ")}`);
child(executablePath, parameters, function(err: string, data: Buffer) {
var output = data?.toString();
const output = data?.toString();
if (err) {
rej(err);
rej({ error: err, output });
} else if (output) {
res(output);
}

View File

@ -126,5 +126,7 @@
"statusScene.showRawData": "Rohdaten anzeigen",
"statusScene.tableParameter": "Parameter",
"statusScene.tableValue": "Aktueller Wert",
"statusScene.tableMaxValue": "Max. Wert"
"statusScene.tableMaxValue": "Max. Wert",
"statusScene.failed": "Fehler beim Laden der Daten von rjzenadj. Bitte prüfe die Einstellungen",
"statusScene.permissions": "Fehler beim Datenzugriff. Stelle sicher, dass Ryzen Controller als Administrator ausgeführt wird"
}

View File

@ -126,5 +126,7 @@
"statusScene.showRawData": "Show raw data",
"statusScene.tableParameter": "Parameter",
"statusScene.tableValue": "Current value",
"statusScene.tableMaxValue": "Max. value"
"statusScene.tableMaxValue": "Max. value",
"statusScene.failed": "Failed to fetch data from ryzenadj. Please check your settings",
"statusScene.permissions": "Error accessing data. Make sure Ryzen Controller is running as Administrator"
}

View File

@ -6,8 +6,19 @@ import LightModeContext from "../contexts/LightModeContext";
import { appContextSettingsKey, RyzenControllerSettingsDefinitions } from "../contexts/RyzenControllerAppContext";
const electronSettings = window.require("electron-settings");
enum State {
Init,
Valid,
PermissionError,
GernericError,
}
const i18n = {
noData: getTranslation("statusScene.noData", "No data to show"),
failed: getTranslation("statusScene.failed", "Failed to fetch data from ryzenadj. Please check your settings"),
permissions: getTranslation(
"statusScene.permissions",
"Error accessing data. Make sure Ryzen Controller is running as Administrator"
),
thmValueCore: getTranslation("statusScene.thmValueCore", "Core Temperature"),
pptValueApu: getTranslation("statusScene.pptValueApu", "Package Power Consumption"),
showRawData: getTranslation("statusScene.showRawData", "Show raw data"),
@ -18,12 +29,25 @@ const i18n = {
class PresetsScene extends React.Component {
_isMounted = false;
_state = State.Init;
data: { [key: string]: number } = {};
allData = false;
__constructor() {}
async loadData() {
try {
this.parseData(await ryzenAdjProcess(["-i"]));
} catch (e) {
console.warn(e.output);
if (e.output.includes("check permission")) {
this._state = State.PermissionError;
} else {
this._state = State.GernericError;
}
}
}
async componentDidMount() {
this._isMounted = true;
this.parseData(await ryzenAdjProcess(["-i"]));
this.loadData();
let intervalDuration =
electronSettings.get(appContextSettingsKey)?.settings.statusUpdateInterval ||
RyzenControllerSettingsDefinitions["statusUpdateInterval"].default;
@ -33,10 +57,15 @@ class PresetsScene extends React.Component {
clearInterval(interval);
return;
}
this.parseData(await ryzenAdjProcess(["-i"]));
this.loadData();
}, intervalDuration as number);
}
parseData(output: string) {
if (!output && this._state !== State.Valid) {
this._state = State.GernericError;
return;
}
console.warn(output);
output
.split("\n")
.slice(2)
@ -60,8 +89,14 @@ class PresetsScene extends React.Component {
}
render() {
if (this._state === State.GernericError) {
return <h2 className="uk-flex uk-flex-center uk-text-center">{i18n.failed}</h2>;
}
if (this._state === State.PermissionError) {
return <h2 className="uk-flex uk-flex-center uk-text-center">{i18n.permissions}</h2>;
}
if (Object.keys(this.data).length === 0) {
return <h2 className="uk-flex uk-flex-center">{i18n.noData}</h2>;
return <h2 className="uk-flex uk-flex-center uk-text-center">{i18n.noData}</h2>;
}
return (
<LightModeContext.Consumer>