Skip to content

Commit

Permalink
Merge pull request #69 from mengmeet/dev
Browse files Browse the repository at this point in the history
Allow force show TDP control in plugin
  • Loading branch information
honjow authored Apr 16, 2024
2 parents 16574a8 + df71ca1 commit 64879de
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 29 deletions.
2 changes: 1 addition & 1 deletion backend/fan_config/hwmon/asus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ hwmon_name: asus_custom_fan_curve

fans:
- fan_name: CPU Fan
pwm_mode: 1
pwm_mode: 1 # 写入的模式 0.普通模式(对单个文件写入) 1.rog掌机特殊模式(对多个文件写入同样的数值)

pwm_enable:
manual_value: 1
Expand Down
66 changes: 44 additions & 22 deletions src/components/cpu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,18 @@ const CPUTDPComponent: VFC = () => {
const [tdpEnable, setTDPEnable] = useState<boolean>(Settings.appTDPEnable());
const [tdp, setTDP] = useState<number>(Settings.appTDP());
const [disabled, setDisable] = useState<boolean>(Settings.appGPUMode() == GPUMODE.AUTO);
const [forceShow, setForceShow] = useState<boolean>(Settings.appForceShowTDP());
const [enableCustomTDPRange, setEnableCustomTDPRange] = useState<boolean>(Settings.appEnableCustomTDPRange());
const [customTDPRangeMax, setCustomTDPRangeMax] = useState<number>(Settings.appCustomTDPRangeMax());
const [customTDPRangeMin, setCustomTDPRangeMin] = useState<number>(Settings.appCustomTDPRangeMin());
const refresh = () => {
setTDPEnable(Settings.appTDPEnable());
setTDP(Settings.appTDP());
setDisable(Settings.appGPUMode() == GPUMODE.AUTO);
setEnableCustomTDPRange(Settings.appEnableCustomTDPRange());
setCustomTDPRangeMax(Settings.appCustomTDPRangeMax());
setCustomTDPRangeMin(Settings.appCustomTDPRangeMin());
setForceShow(Settings.appForceShowTDP());
};
useEffect(() => {
PluginManager.listenUpdateComponent(ComponentName.CPU_TDP, [ComponentName.CPU_TDP, ComponentName.GPU_FREQMODE], (_ComponentName, updateType) => {
Expand All @@ -133,33 +141,47 @@ const CPUTDPComponent: VFC = () => {
})
}, []);
return (
<div>
<>
<PanelSectionRow>
<ToggleField
label={localizationManager.getString(localizeStrEnum.TDP)}
description={localizationManager.getString(localizeStrEnum.TDP_DESC)}
checked={tdpEnable}
disabled={disabled}
label={localizationManager.getString(localizeStrEnum.FORCE_SHOW_TDP)}
description={localizationManager.getString(localizeStrEnum.FORCE_SHOW_TDP_DESC)}
checked={forceShow || !PluginManager.isPatchSuccess(Patch.TDPPatch)}
onChange={(value) => {
Settings.setTDPEnable(value);
// setForceShow(value);
Settings.setForceShowTDP(value);
}}
/>
</PanelSectionRow>
{tdpEnable && <PanelSectionRow>
<SlowSliderField
label={localizationManager.getString(localizeStrEnum.WATTS)}
value={tdp}
step={1}
max={Backend.data.getTDPMax()}
min={3}
disabled={disabled}
showValue={true}
onChangeEnd={(value: number) => {
Settings.setTDP(value);
}}
/>
</PanelSectionRow>}
</div>
{!PluginManager.isPatchSuccess(Patch.TDPPatch) || forceShow &&
<>
<PanelSectionRow>
<ToggleField
label={localizationManager.getString(localizeStrEnum.TDP)}
description={localizationManager.getString(localizeStrEnum.TDP_DESC)}
checked={tdpEnable}
disabled={disabled}
onChange={(value) => {
Settings.setTDPEnable(value);
}}
/>
</PanelSectionRow>
{tdpEnable && <PanelSectionRow>
<SlowSliderField
label={localizationManager.getString(localizeStrEnum.WATTS)}
value={tdp}
step={1}
max={enableCustomTDPRange ? customTDPRangeMax : Backend.data.getTDPMax()}
min={enableCustomTDPRange ? customTDPRangeMin : 3}
disabled={disabled}
showValue={true}
onChangeEnd={(value: number) => {
Settings.setTDP(value);
}}
/>
</PanelSectionRow>}
</>}
</>
);
}

Expand Down Expand Up @@ -196,7 +218,7 @@ export const CPUComponent: VFC = () => {
<CPUBoostComponent />
{isSpportSMT && <CPUSmtComponent />}
<CPUNumComponent />
{!PluginManager.isPatchSuccess(Patch.TDPPatch) && <CPUTDPComponent />}
<CPUTDPComponent />
<CustomTDPComponent />
</PanelSection>}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/customTDP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const CustomTDPComponent: VFC = () => {
};

useEffect(() => {
PluginManager.listenUpdateComponent(ComponentName.CUSTOM_TDP, [ComponentName.CUSTOM_TDP], (_ComponentName, updateType: string) => {
PluginManager.listenUpdateComponent(ComponentName.CUSTOM_TDP, [ComponentName.CPU_TDP,ComponentName.CUSTOM_TDP], (_ComponentName, updateType: string) => {
switch (updateType) {
case UpdateType.UPDATE:
refresh();
Expand Down
4 changes: 3 additions & 1 deletion src/i18n/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@
"FIXED_FREQ_DESC": "Fixed GPU frequency",
"RANGE_FREQ_DESC": "Set GPU frequency range",
"AUTO_FREQ_DESC": "Adaptive GPU frequency, forcibly disabled TDP limit, disabled Boost",
"AUTO_FREQ_TDP_NOTIF": "GPU mode {{mode}}, TDP limit disabled"
"AUTO_FREQ_TDP_NOTIF": "GPU mode {{mode}}, TDP limit disabled",
"FORCE_SHOW_TDP": "Force Show TDP Control",
"FORCE_SHOW_TDP_DESC": "By default, the plugin will process the native TDP slider. If there is an issue with the native slider, enable this option to use the plugin's internal TDP control"
}
5 changes: 4 additions & 1 deletion src/i18n/localizeMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,8 @@ export enum localizeStrEnum {
FIXED_FREQ_DESC = "FIXED_FREQ_DESC",
RANGE_FREQ_DESC = "RANGE_FREQ_DESC",
AUTO_FREQ_DESC = "AUTO_FREQ_DESC",
AUTO_FREQ_TDP_NOTIF = "AUTO_FREQ_TDP_NOTIF"
AUTO_FREQ_TDP_NOTIF = "AUTO_FREQ_TDP_NOTIF",

FORCE_SHOW_TDP = "FORCE_SHOW_TDP",
FORCE_SHOW_TDP_DESC = "FORCE_SHOW_TDP_DESC"
}
4 changes: 3 additions & 1 deletion src/i18n/schinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@
"FIXED_FREQ_DESC": "固定 GPU 频率",
"RANGE_FREQ_DESC": "设置 GPU 频率范围",
"AUTO_FREQ_DESC": "自适应 GPU 频率, 强制关闭 TDP 限制, 关闭 Boost",
"AUTO_FREQ_TDP_NOTIF": "GPU 模式为{{mode}}, 关闭 TDP 限制"
"AUTO_FREQ_TDP_NOTIF": "GPU 模式为{{mode}}, 关闭 TDP 限制",
"FORCE_SHOW_TDP": "强制显示 TDP 控制",
"FORCE_SHOW_TDP_DESC": "默认情况下插件会对原生 TDP 滑动条进行处理, 如果原生滑动条异常, 打开此项使用插件内 TDP 控制"
}
4 changes: 3 additions & 1 deletion src/i18n/tchinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@
"FIXED_FREQ_DESC": "固定 GPU 頻率",
"RANGE_FREQ_DESC": "設定 GPU 頻率範圍",
"AUTO_FREQ_DESC": "自適應 GPU 頻率,強制關閉 TDP 限制,關閉 Boost",
"AUTO_FREQ_TDP_NOTIF": "GPU 模式为{{mode}}, 關閉 TDP 限制"
"AUTO_FREQ_TDP_NOTIF": "GPU 模式为{{mode}}, 關閉 TDP 限制",
"FORCE_SHOW_TDP": "強制顯示 TDP 控制",
"FORCE_SHOW_TDP_DESC": "默認情況下, 插件將處理原生 TDP 滑塊。如果原生滑塊出現問題, 請啟用此選項以使用插件內部的 TDP 控制"
}
12 changes: 11 additions & 1 deletion src/util/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export class Backend {
? Math.min(customTDPRangeMax, Math.max(customTDPRangeMin, tdp))
: tdp;

if (!PluginManager.isPatchSuccess(Patch.TDPPatch)) {
if (!PluginManager.isPatchSuccess(Patch.TDPPatch) || Settings.appForceShowTDP()) {
// console.log(
// `>>>>> 插件方式更新 TDP = ${_tdp} TDPEnable = ${tdpEnable}`
// );
Expand All @@ -406,6 +406,16 @@ export class Backend {
} 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);
}
}
} else {
// console.log(
// `>>>>> 原生设置更新 TDP = ${_tdp} TDPEnable = ${tdpEnable}`
Expand Down
15 changes: 15 additions & 0 deletions src/util/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ export class SettingsData {
@JsonProperty()
public customTDPRangeMin: number;

@JsonProperty()
public forceShowTDP: boolean = false;

@JsonProperty({ isDictionary: true, type: AppSettingData })
public perApp: { [appId: string]: AppSettingData } = {};

Expand Down Expand Up @@ -314,6 +317,18 @@ export class Settings {
}
}

static appForceShowTDP(): boolean {
return this._instance.data.forceShowTDP;
}

static setForceShowTDP(forceShowTDP: boolean) {
if (this._instance.data.forceShowTDP != forceShowTDP) {
this._instance.data.forceShowTDP = forceShowTDP;
Settings.saveSettingsToLocalStorage();
PluginManager.updateComponent(ComponentName.CPU_TDP, UpdateType.UPDATE);
}
}

static appACStateOverWrite(): boolean {
return (
this._instance.data.perApp[Settings.ensureAppID()].acStateOverwrite ??
Expand Down

0 comments on commit 64879de

Please sign in to comment.