From 68cf16aa9b3f0bc01d2edf8e47a5c4b079e847d9 Mon Sep 17 00:00:00 2001 From: honjow Date: Tue, 28 May 2024 20:57:54 +0800 Subject: [PATCH] fix disable tdp limit --- src/components/cpu.tsx | 16 +++----------- src/util/backend.ts | 49 ++++++++++++++++++++++++++++-------------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/components/cpu.tsx b/src/components/cpu.tsx index df51971..594ca56 100755 --- a/src/components/cpu.tsx +++ b/src/components/cpu.tsx @@ -4,7 +4,7 @@ import { ToggleField, } from "decky-frontend-lib"; import { useEffect, useState, VFC } from "react"; -import { Settings, Backend, PluginManager, ComponentName, UpdateType, GPUMODE, Patch, SteamUtils } from "../util"; +import { Settings, Backend, PluginManager, ComponentName, UpdateType, GPUMODE, Patch } from "../util"; import { localizeStrEnum, localizationManager } from "../i18n"; import { SlowSliderField } from "./SlowSliderField" import { CustomTDPComponent } from "."; @@ -164,9 +164,9 @@ const CPUTDPComponent: VFC = () => { const [customTDPRangeMin, setCustomTDPRangeMin] = useState(Settings.appCustomTDPRangeMin()); // 隐藏强制显示TDP开关, 并默认显示 TDP 控制组件。新版 Steam 客户端临时方案 - const [hideForceShowSwitch, setHideForceShowSwitch] = useState(false); + const [hideForceShowSwitch, _] = useState(Backend.data.getForceShowTDP()); - const minSteamVersion = 1714854927; + // const minSteamVersion = 1714854927; const refresh = () => { setTDPEnable(Settings.appTDPEnable()); @@ -196,16 +196,6 @@ const CPUTDPComponent: VFC = () => { } } }) - - // 检查 Steam 客户端版本,如果版本大于等于 minSteamVersion。不显示强制 TDP 开关。并默认显示 TDP 控制组件 - // 在解决 QAM 中 TDP 控制组件显示问题后,可以移除该逻辑 - SteamUtils.getSystemInfo().then((systemInfo) => { - // json output - console.log(`>>>>>>>> System Info: ${JSON.stringify(systemInfo, null, 2)}`); - if (systemInfo.nSteamVersion >= minSteamVersion) { - setHideForceShowSwitch(true); - } - }); }, []); const _showTdp = !PluginManager.isPatchSuccess(Patch.TDPPatch) || forceShow || hideForceShowSwitch; diff --git a/src/util/backend.ts b/src/util/backend.ts index 67a571d..5bdb20a 100755 --- a/src/util/backend.ts +++ b/src/util/backend.ts @@ -2,11 +2,13 @@ import { ServerAPI } from "decky-frontend-lib"; import { APPLYTYPE, FANMODE, GPUMODE, Patch } from "./enum"; import { FanControl, PluginManager } from "./pluginMain"; import { Settings, SettingsData } from "./settings"; -import { DEFAULT_TDP_MAX, DEFAULT_TDP_MIN, QAMPatch } from "."; +import { DEFAULT_TDP_MAX, DEFAULT_TDP_MIN, QAMPatch, SteamUtils, SystemInfo } from "."; import { JsonSerializer } from "typescript-json-serializer"; const serializer = new JsonSerializer(); +const minSteamVersion = 1714854927; + export class BackendData { private serverAPI: ServerAPI | undefined; private cpuMaxNum = 0; @@ -24,6 +26,7 @@ export class BackendData { private current_version = ""; private latest_version = ""; private supportCPUMaxPct = false; + private systemInfo: SystemInfo | undefined; public async init(serverAPI: ServerAPI) { this.serverAPI = serverAPI; await serverAPI! @@ -91,6 +94,15 @@ export class BackendData { } } ); + + SteamUtils.getSystemInfo().then((systemInfo) => { + this.systemInfo = systemInfo; + }); + } + + public getForceShowTDP() { + // 检查 Steam 客户端版本,如果版本大于等于 minSteamVersion。不显示强制 TDP 开关。并默认显示 TDP 控制组件 + return this.systemInfo!.nSteamVersion >= minSteamVersion } public getCpuMaxNum() { @@ -418,33 +430,38 @@ export class Backend { : tdp; if (!PluginManager.isPatchSuccess(Patch.TDPPatch) || Settings.appForceShowTDP()) { - // console.log( - // `>>>>> 插件方式更新 TDP = ${_tdp} TDPEnable = ${tdpEnable}` - // ); + console.log( + `>>>>> 插件方式更新 TDP = ${_tdp} TDPEnable = ${tdpEnable}` + ); + if (tdpEnable) { Backend.applyTDP(_tdp); } else { Backend.applyTDP(Backend.data.getTDPMax()); } - if (Settings.appForceShowTDP()) { - try { - QAMPatch.setTDPEanble(tdpEnable); - if (tdpEnable) { - QAMPatch.setTDP(_tdp); - } - } catch (error) { - console.error(`>>>>> 强制显示 TDP 时设置QAM失败`, error); + + try { + QAMPatch.setTDPEanble(tdpEnable); + if (tdpEnable) { + QAMPatch.setTDP(_tdp); } + } catch (error) { + console.error(`>>>>> 强制显示 TDP 时设置QAM失败`, error); } - } else { - // console.log( - // `>>>>> 原生设置更新 TDP = ${_tdp} TDPEnable = ${tdpEnable}` - // ); + } + + // patch 成功, 更新 QAM 中设置的值 + if (PluginManager.isPatchSuccess(Patch.TDPPatch)) { + console.log( + `>>>>> 原生设置更新 TDP = ${_tdp} TDPEnable = ${tdpEnable}` + ); // patch 成功才更新 QAM 中设置的值 QAMPatch.setTDPEanble(tdpEnable); QAMPatch.setTDP(_tdp); if (tdpEnable) { Backend.applyTDP(_tdp); + } else { + Backend.applyTDP(Backend.data.getTDPMax()); } } }