Skip to content

Commit

Permalink
Merge pull request #6 from Emiliopg91/develop
Browse files Browse the repository at this point in the history
GUI redesign and default TDP values for Custom
  • Loading branch information
Emiliopg91 authored Sep 13, 2024
2 parents 7f5da4b + 4057a46 commit 4709423
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 133 deletions.
12 changes: 6 additions & 6 deletions assets/translations.i18n.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"profile.for": {
"en": "Profile for {{name}}",
"es": "Perfil para {{name}}"
"en": "Profile",
"es": "Perfil"
},
"smt.description": {
"en": "Enable multithreading. Best disabled for no CPU intensive software",
Expand Down Expand Up @@ -72,12 +72,12 @@
"es": "Incrementa la vida útil de batería limitando la carga al 80%"
},
"main.menu": {
"en": "main menu",
"es": "menú principal"
"en": "Main menu",
"es": "Menú principal"
},
"mode.SILENT": {
"en": "SILENT",
"es": "SILENCIOSO"
"es": "SILENCIO"
},
"mode.PERFORMANCE": {
"en": "PERFORMANCE",
Expand All @@ -89,7 +89,7 @@
},
"mode.CUSTOM": {
"en": "CUSTOM",
"es": "PERSONALIZADO"
"es": "CUSTOM"
},
"contribute.info": {
"en": "Contribute",
Expand Down
33 changes: 0 additions & 33 deletions src/components/collapsibleItem.tsx

This file was deleted.

121 changes: 64 additions & 57 deletions src/components/cpuBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { NotchLabel, PanelSectionRow, SliderField, ToggleField } from "decky-frontend-lib"
import { useEffect, useState, VFC } from "react"
import { NotchLabel, PanelSection, PanelSectionRow, SliderField, ToggleField, Field } from "decky-frontend-lib"
import { FC, useEffect, useState } from "react"

import { useProfile } from "../hooks/useProfile";
import { Logger, Translator } from "decky-plugin-framework";
import { Profiles } from "../settings/profiles";
import { BackendUtils } from "../utils/backend";
import { Mode } from "../utils/mode";
import { debounce } from 'lodash'
import { CollapsibleItem } from "./collapsibleItem";


const saveSettings = debounce((id: string, name: string, mode: Number, spl: Number, sppl: Number, fppl: Number, cpuBoost: Boolean, smtEnabled: Boolean) => {
Expand All @@ -16,7 +15,7 @@ const saveSettings = debounce((id: string, name: string, mode: Number, spl: Numb
BackendUtils.setTdpProfile(Profiles.getProfileForId(id))
}, 500)

export const CpuBlock: VFC<{ collapsed: boolean, onCollapse: () => void }> = ({ collapsed, onCollapse }) => {
export const CpuBlock: FC = () => {
const modeIndexes: Array<Number> = []
const modeTags: Array<String> = []
const notchLabels: NotchLabel[] = [];
Expand Down Expand Up @@ -66,16 +65,13 @@ export const CpuBlock: VFC<{ collapsed: boolean, onCollapse: () => void }> = ({
}, [id])

const onModeChange = (newVal: number) => {
if (newVal == modeTags.indexOf(Mode[Mode.CUSTOM])) {
saveSettings(id, name, newVal, spl, sppl, fppl, cpuBoost, smtEnabled)
} else {
const tdps = Profiles.getTdpForMode(newVal)
saveSettings(id, name, newVal, tdps[0], tdps[1], tdps[2], cpuBoost, smtEnabled)

setSpl(tdps[0])
setSppl(tdps[1])
setFppl(tdps[2])
}
let tdps = Profiles.getTdpForMode(newVal)

saveSettings(id, name, newVal, tdps[0], tdps[1], tdps[2], cpuBoost, smtEnabled)

setSpl(tdps[0])
setSppl(tdps[1])
setFppl(tdps[2])
setMode(newVal)
}

Expand Down Expand Up @@ -123,13 +119,14 @@ export const CpuBlock: VFC<{ collapsed: boolean, onCollapse: () => void }> = ({
}

return (
<CollapsibleItem title={Translator.translate("performance.settings")} collapsed={collapsed} onCollapse={onCollapse}>
<PanelSection >
<PanelSectionRow>
<span>{Translator.translate("profile.for", { name })}</span>
<Field label={Translator.translate("profile.for")} bottomSeparator="standard">
{name}
</Field>
</PanelSectionRow>
<PanelSectionRow>
<SliderField
label={Translator.translate("performance.mode")}
value={mode}
min={0}
max={modeIndexes.length - 1}
Expand All @@ -141,46 +138,56 @@ export const CpuBlock: VFC<{ collapsed: boolean, onCollapse: () => void }> = ({
bottomSeparator={"none"}
onChange={onModeChange}
/>
<SliderField
label={Translator.translate("spl.desc")}
value={spl}
disabled={mode !== modeTags.indexOf(Mode[Mode.CUSTOM].substring(0, 1) + Mode[Mode.CUSTOM].substring(1))}
showValue
step={1}
valueSuffix="W"
min={5}
max={30}
validValues="range"
bottomSeparator="none"
onChange={onSplChange}
/>
<SliderField
label={Translator.translate("sppl.desc")}
value={sppl}
disabled={mode !== modeTags.indexOf(Mode[Mode.CUSTOM].substring(0, 1) + Mode[Mode.CUSTOM].substring(1))}
showValue
step={1}
valueSuffix="W"
min={5}
max={30}
validValues="range"
bottomSeparator="none"
onChange={onSpplChange}
/>
<SliderField
label={Translator.translate("fppl.desc")}
value={fppl}
disabled={mode !== modeTags.indexOf(Mode[Mode.CUSTOM].substring(0, 1) + Mode[Mode.CUSTOM].substring(1))}
showValue
step={1}
valueSuffix="W"
min={5}
max={30}
validValues="range"
bottomSeparator="none"
onChange={onFpplChange}
/>
</PanelSectionRow>
{mode == 3 &&
<>
<PanelSectionRow>
<SliderField
label={Translator.translate("spl.desc")}
value={spl}
disabled={mode !== modeTags.indexOf(Mode[Mode.CUSTOM].substring(0, 1) + Mode[Mode.CUSTOM].substring(1))}
showValue
step={1}
valueSuffix="W"
min={5}
max={30}
validValues="range"
bottomSeparator="none"
onChange={onSplChange}
/>
</PanelSectionRow>
<PanelSectionRow>
<SliderField
label={Translator.translate("sppl.desc")}
value={sppl}
disabled={mode !== modeTags.indexOf(Mode[Mode.CUSTOM].substring(0, 1) + Mode[Mode.CUSTOM].substring(1))}
showValue
step={1}
valueSuffix="W"
min={5}
max={30}
validValues="range"
bottomSeparator="none"
onChange={onSpplChange}
/>
</PanelSectionRow>
<PanelSectionRow>
<SliderField
label={Translator.translate("fppl.desc")}
value={fppl}
disabled={mode !== modeTags.indexOf(Mode[Mode.CUSTOM].substring(0, 1) + Mode[Mode.CUSTOM].substring(1))}
showValue
step={1}
valueSuffix="W"
min={5}
max={30}
validValues="range"
bottomSeparator="none"
onChange={onFpplChange}
/>
</PanelSectionRow>
</>
}
<PanelSectionRow>
<ToggleField
label="SMT"
Expand All @@ -199,6 +206,6 @@ export const CpuBlock: VFC<{ collapsed: boolean, onCollapse: () => void }> = ({
highlightOnFocus
/>
</PanelSectionRow>
</CollapsibleItem>
</PanelSection>
);
};
11 changes: 5 additions & 6 deletions src/components/pluginBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { ButtonItem, Field, PanelSectionRow } from "decky-frontend-lib"
import { useEffect, useState, VFC } from "react"
import { ButtonItem, Field, PanelSection, PanelSectionRow } from "decky-frontend-lib"
import { FC, useEffect, useState, } from "react"
import { Constants } from "../utils/constants";
import { BackendUtils } from "../utils/backend";
import { CollapsibleItem } from "./collapsibleItem";
import { Toast, Translator } from "decky-plugin-framework";

const getLatestVersionNum = async () => {
Expand All @@ -19,7 +18,7 @@ const getLatestVersionNum = async () => {
return "";
};

export const PluginBlock: VFC<{ collapsed: boolean, onCollapse: () => void }> = ({ collapsed, onCollapse }) => {
export const PluginBlock: FC = () => {
const [latestVersionNum, setLatestVersionNum] = useState("");
const [isUpdated, setIsUpdated] = useState(true);
const [isDoingThings, setIsDoingThings] = useState(false);
Expand All @@ -34,7 +33,7 @@ export const PluginBlock: VFC<{ collapsed: boolean, onCollapse: () => void }> =

return (
<>
<CollapsibleItem title={Translator.translate('plugin.info')} collapsed={collapsed} onCollapse={onCollapse}>
<PanelSection>
<>
<PanelSectionRow>
<Field label={Translator.translate("installed.version")} bottomSeparator="none">
Expand Down Expand Up @@ -72,7 +71,7 @@ export const PluginBlock: VFC<{ collapsed: boolean, onCollapse: () => void }> =
</>
)}
</>
</CollapsibleItem >
</PanelSection >
</>
);
};
11 changes: 5 additions & 6 deletions src/components/systemBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { PanelSectionRow, ToggleField } from "decky-frontend-lib"
import { useState, VFC } from "react"
import { PanelSection, PanelSectionRow, ToggleField } from "decky-frontend-lib"
import { FC, useState } from "react"
import { SystemSettings } from "../settings/system";
import { CollapsibleItem } from "./collapsibleItem";
import { Translator } from "decky-plugin-framework";

export const SystemBlock: VFC<{ collapsed: boolean, onCollapse: () => void }> = ({ collapsed, onCollapse }) => {
export const SystemBlock: FC = () => {
const [limitBattery, setLimitBattery] = useState(SystemSettings.getLimitBattery())
const onLimitBatteryChange = (newVal: boolean) => {
SystemSettings.setLimitBattery(newVal);
Expand All @@ -14,7 +13,7 @@ export const SystemBlock: VFC<{ collapsed: boolean, onCollapse: () => void }> =

return (
<>
<CollapsibleItem title={Translator.translate("system.info")} collapsed={collapsed} onCollapse={onCollapse}>
<PanelSection>
<PanelSectionRow>
<ToggleField
label={Translator.translate("limit.battery")}
Expand All @@ -24,7 +23,7 @@ export const SystemBlock: VFC<{ collapsed: boolean, onCollapse: () => void }> =
highlightOnFocus
/>
</PanelSectionRow>
</CollapsibleItem>
</PanelSection>
</>
);
};
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
import { State } from "./utils/state";
import { Profile, Profiles } from './settings/profiles'
import { BackendUtils } from "./utils/backend";
import { SystemSettings } from "./settings/system";
import { SystemSettings } from "./settings/system";

let gameInterval: NodeJS.Timeout | undefined = undefined;
let onSuspendUnregister: Function | undefined;
Expand Down
Loading

0 comments on commit 4709423

Please sign in to comment.