feat: Display a preset compatibility note for each online preset.

This commit is contained in:
Quentin “Storm1er” Decaunes 2020-03-16 16:36:18 +01:00
parent e5e0724871
commit 775ac86f35
12 changed files with 86 additions and 23 deletions

View File

@ -3,7 +3,11 @@ import TopBar from "./components/TopBar";
import SceneSelector from "./components/SceneSelector"; import SceneSelector from "./components/SceneSelector";
import Scene from "./scenes/Scene"; import Scene from "./scenes/Scene";
import { HashRouter as Router } from "react-router-dom"; import { HashRouter as Router } from "react-router-dom";
import SysInfoContext, { createMachineSignature, SysInfoState } from "./contexts/SysInfoContext"; import SysInfoContext, {
createMachineSignature,
SysInfoState,
createPermissiveMachineSignature,
} from "./contexts/SysInfoContext";
import LightModeContext from "./contexts/LightModeContext"; import LightModeContext from "./contexts/LightModeContext";
import { checkNewVersion } from "./contexts/RyzenControllerAppContext"; import { checkNewVersion } from "./contexts/RyzenControllerAppContext";
import LocaleContext, { getTranslation } from "./contexts/LocaleContext"; import LocaleContext, { getTranslation } from "./contexts/LocaleContext";
@ -34,6 +38,7 @@ class App extends React.Component<{}, AppState> {
system: false, system: false,
bios: false, bios: false,
signature: false, signature: false,
permissiveSignature: false,
}; };
state = { state = {
@ -79,6 +84,7 @@ class App extends React.Component<{}, AppState> {
si.getAllData() si.getAllData()
.then((data: SysInfoState) => { .then((data: SysInfoState) => {
data.signature = createMachineSignature(data); data.signature = createMachineSignature(data);
data.permissiveSignature = createPermissiveMachineSignature(data);
this._isMounted && this.setState({ sysinfo: data }); this._isMounted && this.setState({ sysinfo: data });
}) })
.catch((error: string) => { .catch((error: string) => {

View File

@ -51,7 +51,11 @@ class PresetButtons extends React.Component<PresetButtonsProps, {}> {
{(presetsOnlineContext: PresetsOnlineContextType) => ( {(presetsOnlineContext: PresetsOnlineContextType) => (
<button <button
className="uk-button uk-button-small uk-button-default" className="uk-button uk-button-small uk-button-default"
onClick={this.uploadPreset(presetsOnlineContext, sysinfo.signature)} onClick={this.uploadPreset(
presetsOnlineContext,
sysinfo.signature,
sysinfo.permissiveSignature
)}
> >
{getTranslation("presetButtons.upload", "Upload")} {getTranslation("presetButtons.upload", "Upload")}
</button> </button>
@ -77,17 +81,21 @@ class PresetButtons extends React.Component<PresetButtonsProps, {}> {
uploadPreset( uploadPreset(
presetsOnlineContext: PresetsOnlineContextType, presetsOnlineContext: PresetsOnlineContextType,
signature: string | false signature: string | false,
permissiveSignature: string | false
): (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void { ): (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void {
return () => { return () => {
if (!signature) { if (!signature || !permissiveSignature) {
NotificationContext.warning( NotificationContext.warning(
getTranslation("presetButtons.mustWaitForSignatureGen", "You must wait for laptop signature to be generated") getTranslation("presetButtons.mustWaitForSignatureGen", "You must wait for laptop signature to be generated")
); );
return; return;
} }
let presetsWithSameName = presetsOnlineContext.list.filter(preset => { let presetsWithSameName = presetsOnlineContext.list.filter((preset: ApiPreset) => {
return preset.name === this.props.presetName && preset.systemHash === signature; return (
preset.name === this.props.presetName &&
(preset.systemHash === signature || preset.permissiveSystemHash === permissiveSignature)
);
}); });
if (presetsWithSameName.length > 0) { if (presetsWithSameName.length > 0) {
NotificationContext.warning( NotificationContext.warning(
@ -110,6 +118,7 @@ class PresetButtons extends React.Component<PresetButtonsProps, {}> {
.uploadPreset({ .uploadPreset({
name: this.props.presetName, name: this.props.presetName,
systemHash: signature, systemHash: signature,
permissiveSystemHash: permissiveSignature,
ryzenAdjArguments: this.props.preset, ryzenAdjArguments: this.props.preset,
}) })
.then(value => { .then(value => {

View File

@ -12,17 +12,20 @@ function PresetOnline() {
{(sysInfoContext: SysInfoState) => ( {(sysInfoContext: SysInfoState) => (
<PresetsOnlineContext.Consumer> <PresetsOnlineContext.Consumer>
{(presetsOnlineContext: PresetsOnlineContextType) => { {(presetsOnlineContext: PresetsOnlineContextType) => {
return presetsOnlineContext.list const compatPresetList = presetsOnlineContext.list
.filter(preset => isPresetValid(preset.ryzenAdjArguments)) .filter(preset => isPresetValid(preset.ryzenAdjArguments))
.filter(preset => preset.systemHash === sysInfoContext.signature).length && sysInfoContext?.signature ? ( .filter(
preset =>
preset.permissiveSystemHash === sysInfoContext.permissiveSignature ||
preset.systemHash === sysInfoContext.signature
);
return compatPresetList.length && sysInfoContext?.signature ? (
<ul className="uk-margin uk-list uk-list-large uk-list-striped"> <ul className="uk-margin uk-list uk-list-large uk-list-striped">
{presetsOnlineContext.list {compatPresetList.map((preset: ApiPreset, index) => {
.filter(preset => isPresetValid(preset.ryzenAdjArguments)) const presetName = preset.name;
.filter(preset => preset.systemHash === sysInfoContext.signature) return <PresetOnlineLine preset={preset} key={`online_${index}_${presetName}_btn`} />;
.map((preset: ApiPreset, index) => { })}
const presetName = preset.name;
return <PresetOnlineLine preset={preset} key={`online_${index}_${presetName}_btn`} />;
})}
</ul> </ul>
) : presetsOnlineContext.error && !presetsOnlineContext.loading ? ( ) : presetsOnlineContext.error && !presetsOnlineContext.loading ? (
<Card title={getTranslation("PresetOnline.errorLoadingPresets", "Unable to load presets.")}> <Card title={getTranslation("PresetOnline.errorLoadingPresets", "Unable to load presets.")}>
@ -35,7 +38,7 @@ function PresetOnline() {
{getTranslation("PresetOnline.retryLoadingPresetListBtn", "Retry")} {getTranslation("PresetOnline.retryLoadingPresetListBtn", "Retry")}
</button> </button>
</Card> </Card>
) : presetsOnlineContext.loading || !sysInfoContext?.signature ? ( ) : presetsOnlineContext.loading || !sysInfoContext?.signature || !sysInfoContext?.permissiveSignature ? (
<div className="uk-flex uk-flex-center"> <div className="uk-flex uk-flex-center">
<div uk-spinner="ratio: 2"></div> <div uk-spinner="ratio: 2"></div>
</div> </div>

View File

@ -1,6 +1,10 @@
import * as React from "react"; import * as React from "react";
import PresetSummary from "../components/PresetSummary"; import PresetSummary from "../components/PresetSummary";
import PresetOnlineButtons from "../components/PresetOnlineButtons"; import PresetOnlineButtons from "../components/PresetOnlineButtons";
import SysInfoContext, { SysInfoState } from "../contexts/SysInfoContext";
import { getTranslation } from "../contexts/LocaleContext";
const compatSentence = getTranslation("presetLine.compatibility", "Compatibility level:");
type PresetOnlineLineProps = { type PresetOnlineLineProps = {
preset: ApiPreset; preset: ApiPreset;
@ -24,6 +28,22 @@ class PresetOnlineLine extends React.PureComponent<PresetOnlineLineProps, {}> {
downvote={this.props.preset.downvote} downvote={this.props.preset.downvote}
/> />
</div> </div>
<SysInfoContext.Consumer>
{(sysInfo: SysInfoState) => {
var compatLevel = 1;
if (sysInfo.permissiveSignature === this.props.preset.permissiveSystemHash) {
compatLevel = 2;
}
if (sysInfo.signature === this.props.preset.systemHash) {
compatLevel = 3;
}
return (
<div className="uk-width-1-1">
{compatSentence} {compatLevel}/3
</div>
);
}}
</SysInfoContext.Consumer>
</div> </div>
</li> </li>
); );

View File

@ -11,6 +11,7 @@ export type SysInfoState = {
system: Systeminformation.SystemData | false; system: Systeminformation.SystemData | false;
bios: Systeminformation.BiosData | false; bios: Systeminformation.BiosData | false;
signature: string | false; signature: string | false;
permissiveSignature: string | false;
error?: string; error?: string;
}; };
@ -36,6 +37,20 @@ const createMachineSignature = function(data: SysInfoState): string | false {
}); });
}; };
const createPermissiveMachineSignature = function(data: SysInfoState): string | false {
if (data.error) {
return false;
}
if (data.system === false || data.graphics === false) {
return false;
}
return hasher({
"system.manufacturer": data.system.manufacturer,
"system.model": data.system.model,
});
};
let context: SysInfoState = { let context: SysInfoState = {
cpu: false, cpu: false,
graphics: false, graphics: false,
@ -44,10 +59,11 @@ let context: SysInfoState = {
system: false, system: false,
bios: false, bios: false,
signature: false, signature: false,
permissiveSignature: false,
}; };
const SysInfoContext = createContext(context); const SysInfoContext = createContext(context);
SysInfoContext.displayName = "SysInfoContext"; SysInfoContext.displayName = "SysInfoContext";
export default SysInfoContext; export default SysInfoContext;
export { createMachineSignature }; export { createMachineSignature, createPermissiveMachineSignature };

View File

@ -105,5 +105,6 @@
"PresetOnline.errorLoadingPresets": "无法加载预设。", "PresetOnline.errorLoadingPresets": "无法加载预设。",
"PresetOnline.retryLoadingPresetListBtn": "重试", "PresetOnline.retryLoadingPresetListBtn": "重试",
"PresetOnline.pleaseCheckInternetConnection": "请检查您的互联网连接。", "PresetOnline.pleaseCheckInternetConnection": "请检查您的互联网连接。",
"presetButtons.uploadError": "上载预设时发生错误" "presetButtons.uploadError": "上载预设时发生错误",
"presetLine.compatibility": "兼容性:"
} }

View File

@ -105,5 +105,6 @@
"PresetOnline.errorLoadingPresets": "Presets können nicht geladen werden.", "PresetOnline.errorLoadingPresets": "Presets können nicht geladen werden.",
"PresetOnline.retryLoadingPresetListBtn": "Wiederholen", "PresetOnline.retryLoadingPresetListBtn": "Wiederholen",
"PresetOnline.pleaseCheckInternetConnection": "Bitte überprüfe deine Internetverbindung.", "PresetOnline.pleaseCheckInternetConnection": "Bitte überprüfe deine Internetverbindung.",
"presetButtons.uploadError": "Beim Hochladen der Voreinstellung ist ein Fehler aufgetreten" "presetButtons.uploadError": "Beim Hochladen der Voreinstellung ist ein Fehler aufgetreten",
"presetLine.compatibility": "Kompatibilität:"
} }

View File

@ -105,5 +105,6 @@
"PresetOnline.errorLoadingPresets": "Unable to load presets.", "PresetOnline.errorLoadingPresets": "Unable to load presets.",
"PresetOnline.retryLoadingPresetListBtn": "Retry", "PresetOnline.retryLoadingPresetListBtn": "Retry",
"PresetOnline.pleaseCheckInternetConnection": "Please check your internet connection.", "PresetOnline.pleaseCheckInternetConnection": "Please check your internet connection.",
"presetButtons.uploadError": "An error occured while uploading the preset" "presetButtons.uploadError": "An error occured while uploading the preset",
"presetLine.compatibility": "Compatibility:"
} }

View File

@ -105,5 +105,6 @@
"PresetOnline.errorLoadingPresets": "Impossible de charger les presets en ligne.", "PresetOnline.errorLoadingPresets": "Impossible de charger les presets en ligne.",
"PresetOnline.retryLoadingPresetListBtn": "Réessayer", "PresetOnline.retryLoadingPresetListBtn": "Réessayer",
"PresetOnline.pleaseCheckInternetConnection": "Veuillez vérifier votre connexion internet.", "PresetOnline.pleaseCheckInternetConnection": "Veuillez vérifier votre connexion internet.",
"presetButtons.uploadError": "Une erreur est survenu lors de l'upload du preset" "presetButtons.uploadError": "Une erreur est survenu lors de l'upload du preset",
"presetLine.compatibility": "Compatibilité :"
} }

View File

@ -105,5 +105,6 @@
"PresetOnline.errorLoadingPresets": "Ön ayarlar yüklenemiyor.", "PresetOnline.errorLoadingPresets": "Ön ayarlar yüklenemiyor.",
"PresetOnline.retryLoadingPresetListBtn": "Yeniden Dene", "PresetOnline.retryLoadingPresetListBtn": "Yeniden Dene",
"PresetOnline.pleaseCheckInternetConnection": "Lütfen internet bağlantınızı kontrol edin.", "PresetOnline.pleaseCheckInternetConnection": "Lütfen internet bağlantınızı kontrol edin.",
"presetButtons.uploadError": "Ön ayar yüklenirken bir hata oluştu" "presetButtons.uploadError": "Ön ayar yüklenirken bir hata oluştu",
"presetLine.compatibility": "bağdaşma:"
} }

View File

@ -107,6 +107,7 @@ type RyzenControllerAppContextType = {
type ApiPreset = { type ApiPreset = {
id: number; id: number;
systemHash: string; systemHash: string;
permissiveSystemHash: string;
upvote: number; upvote: number;
downvote: number; downvote: number;
name: string; name: string;

View File

@ -25,7 +25,10 @@ class SettingsScene extends React.PureComponent<{}, {}> {
"This will be used to ensure downloaded presets compatibility." "This will be used to ensure downloaded presets compatibility."
)}`} )}`}
> >
System hash: {sysInfoContext.signature || getTranslation("SettingsScene.loadingSysHash", "Loading...")} System hash:{" "}
{sysInfoContext.signature && sysInfoContext.permissiveSignature
? `${sysInfoContext.signature} || ${sysInfoContext.permissiveSignature}`
: getTranslation("SettingsScene.loadingSysHash", "Loading...")}
</p> </p>
)} )}
</SysInfoContext.Consumer> </SysInfoContext.Consumer>