Skip to content

Commit

Permalink
add IS_DESKTOP logic for async functions
Browse files Browse the repository at this point in the history
  • Loading branch information
aarron-lee committed Sep 29, 2024
1 parent 118807b commit 4f3c0eb
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 64 deletions.
154 changes: 90 additions & 64 deletions src/backend/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { callable, call } from "@decky/api";
import { IS_DESKTOP } from "../components/atoms/DeckyFrontendLib";

export enum AdvancedOptionsEnum {
ENABLE_TDP_CONTROL = "enableTdpControl",
Expand Down Expand Up @@ -67,24 +68,27 @@ export enum ServerAPIMethods {
}

export const getSettings = callable<[], any>(ServerAPIMethods.GET_SETTINGS);
export const setSetting = ({ name, value }: { name: string; value: any }) =>
call<[name: String, value: any], void>(
ServerAPIMethods.SET_SETTING,
name,
value
);
export const onSuspend = callable<[], any>(ServerAPIMethods.ON_SUSPEND);

export const setPollTdp = ({ currentGameId }: { currentGameId: string }) =>
call<[currentGameId: string], void>(ServerAPIMethods.POLL_TDP, currentGameId);
export const setMaxTdp = callable<[], void>(ServerAPIMethods.SET_MAX_TDP);
export const isSteamRunning = callable<[], boolean>(
ServerAPIMethods.GET_IS_STEAM_RUNNING
);
export const setSetting = ({ name, value }: { name: string; value: any }) => {
if (IS_DESKTOP) {
return call(ServerAPIMethods.SET_SETTING, { name, value });
}

return call(ServerAPIMethods.SET_SETTING, name, value);
};
export const onSuspend = callable(ServerAPIMethods.ON_SUSPEND);

export const setPollTdp = ({ currentGameId }: { currentGameId: string }) => {
if (IS_DESKTOP) {
return call(ServerAPIMethods.POLL_TDP, { currentGameId });
}

return call(ServerAPIMethods.POLL_TDP, currentGameId);
};
export const setMaxTdp = callable(ServerAPIMethods.SET_MAX_TDP);
export const isSteamRunning = callable(ServerAPIMethods.GET_IS_STEAM_RUNNING);

export const logInfo = ({ info }: { info: any }) => {
const logger = callable<[{ info: any }], any>(ServerAPIMethods.LOG_INFO);
logger(info);
return call(ServerAPIMethods.LOG_INFO, { info });
};

export const saveTdpProfiles = ({
Expand All @@ -95,29 +99,32 @@ export const saveTdpProfiles = ({
tdpProfiles: any;
currentGameId: any;
advanced: any;
}) =>
call<[tdpProfiles: any, currentGameId: any, advanced: any, void]>(
ServerAPIMethods.SAVE_TDP,
tdpProfiles,
currentGameId,
advanced
);

export const getLatestVersionNum = callable<[], any>(
}) => {
if (IS_DESKTOP) {
return call(ServerAPIMethods.SAVE_TDP, {
tdpProfiles,
currentGameId,
advanced,
});
}
return call(ServerAPIMethods.SAVE_TDP, tdpProfiles, currentGameId, advanced);
};

export const getLatestVersionNum = callable(
ServerAPIMethods.GET_LATEST_VERSION_NUM
);

export const otaUpdate = callable<[], void>(ServerAPIMethods.OTA_UPDATE);
export const otaUpdate = callable(ServerAPIMethods.OTA_UPDATE);

export const getPowerControlInfo = callable(
ServerAPIMethods.GET_POWER_CONTROL_INFO
);

export const getSupportsCustomAcPower = callable<[], boolean>(
export const getSupportsCustomAcPower = callable(
ServerAPIMethods.GET_SUPPORTS_CUSTOM_AC_POWER_MANAGEMENT
);

export const getCurrentAcPowerStatus = callable<[], "0" | "1">(
export const getCurrentAcPowerStatus = callable(
ServerAPIMethods.GET_CURRENT_AC_POWER_STATUS
);

Expand All @@ -128,11 +135,14 @@ export const setPowerGovernor = ({
powerGovernorInfo: any;
gameId: string;
}) => {
call<[powerGovernorInfo: any, gameId: string], any>(
ServerAPIMethods.SET_POWER_GOVERNOR,
powerGovernorInfo,
gameId
);
if (IS_DESKTOP) {
return call(ServerAPIMethods.SET_POWER_GOVERNOR, {
powerGovernorInfo,
gameId,
});
}

return call(ServerAPIMethods.SET_POWER_GOVERNOR, powerGovernorInfo, gameId);
};

export const setEpp = ({
Expand All @@ -142,11 +152,11 @@ export const setEpp = ({
eppInfo: any;
gameId: string;
}) => {
call<[eppInfo: any, gameId: string], any>(
ServerAPIMethods.SET_EPP,
eppInfo,
gameId
);
if (IS_DESKTOP) {
return call(ServerAPIMethods.SET_EPP, { eppInfo, gameId });
}

return call(ServerAPIMethods.SET_EPP, eppInfo, gameId);
};

export const persistTdp = ({
Expand All @@ -156,26 +166,33 @@ export const persistTdp = ({
tdp: number;
gameId: string;
}) => {
call<[tdp: number, gameId: string], any>(
ServerAPIMethods.PERSIST_TDP,
tdp,
gameId
);
if (IS_DESKTOP) {
return call(ServerAPIMethods.PERSIST_TDP, { tdp, gameId });
}

return call(ServerAPIMethods.PERSIST_TDP, tdp, gameId);
};

export const setValuesForGameId = ({ gameId }: { gameId: string }) => {
call<[gameId: string], any>(ServerAPIMethods.SET_VALUES_FOR_GAME_ID, gameId);
if (IS_DESKTOP) {
return call(ServerAPIMethods.SET_VALUES_FOR_GAME_ID, { gameId });
}

return call(ServerAPIMethods.SET_VALUES_FOR_GAME_ID, gameId);
};

export const setSteamPatchValuesForGameId = ({
gameId,
}: {
gameId: string;
}) => {
call<[gameId: string], any>(
ServerAPIMethods.SET_STEAM_PATCH_VALUES_FOR_GAME_ID,
gameId
);
if (IS_DESKTOP) {
return call(ServerAPIMethods.SET_STEAM_PATCH_VALUES_FOR_GAME_ID, {
gameId,
});
}

return call(ServerAPIMethods.SET_STEAM_PATCH_VALUES_FOR_GAME_ID, gameId);
};

export const persistGpu = ({
Expand All @@ -187,12 +204,18 @@ export const persistGpu = ({
maxGpuFrequency: number;
gameId: string;
}) => {
call<[minGpuFrequency: number, maxGpuFrequency: number, gameId: string], any>(
ServerAPIMethods.PERSIST_GPU,
minGpuFrequency,
maxGpuFrequency,
gameId
);
if (IS_DESKTOP) {
return call(ServerAPIMethods.PERSIST_GPU, {
minGpuFrequency,
maxGpuFrequency,
gameId,
});
}

return call<
[minGpuFrequency: number, maxGpuFrequency: number, gameId: string],
any
>(ServerAPIMethods.PERSIST_GPU, minGpuFrequency, maxGpuFrequency, gameId);
};

export const persistSmt = ({
Expand All @@ -202,11 +225,14 @@ export const persistSmt = ({
smt: boolean;
gameId: string;
}) => {
call<[smt: boolean, gameId: string], any>(
ServerAPIMethods.PERSIST_SMT,
smt,
gameId
);
if (IS_DESKTOP) {
return call(ServerAPIMethods.PERSIST_SMT, {
smt,
gameId,
});
}

return call(ServerAPIMethods.PERSIST_SMT, smt, gameId);
};

export const persistCpuBoost = ({
Expand All @@ -216,9 +242,9 @@ export const persistCpuBoost = ({
cpuBoost: boolean;
gameId: string;
}) => {
call<[cpuBoost: boolean, gameId: string], any>(
ServerAPIMethods.PERSIST_CPU_BOOST,
cpuBoost,
gameId
);
if (IS_DESKTOP) {
return call(ServerAPIMethods.PERSIST_CPU_BOOST, { cpuBoost, gameId });
}

return call(ServerAPIMethods.PERSIST_CPU_BOOST, cpuBoost, gameId);
};
2 changes: 2 additions & 0 deletions src/components/atoms/DeckyFrontendLib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
Router,
} from "@decky/ui";

export const IS_DESKTOP = false;

export const DeckySection = PanelSection;

export const DeckyRow = PanelSectionRow;
Expand Down

0 comments on commit 4f3c0eb

Please sign in to comment.