Skip to content

Commit

Permalink
将原生的tdp滑动条范围调整并使其可用,去除插件内的tdp滑动条
Browse files Browse the repository at this point in the history
  • Loading branch information
Gawah committed Nov 23, 2023
1 parent b053e1d commit 1946303
Show file tree
Hide file tree
Showing 39 changed files with 126 additions and 29 deletions.
Empty file modified .github/workflows/release.yml
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions backend/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"G1618-04":45, #GPD WIN4
"G1617-01":30, #GPD WIN mini
"ROG Ally RC71L_RC71L":40,
"Jupiter":20,
}
TDP_LIMIT_CONFIG_CPU={
"AMD Ryzen 7 7735HS with Radeon Graphics":45,
Expand Down
Empty file modified backend/fan.py
100644 → 100755
Empty file.
Empty file modified install.sh
100644 → 100755
Empty file.
Empty file modified pnpm-lock.yaml
100644 → 100755
Empty file.
Empty file modified rollup.config.js
100644 → 100755
Empty file.
Empty file modified src/components/SlowSliderField.tsx
100644 → 100755
Empty file.
3 changes: 2 additions & 1 deletion src/components/cpu.tsx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const CPUNumComponent:VFC = () =>{
);
}

/*
const CPUTDPComponent:VFC = () =>{
const [tdpEnable, setTDPEnable] = useState<boolean>(Settings.appTDPEnable());
const [tdp,setTDP] = useState<number>(Settings.appTDP());
Expand Down Expand Up @@ -160,6 +161,7 @@ const CPUTDPComponent:VFC = () =>{
</div>
);
}
*/

export const CPUComponent: VFC = () => {
const [show,setShow] = useState<boolean>(Settings.ensureEnable());
Expand Down Expand Up @@ -187,7 +189,6 @@ export const CPUComponent: VFC = () => {
<CPUBoostComponent/>
<CPUSmtComponent/>
<CPUNumComponent/>
<CPUTDPComponent/>
</PanelSection>}
</div>
);
Expand Down
Empty file modified src/components/fan.tsx
100644 → 100755
Empty file.
Empty file modified src/components/fanCanvas.tsx
100644 → 100755
Empty file.
Empty file modified src/components/gpu.tsx
100644 → 100755
Empty file.
Empty file modified src/components/index.ts
100644 → 100755
Empty file.
Empty file modified src/components/settings.tsx
100644 → 100755
Empty file.
Empty file modified src/i18n/bulgarian.json
100644 → 100755
Empty file.
Empty file modified src/i18n/english.json
100644 → 100755
Empty file.
Empty file modified src/i18n/french.json
100644 → 100755
Empty file.
Empty file modified src/i18n/german.json
100644 → 100755
Empty file.
Empty file modified src/i18n/index.ts
100644 → 100755
Empty file.
Empty file modified src/i18n/italian.json
100644 → 100755
Empty file.
Empty file modified src/i18n/japanese.json
100644 → 100755
Empty file.
Empty file modified src/i18n/koreana.json
100644 → 100755
Empty file.
Empty file modified src/i18n/localization.ts
100644 → 100755
Empty file.
Empty file modified src/i18n/localizeMap.ts
100644 → 100755
Empty file.
Empty file modified src/i18n/schinese.json
100644 → 100755
Empty file.
Empty file modified src/i18n/tchinese.json
100644 → 100755
Empty file.
Empty file modified src/i18n/thai.json
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion src/index.tsx
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default definePlugin((serverAPI: ServerAPI) => {
content: <Content/>,
icon: <FaSuperpowers />,
onDismount() {
PluginManager.unregister();
PluginManager?.unregister();
}
};
});
22 changes: 5 additions & 17 deletions src/util/backend.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export class BackendData{
private has_cpuMaxNum = false;
private tdpMax = 0;
private has_tdpMax= false;
private has_ryzenadj = false;
private gpuMax = 0;
private has_gpuMax = false;
private gpuMin = 0;
Expand All @@ -35,12 +34,6 @@ export class BackendData{
this.has_tdpMax = true;
}
})
await serverAPI!.callPluginMethod<{},boolean>("get_hasRyzenadj",{}).then(res=>{
if (res.success){
console.info("has_ryzenadj = " + res.result);
this.has_ryzenadj= res.result;
}
})
await serverAPI!.callPluginMethod<{},number>("get_gpuFreqMax",{}).then(res=>{
if (res.success){
console.info("gpuMax = " + res.result);
Expand Down Expand Up @@ -103,10 +96,6 @@ export class BackendData{
return this.has_tdpMax;
}

public HasRyzenadj(){
return this.has_ryzenadj;
}

public getFanMAXPRM(){
return this.fanMaxRPM;
}
Expand Down Expand Up @@ -181,10 +170,7 @@ export class Backend {
this.serverAPI!.callPluginMethod("set_cpuBoost", { "value": cpuBoost });
}

private static applyTDP(tdp: number) {
console.log("Applying tdp " + tdp.toString());
this.serverAPI!.callPluginMethod("set_cpuTDP", {"value":tdp});
}


private static applyGPUFreq(freq: number){
console.log("Applying gpuFreq " + freq.toString());
Expand Down Expand Up @@ -236,6 +222,7 @@ export class Backend {
const cpuBoost = Settings.appCpuboost();
Backend.applyCpuBoost(cpuBoost);
}
/*
if (applyTarget == APPLYTYPE.SET_ALL || applyTarget == APPLYTYPE.SET_TDP) {
const tdp = Settings.appTDP();
const tdpEnable = Settings.appTDPEnable();
Expand All @@ -246,6 +233,7 @@ export class Backend {
Backend.applyTDP(Backend.data.getTDPMax());
}
}
*/
if (applyTarget == APPLYTYPE.SET_ALL || applyTarget == APPLYTYPE.SET_GPUMODE) {
const gpuMode = Settings.appGPUMode();
const gpuFreq = Settings.appGPUFreq();
Expand All @@ -261,7 +249,7 @@ export class Backend {
Backend.applyGPUFreq(gpuFreq);
} else if (gpuMode == GPUMODE.AUTO) {
console.log(`开始自动优化GPU频率`)
Settings.setTDPEnable(false);
//Settings.setTDPEnable(false);
Settings.setCpuboost(false);
Backend.applyGPUAutoMax(gpuAutoMaxFreq);
Backend.applyGPUAutoMin(gpuAutoMinFreq);
Expand Down Expand Up @@ -318,7 +306,7 @@ export class Backend {
Backend.applySmt(true);
Backend.applyCpuNum(Backend.data.getCpuMaxNum());
Backend.applyCpuBoost(true);
Backend.applyTDP(Backend.data.getTDPMax());
//Backend.applyTDP(Backend.data.getTDPMax());
Backend.applyGPUFreq(0);
Backend.applyFanAuto(true);
};
Expand Down
Empty file modified src/util/enum.ts
100644 → 100755
Empty file.
3 changes: 2 additions & 1 deletion src/util/index.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from "./pluginMain"
export * from "./settings"
export * from "./position"
export * from "./steamClient"
export * from "./enum"
export * from "./enum"
export * from "./patch"
99 changes: 99 additions & 0 deletions src/util/patch.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import {
findModuleChild,
afterPatch,
ServerAPI,
} from "decky-frontend-lib";
import { Backend } from "./backend";


export class QAMPatch {
private static TDP_Patch: TDPPatch;
public static async init(serverAPI:ServerAPI){
var perfStoreClass;
while(!perfStoreClass){
perfStoreClass = findModuleChild((m: any) => {
if (typeof m !== "object") return undefined;
for (let prop in m) {
if (m[prop]?.prototype?.SetFPSLimit) return m[prop];
}
});
}
this.TDP_Patch = new TDPPatch();
await this.TDP_Patch.init(serverAPI,perfStoreClass);
this.patch();
}

public static patch() {
console.debug("QAM patch");
this.TDP_Patch.patch();
}

public static unpatch() {
console.debug("QAM unpatch");
this.TDP_Patch?.unpatch();
}
}

class TDPPatch{
private perfStoreClass:any;
private perfStore:any;
private serverAPI:any;
private stateChangeHook:any;
private suspendEndHook:any;
private tdpPatch:any;
private applyCount:number=0;
private tdp_limit:number=0;
private is_tdp_limit_enabled:boolean=false;
public init(serverAPI:ServerAPI,perfStoreClass:any){
this.serverAPI = serverAPI;
this.perfStoreClass = perfStoreClass;
this.perfStore = perfStoreClass.Get();
}
private applyTDP = ()=>{
if(this.is_tdp_limit_enabled){
console.log("Applying tdp " + this.tdp_limit.toString());
this.serverAPI!.callPluginMethod("set_cpuTDP", {"value":this.tdp_limit});
}else{
if(Backend.data.HasTDPMax()){
console.log("Applying tdp " + Backend.data.getTDPMax().toString());
this.serverAPI!.callPluginMethod("set_cpuTDP", {"value":Backend.data.getTDPMax()});
}
}

}

public patch(){
//状态改变时tdp发生变化则修改TDP
this.stateChangeHook = SteamClient.System.Perf.RegisterForStateChanges(()=>{
this.applyCount++;
setTimeout(()=>{
this.applyCount--;
if(this.applyCount!=0)
return;
if(this.tdp_limit != this.perfStore.msgSettingsPerApp.tdp_limit||this.is_tdp_limit_enabled != this.perfStore.msgSettingsPerApp.is_tdp_limit_enabled){
this.tdp_limit = this.perfStore.msgSettingsPerApp.tdp_limit;
this.is_tdp_limit_enabled = this.perfStore.msgSettingsPerApp.is_tdp_limit_enabled;
this.applyTDP();
}
},500)
})
//挂起结束时修改一次TDP
this.suspendEndHook = SteamClient.System.RegisterForOnResumeFromSuspend(async () => {
this.applyTDP();
});

//tdp最大值修补
this.tdpPatch = afterPatch(this.perfStoreClass, "Get", (_: any[], ret: any) => {
if(Backend.data.HasTDPMax()){
this.perfStore.msgLimits.tdp_limit_max = Backend.data.getTDPMax();
}
return ret;
});
}

public unpatch(){
this.stateChangeHook?.unregister();
this.suspendEndHook?.unregister();
this.tdpPatch?.unpatch();
}
}
13 changes: 8 additions & 5 deletions src/util/pluginMain.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { localizationManager } from "../i18n";
import { Settings } from "./settings";
import { AppOverviewExt } from "./steamClient";
import { calPointInLine, fanPosition } from "./position";
import { QAMPatch } from "./patch";

type ActiveAppChangedHandler = (newAppId: string, oldAppId: string) => void;
type ComponentUpdateHandler = (componentsName: ComponentName,updateType:UpdateType) => void;
Expand Down Expand Up @@ -169,6 +170,7 @@ export class PluginManager{
PluginManager.state = PluginState.INIT;
await Backend.init(serverAPI);
await localizationManager.init(serverAPI);
await QAMPatch.init(serverAPI);
RunningApps.register();
FanControl.register();
RunningApps.listenActiveChange((newAppId, oldAppId) => {
Expand All @@ -193,12 +195,13 @@ export class PluginManager{
return PluginManager.state==PluginState.INIT
}

public static unregister = ()=>{
PluginManager.suspendEndHook!.unregister();
public static unregister(){
PluginManager.suspendEndHook?.unregister();
PluginManager.updateAllComponent(UpdateType.DISMOUNT);
RunningApps.unregister();
FanControl.unregister();
Backend.resetSettings();
QAMPatch?.unpatch();
RunningApps?.unregister();
FanControl?.unregister();
Backend?.resetSettings();
PluginManager.state = PluginState.QUIT;
}

Expand Down
Empty file modified src/util/position.ts
100644 → 100755
Empty file.
12 changes: 8 additions & 4 deletions src/util/settings.ts
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ export class AppSetting {
cpuNum?: number;
@JsonProperty()
cpuboost?: boolean;
/*
@JsonProperty()
tdp?:number;
@JsonProperty()
tdpEnable?:boolean
*/
@JsonProperty()
gpuMode?:number
@JsonProperty()
Expand All @@ -40,8 +42,8 @@ export class AppSetting {
this.smt=false;
this.cpuNum=Backend.data?.HasCpuMaxNum()?Backend.data?.getCpuMaxNum():4;
this.cpuboost=false;
this.tdpEnable=true;
this.tdp=Backend.data?.HasTDPMax()?Math.trunc(Backend.data?.getTDPMax()/2):15;
//this.tdpEnable=true;
//this.tdp=Backend.data?.HasTDPMax()?Math.trunc(Backend.data?.getTDPMax()/2):15;
this.gpuMode=GPUMODE.NOLIMIT;
this.gpuFreq=Backend.data?.HasGPUFreqMax()?Backend.data.getGPUFreqMax():1600;
this.gpuAutoMaxFreq=Backend.data?.HasGPUFreqMax()?Backend.data.getGPUFreqMax():1600;
Expand All @@ -54,8 +56,8 @@ export class AppSetting {
this.smt=copyTarget.smt;
this.cpuNum=copyTarget.cpuNum;
this.cpuboost=copyTarget.cpuboost;
this.tdpEnable=copyTarget.tdpEnable;
this.tdp=copyTarget.tdp;
//this.tdpEnable=copyTarget.tdpEnable;
//this.tdp=copyTarget.tdp;
this.gpuMode=copyTarget.gpuMode;
this.gpuFreq=copyTarget.gpuFreq;
this.gpuAutoMaxFreq=copyTarget.gpuAutoMaxFreq;
Expand Down Expand Up @@ -202,6 +204,7 @@ export class Settings {
}
}

/*
static appTDP() {
return Settings.ensureApp().tdp!!;
}
Expand All @@ -227,6 +230,7 @@ export class Settings {
PluginManager.updateComponent(ComponentName.CPU_TDP,UpdateType.UPDATE);
}
}
*/

static appGPUMode(){
return Settings.ensureApp().gpuMode!!;
Expand Down
Empty file modified src/util/steamClient.ts
100644 → 100755
Empty file.
Empty file modified tsconfig.json
100644 → 100755
Empty file.

0 comments on commit 1946303

Please sign in to comment.