Skip to content

Commit

Permalink
Merge pull request #62 from mengmeet/toast
Browse files Browse the repository at this point in the history
Add toast
  • Loading branch information
honjow authored Mar 17, 2024
2 parents 29d2f99 + ae395e3 commit ff3c4d0
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 7 deletions.
30 changes: 30 additions & 0 deletions src/components/gpu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,25 @@ const GPUModeNaviteComponent: VFC = () => {
}
);

const description = (mode: GPUMODE) => {
switch (mode) {
case GPUMODE.NATIVE:
return localizationManager.getString(localizeStrEnum.NATIVE_FREQ_DESC);
case GPUMODE.RANGE:
return localizationManager.getString(localizeStrEnum.RANGE_FREQ_DESC);
case GPUMODE.AUTO:
return localizationManager.getString(localizeStrEnum.AUTO_FREQ_DESC);
default:
return "";
}
}

return (
<div>
<PanelSectionRow>
<SliderField
label={localizationManager.getString(localizeStrEnum.GPU_FREQMODE)}
description={description(gpuMode as GPUMODE)}
value={modesWithNative.findIndex((mode) => mode == gpuMode)}
step={1}
max={2}
Expand Down Expand Up @@ -254,10 +268,26 @@ const GPUModeLegacyComponent: VFC = () => {
})
}, []);

const description = (mode: GPUMODE) => {
switch (mode) {
case GPUMODE.NOLIMIT:
return localizationManager.getString(localizeStrEnum.UNLIMITED_DESC);
case GPUMODE.FIX:
return localizationManager.getString(localizeStrEnum.FIXED_FREQ_DESC);
case GPUMODE.RANGE:
return localizationManager.getString(localizeStrEnum.RANGE_FREQ_DESC);
case GPUMODE.AUTO:
return localizationManager.getString(localizeStrEnum.AUTO_FREQ_DESC);
default:
return "";
}
}

return (
<PanelSectionRow>
<SliderField
label={localizationManager.getString(localizeStrEnum.GPU_FREQMODE)}
description={description(gpuMode as GPUMODE)}
value={modesLegacy.findIndex((mode) => mode == gpuMode)}
step={1}
max={notchLabelsLegacy.length - 1}
Expand Down
7 changes: 6 additions & 1 deletion src/i18n/english.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@
"AC_MODE": "AC Mode",
"BAT_MODE": "Battery Mode",
"CUSTOM_TDP_RANGE": "Custom TDP Range",
"RESET_ALL": "Reset All"
"RESET_ALL": "Reset All",
"NATIVE_FREQ_DESC": "Set frequency using system shortcut menu",
"UNLIMITED_DESC": "No limit on GPU frequency, system default scheduling",
"FIXED_FREQ_DESC": "Fixed GPU frequency",
"RANGE_FREQ_DESC": "Set GPU frequency range",
"AUTO_FREQ_DESC": "Adaptive GPU frequency, forcibly turn off TDP limit, turn off Boost"
}
8 changes: 7 additions & 1 deletion src/i18n/localizeMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ export enum localizeStrEnum {

CUSTOM_TDP_RANGE="CUSTOM_TDP_RANGE",

RESET_ALL="RESET_ALL"
RESET_ALL="RESET_ALL",

NATIVE_FREQ_DESC="NATIVE_FREQ_DESC",
UNLIMITED_DESC="UNLIMITED_DESC",
FIXED_FREQ_DESC="FIXED_FREQ_DESC",
RANGE_FREQ_DESC="RANGE_FREQ_DESC",
AUTO_FREQ_DESC="AUTO_FREQ_DESC"
}

7 changes: 6 additions & 1 deletion src/i18n/schinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@
"AC_MODE": "充电模式",
"BAT_MODE": "电池模式",
"CUSTOM_TDP_RANGE": "自定义 TDP 范围",
"RESET_ALL": "重置所有设置"
"RESET_ALL": "重置所有设置",
"NATIVE_FREQ_DESC": "使用系统快捷菜单频率设置",
"UNLIMITED_DESC": "不限制 GPU 频率, 系统默认调度",
"FIXED_FREQ_DESC": "固定 GPU 频率",
"RANGE_FREQ_DESC": "设置 GPU 频率范围",
"AUTO_FREQ_DESC": "自适应 GPU 频率, 强制关闭 TDP 限制, 关闭 Boost"
}
7 changes: 6 additions & 1 deletion src/i18n/tchinese.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@
"AC_MODE": "充電模式",
"BAT_MODE": "電池模式",
"CUSTOM_TDP_RANGE": "自訂 TDP 範圍",
"RESET_ALL": "重置所有設定"
"RESET_ALL": "重置所有設定",
"NATIVE_FREQ_DESC": "使用系統快捷選單設定頻率",
"UNLIMITED_DESC": "不限制 GPU 頻率,系統預設調度",
"FIXED_FREQ_DESC": "固定 GPU 頻率",
"RANGE_FREQ_DESC": "設定 GPU 頻率範圍",
"AUTO_FREQ_DESC": "自適應 GPU 頻率,強制關閉 TDP 限制,關閉 Boost"
}
5 changes: 5 additions & 0 deletions src/util/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class BackendData {
}
);
}

public getCpuMaxNum() {
return this.cpuMaxNum;
}
Expand Down Expand Up @@ -336,6 +337,10 @@ export class Backend {
);
}

public static getServerAPI() {
return this.serverAPI;
}

public static applySettings = (applyTarget: string) => {
if (!Settings.ensureEnable()) {
Backend.resetSettings();
Expand Down
3 changes: 2 additions & 1 deletion src/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export * from "./settings"
export * from "./position"
export * from "./steamClient"
export * from "./enum"
export * from "./patch"
export * from "./patch"
export * from "./steamUtils"
16 changes: 14 additions & 2 deletions src/util/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { findModuleChild, afterPatch } from "decky-frontend-lib";
import { Backend } from "./backend";
import { GPUMODE, GPUPerformanceLevel, Patch } from "./enum";
import { Settings } from "./settings";
import { BatteryStateChange } from ".";
import { BatteryStateChange, SteamUtils } from ".";

export class QAMPatch {
private static TDP_Patch: TDPPatch;
Expand Down Expand Up @@ -231,7 +231,19 @@ class TDPPatch {
`QAM tdp limit enable change: ${this.last_is_tdp_limit_enabled} -> ${this.perfStore?.msgSettingsPerApp?.is_tdp_limit_enabled}`
);

if (this.last_tdp_limit != 0) {
if (
Settings.appGPUMode() === GPUMODE.AUTO &&
this.perfStore?.msgSettingsPerApp?.is_tdp_limit_enabled === true
) {
console.error(
"While GPU mode is AUTO, TDP limit must be disabled"
);

const notificationText = `GPU mode is AUTO, TDP limit disabled`;
SteamUtils.simpleToast(notificationText, 3000);

this.perfStore.msgSettingsPerApp.is_tdp_limit_enabled = false;
} else if (this.last_tdp_limit != 0) {
// console.log("saveTDP from qam listener");
Settings.saveTDPFromQAM(
this.perfStore?.msgSettingsPerApp?.tdp_limit ?? 15,
Expand Down
62 changes: 62 additions & 0 deletions src/util/steamUtils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Module, findModuleChild } from "decky-frontend-lib";
import { Backend } from ".";
import { ReactNode } from "react";
import { FaSuperpowers } from "react-icons/fa";

//#region Find SteamOS modules
const findModule = (property: string) => {
return findModuleChild((m: Module) => {
if (typeof m !== "object") return undefined;
for (let prop in m) {
try {
if (m[prop][property]) return m[prop];
} catch {
return undefined;
}
}
});
};
// @ts-ignore
const NavSoundMap = findModule("ToastMisc");
//#endregion

export interface NotifyProps {
message: ReactNode;
title?: ReactNode;
logo?: ReactNode;
icon?: ReactNode;
showToast?: boolean;
playSound?: boolean;
sound?: number;
duration?: number;
}

export class SteamUtils {
//#region Notification Wrapper
static async notify({
title,
message,
logo,
icon,
showToast,
playSound,
sound,
duration,
}: NotifyProps) {
let toastData = {
title: title || "PowerControl",
body: message,
logo: logo,
icon: icon || <FaSuperpowers />,
duration: duration,
sound: sound || NavSoundMap?.ToastMisc,
playSound: playSound || false,
showToast: showToast || false,
};
Backend.getServerAPI().toaster.toast(toastData);
}

static async simpleToast(message: string, duration?: number) {
this.notify({ message, showToast: true, duration });
}
}

0 comments on commit ff3c4d0

Please sign in to comment.