Skip to content

Commit

Permalink
fix disable tdp limit
Browse files Browse the repository at this point in the history
  • Loading branch information
honjow committed May 28, 2024
1 parent 61ed718 commit 68cf16a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
16 changes: 3 additions & 13 deletions src/components/cpu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 ".";
Expand Down Expand Up @@ -164,9 +164,9 @@ const CPUTDPComponent: VFC = () => {
const [customTDPRangeMin, setCustomTDPRangeMin] = useState<number>(Settings.appCustomTDPRangeMin());

// 隐藏强制显示TDP开关, 并默认显示 TDP 控制组件。新版 Steam 客户端临时方案
const [hideForceShowSwitch, setHideForceShowSwitch] = useState<boolean>(false);
const [hideForceShowSwitch, _] = useState<boolean>(Backend.data.getForceShowTDP());

const minSteamVersion = 1714854927;
// const minSteamVersion = 1714854927;

const refresh = () => {
setTDPEnable(Settings.appTDPEnable());
Expand Down Expand Up @@ -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;
Expand Down
49 changes: 33 additions & 16 deletions src/util/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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!
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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());
}
}
}
Expand Down

0 comments on commit 68cf16a

Please sign in to comment.