From 81fbd0f83f11d5074bb945f0f6d7b6508e9d32d7 Mon Sep 17 00:00:00 2001 From: AAGaming Date: Thu, 29 Dec 2022 23:46:47 -0500 Subject: Fix reloading UI on updates and restarting steam --- frontend/src/steamfixes/restart.ts | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 frontend/src/steamfixes/restart.ts (limited to 'frontend/src/steamfixes/restart.ts') diff --git a/frontend/src/steamfixes/restart.ts b/frontend/src/steamfixes/restart.ts new file mode 100644 index 00000000..467efd6a --- /dev/null +++ b/frontend/src/steamfixes/restart.ts @@ -0,0 +1,60 @@ +import { Patch, findModuleChild, replacePatch, sleep } from 'decky-frontend-lib'; + +import Logger from '../logger'; + +const logger = new Logger('RestartSteamFix'); + +declare global { + interface Window { + SteamClient: any; + appDetailsStore: any; + } +} + +let patch: Patch; + +function rePatch() { + // If you patch anything on SteamClient within the first few seconds of the client having loaded it will get redefined for some reason, so repatch any of these changes that occur with History.listen or an interval + patch = replacePatch(window.SteamClient.User, 'StartRestart', () => SteamClient.User.StartShutdown(false)); +} + +export default async function restartFix() { + try { + rePatch(); + // TODO type and add to frontend-lib + let History: any; + + while (!History) { + History = findModuleChild((m) => { + if (typeof m !== 'object') return undefined; + for (let prop in m) { + if (m[prop]?.m_history) return m[prop].m_history; + } + }); + if (!History) { + logger.debug('Waiting 5s for history to become available.'); + await sleep(5000); + } + } + + function repatchIfNeeded() { + if (window.SteamClient.User.StartRestart !== patch.patchedFunction) { + rePatch(); + } + } + + const unlisten = History.listen(repatchIfNeeded); + + // Just in case + setTimeout(repatchIfNeeded, 5000); + setTimeout(repatchIfNeeded, 10000); + + return () => { + unlisten(); + patch.unpatch(); + }; + } catch (e) { + logger.error('Error patching StartRestart', e); + } + return () => {}; +} -- cgit v1.2.3