Skip to content

Commit

Permalink
cleanup middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
aarron-lee committed Jan 23, 2024
1 parent 44101d7 commit 0e0108c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 42 deletions.
10 changes: 2 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,17 @@ async def save_tdp(self, tdpProfiles, currentGameId, advanced):
merge_tdp_profiles(tdpProfiles)
persist_setting('advanced', advanced)

steam_patch_enabled = advanced_options.get_setting(
advanced_options.DefaultSettings.ENABLE_STEAM_PATCH.value
)

tdp_profile = get_active_tdp_profile(currentGameId)
tdp = tdp_profile.get('tdp', 12)
smt = tdp_profile.get('smt', True)
cpu_boost = tdp_profile.get('cpuBoost', True)

try:
with file_timeout.time_limit(3):
if not steam_patch_enabled:
ryzenadj(tdp)
ryzenadj(tdp)
set_smt(smt)
set_cpu_boost(cpu_boost)
if not steam_patch_enabled:
set_gpu_frequency(currentGameId)
set_gpu_frequency(currentGameId)
except Exception as e:
logging.error(f'main#save_tdp file timeout {e}')

Expand Down
36 changes: 8 additions & 28 deletions src/redux-modules/settingsMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import { ServerAPI } from "decky-frontend-lib";
import { cleanupAction, resumeAction } from "./extraActions";

const resetTdpActionTypes = [
setCurrentGameInfo.type,
setEnableTdpProfiles.type,
updateTdpProfiles.type,
updatePollRate.type,
setCurrentGameInfo.type,
setPolling.type,
updateInitialLoad.type,
updateAdvancedOption.type,
Expand All @@ -45,6 +45,7 @@ const BACKGROUND_POLL_RATE = 10000;
const resetPolling = (store: any) => {
if (pollIntervalId) {
clearInterval(pollIntervalId);
pollIntervalId = undefined;
}
const state = store.getState();

Expand Down Expand Up @@ -83,7 +84,12 @@ export const settingsMiddleware =
advancedState[AdvancedOptionsEnum.STEAM_PATCH]
);

if (!steamPatchEnabled) {
if (steamPatchEnabled) {
if (pollIntervalId) {
clearInterval(pollIntervalId);
pollIntervalId = undefined;
}
} else {
const activeGameId = activeGameIdSelector(state);

if (action.type === resumeAction.type) {
Expand Down Expand Up @@ -114,29 +120,6 @@ export const settingsMiddleware =
);
}

if (action.type === setCurrentGameInfo.type) {
const {
settings: { previousGameId },
} = state;

if (previousGameId !== state.currentGameId) {
// update TDP to new game's TDP value, if appropriate to do so
saveTdpProfiles(
state.settings.tdpProfiles,
activeGameId,
advancedState
);
}
}

if (action.type === updateTdpProfiles.type) {
saveTdpProfiles(
state.settings.tdpProfiles,
activeGameId,
advancedState
);
}

if (action.type === updatePollRate.type) {
// action.type == number (rate in ms)
setSetting({
Expand Down Expand Up @@ -166,9 +149,6 @@ export const settingsMiddleware =
clearInterval(pollIntervalId);
}
}
} else {
// steamPatchEnabled, disable polling
if (pollIntervalId) clearInterval(pollIntervalId);
}

return result;
Expand Down
8 changes: 2 additions & 6 deletions src/redux-modules/steamPatchMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@ export const steamPatchMiddleware =
}

if (action.type === resumeAction.type) {
if (steamPatchEnabled) {
setValuesForGameId(id);
}
setValuesForGameId(id);
}

if (action.type === setCurrentGameInfo.type) {
if (steamPatchEnabled) {
setValuesForGameId(id);
}
setValuesForGameId(id);
}

if (saveToBackendTypes.includes(action.type)) {
Expand Down

0 comments on commit 0e0108c

Please sign in to comment.