Compare commits

...

6 Commits

Author SHA1 Message Date
AAGaming 0e5d991c8d add patch caching 2022-12-31 23:27:04 -05:00
AAGaming 0fe3282828 make that actually work lol 2022-12-31 22:52:37 -05:00
AAGaming 335d38e12b add * option for route in itempatches 2022-12-31 22:46:39 -05:00
AAGaming d762860eac missed this 2022-12-31 22:00:38 -05:00
AAGaming fdbc508fa8 Main menu and overlay patching API 2022-12-31 21:53:39 -05:00
AAGaming 81fbd0f83f Fix reloading UI on updates and restarting steam 2022-12-29 23:46:47 -05:00
13 changed files with 557 additions and 68 deletions
+9 -9
View File
@@ -168,15 +168,15 @@ class PluginManager:
async def inject_javascript(self, tab: Tab, first=False, request=None):
logger.info("Loading Decky frontend!")
try:
# if first:
# if await tab.has_global_var("deckyHasLoaded", False):
# tabs = await get_tabs()
# for t in tabs:
# if t.title != "Steam" and t.title != "SP":
# logger.debug("Closing tab: " + getattr(t, "title", "Untitled"))
# await t.close()
# await sleep(0.5)
await tab.evaluate_js("try{if (window.deckyHasLoaded){setTimeout(() => SteamClient.User.StartShutdown(false), 100)}else{window.deckyHasLoaded = true;(async()=>{try{while(!window.SP_REACT){await new Promise(r => setTimeout(r, 10))};await import('http://localhost:1337/frontend/index.js')}catch(e){console.error(e)};})();}}catch(e){console.error(e)}", False, False, False)
if first:
if await tab.has_global_var("deckyHasLoaded", False):
tabs = await get_tabs()
for t in tabs:
if not t.title or (t.title != "Steam" and t.title != "SP"):
logger.debug("Closing tab: " + getattr(t, "title", "Untitled"))
await t.close()
await sleep(0.5)
await tab.evaluate_js("try{if (window.deckyHasLoaded){setTimeout(() => location.reload(), 100)}else{window.deckyHasLoaded = true;(async()=>{try{while(!window.SP_REACT){await new Promise(r => setTimeout(r, 10))};await import('http://localhost:1337/frontend/index.js')}catch(e){console.error(e)};})();}}catch(e){console.error(e)}", False, False, False)
except:
logger.info("Failed to inject JavaScript into tab\n" + format_exc())
pass
+12 -15
View File
@@ -1,30 +1,27 @@
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import externalGlobals from "rollup-plugin-external-globals";
import del from 'rollup-plugin-delete'
import replace from '@rollup/plugin-replace';
import typescript from '@rollup/plugin-typescript';
import { defineConfig } from 'rollup';
import del from 'rollup-plugin-delete';
import externalGlobals from 'rollup-plugin-external-globals';
const hiddenWarnings = [
"THIS_IS_UNDEFINED",
"EVAL"
];
const hiddenWarnings = ['THIS_IS_UNDEFINED', 'EVAL'];
export default defineConfig({
input: 'src/index.tsx',
plugins: [
del({ targets: "../backend/static/*", force: true }),
del({ targets: '../backend/static/*', force: true }),
commonjs(),
nodeResolve(),
externalGlobals({
react: 'SP_REACT',
'react-dom': 'SP_REACTDOM',
// hack to shut up react-markdown
'process': '{cwd: () => {}}',
'path': '{dirname: () => {}, join: () => {}, basename: () => {}, extname: () => {}}',
'url': '{fileURLToPath: (f) => f}'
process: '{cwd: () => {}}',
path: '{dirname: () => {}, join: () => {}, basename: () => {}, extname: () => {}}',
url: '{fileURLToPath: (f) => f}',
}),
typescript(),
json(),
@@ -38,11 +35,11 @@ export default defineConfig({
dir: '../backend/static',
format: 'esm',
chunkFileNames: (chunkInfo) => {
return 'chunk-[hash].js'
}
return 'chunk-[hash].js';
},
},
onwarn: function ( message, handleWarning ) {
if (hiddenWarnings.some(warning => message.code === warning)) return;
onwarn: function (message, handleWarning) {
if (hiddenWarnings.some((warning) => message.code === warning)) return;
handleWarning(message);
}
},
});
@@ -14,13 +14,13 @@ export class DeckyGlobalComponentsState {
return { components: this._components };
}
addComponent(path: string, component: FC) {
this._components.set(path, component);
addComponent(name: string, component: FC) {
this._components.set(name, component);
this.notifyUpdate();
}
removeComponent(path: string) {
this._components.delete(path);
removeComponent(name: string) {
this._components.delete(name);
this.notifyUpdate();
}
@@ -30,8 +30,8 @@ export class DeckyGlobalComponentsState {
}
interface DeckyGlobalComponentsContext extends PublicDeckyGlobalComponentsState {
addComponent(path: string, component: FC): void;
removeComponent(path: string): void;
addComponent(name: string, component: FC): void;
removeComponent(name: string): void;
}
const DeckyGlobalComponentsContext = createContext<DeckyGlobalComponentsContext>(null as any);
+147
View File
@@ -0,0 +1,147 @@
import { CustomMainMenuItem, ItemPatch, OverlayPatch } from 'decky-frontend-lib';
import { FC, ReactNode, createContext, useContext, useEffect, useState } from 'react';
interface PublicDeckyMenuState {
items: Set<CustomMainMenuItem>;
itemPatches: Map<string, Set<ItemPatch>>;
overlayPatches: Set<OverlayPatch>;
overlayComponents: Set<ReactNode>;
}
export class DeckyMenuState {
private _items = new Set<CustomMainMenuItem>();
private _itemPatches = new Map<string, Set<ItemPatch>>();
private _overlayPatches = new Set<OverlayPatch>();
private _overlayComponents = new Set<ReactNode>();
public eventBus = new EventTarget();
publicState(): PublicDeckyMenuState {
return {
items: this._items,
itemPatches: this._itemPatches,
overlayPatches: this._overlayPatches,
overlayComponents: this._overlayComponents,
};
}
addItem(item: CustomMainMenuItem) {
this._items.add(item);
this.notifyUpdate();
return item;
}
addPatch(path: string, patch: ItemPatch) {
let patchList = this._itemPatches.get(path);
if (!patchList) {
patchList = new Set();
this._itemPatches.set(path, patchList);
}
patchList.add(patch);
this.notifyUpdate();
return patch;
}
addOverlayPatch(patch: OverlayPatch) {
this._overlayPatches.add(patch);
this.notifyUpdate();
return patch;
}
addOverlayComponent(component: ReactNode) {
this._overlayComponents.add(component);
this.notifyUpdate();
return component;
}
removePatch(path: string, patch: ItemPatch) {
const patchList = this._itemPatches.get(path);
patchList?.delete(patch);
if (patchList?.size == 0) {
this._itemPatches.delete(path);
}
this.notifyUpdate();
}
removeItem(item: CustomMainMenuItem) {
this._items.delete(item);
this.notifyUpdate();
return item;
}
removeOverlayPatch(patch: OverlayPatch) {
this._overlayPatches.delete(patch);
this.notifyUpdate();
}
removeOverlayComponent(component: ReactNode) {
this._overlayComponents.delete(component);
this.notifyUpdate();
}
private notifyUpdate() {
this.eventBus.dispatchEvent(new Event('update'));
}
}
interface DeckyMenuStateContext extends PublicDeckyMenuState {
addItem: DeckyMenuState['addItem'];
addPatch: DeckyMenuState['addPatch'];
addOverlayPatch: DeckyMenuState['addOverlayPatch'];
addOverlayComponent: DeckyMenuState['addOverlayComponent'];
removePatch: DeckyMenuState['removePatch'];
removeOverlayPatch: DeckyMenuState['removeOverlayPatch'];
removeOverlayComponent: DeckyMenuState['removeOverlayComponent'];
removeItem: DeckyMenuState['removeItem'];
}
const DeckyMenuStateContext = createContext<DeckyMenuStateContext>(null as any);
export const useDeckyMenuState = () => useContext(DeckyMenuStateContext);
interface Props {
deckyMenuState: DeckyMenuState;
}
export const DeckyMenuStateContextProvider: FC<Props> = ({ children, deckyMenuState }) => {
const [publicDeckyMenuState, setPublicDeckyMenuState] = useState<PublicDeckyMenuState>({
...deckyMenuState.publicState(),
});
useEffect(() => {
function onUpdate() {
setPublicDeckyMenuState({ ...deckyMenuState.publicState() });
}
deckyMenuState.eventBus.addEventListener('update', onUpdate);
return () => deckyMenuState.eventBus.removeEventListener('update', onUpdate);
}, []);
const addItem = deckyMenuState.addItem.bind(deckyMenuState);
const addPatch = deckyMenuState.addPatch.bind(deckyMenuState);
const addOverlayPatch = deckyMenuState.addOverlayPatch.bind(deckyMenuState);
const addOverlayComponent = deckyMenuState.addOverlayComponent.bind(deckyMenuState);
const removePatch = deckyMenuState.removePatch.bind(deckyMenuState);
const removeOverlayPatch = deckyMenuState.removeOverlayPatch.bind(deckyMenuState);
const removeOverlayComponent = deckyMenuState.removeOverlayComponent.bind(deckyMenuState);
const removeItem = deckyMenuState.removeItem.bind(deckyMenuState);
return (
<DeckyMenuStateContext.Provider
value={{
...publicDeckyMenuState,
addItem,
addPatch,
addOverlayPatch,
addOverlayComponent,
removePatch,
removeOverlayPatch,
removeOverlayComponent,
removeItem,
}}
>
{children}
</DeckyMenuStateContext.Provider>
);
};
@@ -1,4 +1,8 @@
import { Patch, findModuleChild, replacePatch } from 'decky-frontend-lib';
import { Patch, findModuleChild, replacePatch, sleep } from 'decky-frontend-lib';
import Logger from '../../../../logger';
const logger = new Logger('LibraryPatch');
declare global {
interface Window {
@@ -10,36 +14,44 @@ declare global {
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 within the first 20s of the last patch
// 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.Apps, 'PromptToChangeShortcut', async ([appid]: number[]) => {
try {
const details = window.appDetailsStore.GetAppDetails(appid);
console.log(details);
logger.debug('game details', details);
// strShortcutStartDir
const file = await window.DeckyPluginLoader.openFilePicker(details.strShortcutStartDir.replaceAll('"', ''));
console.log('user selected', file);
logger.debug('user selected', file);
window.SteamClient.Apps.SetShortcutExe(appid, JSON.stringify(file.path));
const pathArr = file.path.split('/');
pathArr.pop();
const folder = pathArr.join('/');
window.SteamClient.Apps.SetShortcutStartDir(appid, JSON.stringify(folder));
} catch (e) {
console.error(e);
logger.error(e);
}
});
}
// TODO type and add to frontend-lib
const History = findModuleChild((m) => {
if (typeof m !== 'object') return undefined;
for (let prop in m) {
if (m[prop]?.m_history) return m[prop].m_history;
}
});
export default async function libraryPatch() {
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);
}
}
const unlisten = History.listen(() => {
if (window.SteamClient.Apps.PromptToChangeShortcut !== patch.patchedFunction) {
rePatch();
@@ -47,11 +59,11 @@ export default async function libraryPatch() {
});
return () => {
patch.unpatch();
unlisten();
patch.unpatch();
};
} catch (e) {
console.error('Error patching library file picker', e);
logger.error('Error patching library file picker', e);
}
return () => {};
}
+235
View File
@@ -0,0 +1,235 @@
import {
CustomMainMenuItem,
ItemPatch,
MainMenuItem,
OverlayPatch,
afterPatch,
findInReactTree,
sleep,
} from 'decky-frontend-lib';
import { FC } from 'react';
import { ReactNode, cloneElement, createElement } from 'react';
import { DeckyMenuState, DeckyMenuStateContextProvider, useDeckyMenuState } from './components/DeckyMenuState';
import Logger from './logger';
declare global {
interface Window {
__MENU_HOOK_INSTANCE: any;
}
}
class MenuHook extends Logger {
private menuRenderer?: any;
private originalRenderer?: any;
private menuState: DeckyMenuState = new DeckyMenuState();
constructor() {
super('MenuHook');
this.log('Initialized');
window.__MENU_HOOK_INSTANCE?.deinit?.();
window.__MENU_HOOK_INSTANCE = this;
}
init() {
const tree = (document.getElementById('root') as any)._reactRootContainer._internalRoot.current;
let outerMenuRoot: any;
const findMenuRoot = (currentNode: any, iters: number): any => {
if (iters >= 60) {
// currently 54
return null;
}
if (currentNode?.memoizedProps?.navID == 'MainNavMenuContainer') {
this.log(`Menu root was found in ${iters} recursion cycles`);
return currentNode;
}
if (currentNode.child) {
let node = findMenuRoot(currentNode.child, iters + 1);
if (node !== null) return node;
}
if (currentNode.sibling) {
let node = findMenuRoot(currentNode.sibling, iters + 1);
if (node !== null) return node;
}
return null;
};
(async () => {
outerMenuRoot = findMenuRoot(tree, 0);
while (!outerMenuRoot) {
this.error(
'Failed to find Menu root node, reattempting in 5 seconds. A developer may need to increase the recursion limit.',
);
await sleep(5000);
outerMenuRoot = findMenuRoot(tree, 0);
}
this.log('found outermenuroot', outerMenuRoot);
const menuRenderer = outerMenuRoot.return;
this.menuRenderer = menuRenderer;
this.originalRenderer = menuRenderer.type;
let toReplace = new Map<string, ReactNode>();
let alreadyPatched = new Map<string, { total: number; node: ReactNode }>();
let patchedInnerMenu: any;
let overlayComponentManager: any;
const DeckyOverlayComponentManager = () => {
const { overlayComponents } = useDeckyMenuState();
return <>{overlayComponents.values()}</>;
};
const DeckyInnerMenuWrapper = (props: { innerProps: any }) => {
const { overlayPatches } = useDeckyMenuState();
const rendererRet = this.originalRenderer(props.innerProps);
// Find the first array of children, this contains [mainmenu, overlay]
const childArray = findInReactTree(rendererRet, (x) => x?.[0]?.type);
// Insert the overlay components manager
if (!overlayComponentManager) {
overlayComponentManager = <DeckyOverlayComponentManager />;
}
childArray.push(overlayComponentManager);
// This must be cached in patchedInnerMenu to prevent re-renders
if (patchedInnerMenu) {
childArray[0].type = patchedInnerMenu;
} else {
afterPatch(childArray[0], 'type', (_, ret) => {
const { itemPatches, items } = useDeckyMenuState();
const itemList = ret.props.children;
// Add custom menu items
if (items.size > 0) {
const button = findInReactTree(ret.props.children, (x) =>
x?.type?.toString()?.includes('exactRouteMatch:'),
);
const MenuItemComponent: FC<MainMenuItem> = button.type;
items.forEach((item) => {
let realIndex = 0; // there are some non-item things in the array
let count = 0;
itemList.forEach((i: any) => {
if (count == item.index) return;
if (i?.type == MenuItemComponent) count++;
realIndex++;
});
itemList.splice(realIndex, 0, createElement(MenuItemComponent, item));
});
}
// Apply and revert patches
itemList.forEach((item: { props: MainMenuItem }, index: number) => {
if (!item?.props?.route) return;
const replaced = toReplace.get(item?.props?.route as string);
if (replaced) {
itemList[index] = replaced;
toReplace.delete(item?.props.route as string);
}
if (item?.props?.route && (itemPatches.has(item.props.route as string) || itemPatches.has('*'))) {
if (
item?.props?.route &&
alreadyPatched.has(item.props.route) &&
alreadyPatched.get(item.props.route)?.total ==
(itemPatches.get(item.props.route)?.size || 0) + (itemPatches.get('*')?.size || 0)
) {
const patched = alreadyPatched.get(item.props.route);
this.debug('found already patched', patched);
itemList[index] = patched?.node;
return;
}
toReplace.set(item?.props?.route as string, itemList[index]);
itemPatches.get(item.props.route as string)?.forEach((patch) => {
const oType = itemList[index].type;
itemList[index] = patch({
...cloneElement(itemList[index]),
type: (props: any) => createElement(oType, props),
});
});
itemPatches.get('*')?.forEach((patch) => {
const oType = itemList[index].type;
itemList[index] = patch({
...cloneElement(itemList[index]),
type: (props: any) => createElement(oType, props),
});
});
alreadyPatched.set(item.props.route, {
total: (itemPatches.get(item.props.route)?.size || 0) + (itemPatches.get('*')?.size || 0),
node: itemList[index],
});
}
});
return ret;
});
patchedInnerMenu = childArray[0].type;
}
// Apply patches to the overlay
if (childArray[1]) {
overlayPatches.forEach((patch) => (childArray[1] = patch(childArray[1])));
}
return rendererRet;
};
const DeckyOuterMenuWrapper = (props: any) => {
return (
<DeckyMenuStateContextProvider deckyMenuState={this.menuState}>
<DeckyInnerMenuWrapper innerProps={props} />
</DeckyMenuStateContextProvider>
);
};
menuRenderer.type = DeckyOuterMenuWrapper;
if (menuRenderer.alternate) {
menuRenderer.alternate.type = menuRenderer.type;
}
this.log('Finished initial injection');
})();
}
deinit() {
this.menuRenderer.type = this.originalRenderer;
this.menuRenderer.alternate.type = this.menuRenderer.type;
}
addItem(item: CustomMainMenuItem) {
return this.menuState.addItem(item);
}
addPatch(path: string, patch: ItemPatch) {
return this.menuState.addPatch(path, patch);
}
addOverlayPatch(patch: OverlayPatch) {
return this.menuState.addOverlayPatch(patch);
}
addOverlayComponent(component: ReactNode) {
return this.menuState.addOverlayComponent(component);
}
removePatch(path: string, patch: ItemPatch) {
return this.menuState.removePatch(path, patch);
}
removeItem(item: CustomMainMenuItem) {
return this.menuState.removeItem(item);
}
removeOverlayPatch(patch: OverlayPatch) {
return this.menuState.removeOverlayPatch(patch);
}
removeOverlayComponent(component: ReactNode) {
return this.menuState.removeOverlayComponent(component);
}
}
export default MenuHook;
+9 -17
View File
@@ -1,13 +1,4 @@
import {
ConfirmModal,
ModalRoot,
Patch,
QuickAccessTab,
Router,
showModal,
sleep,
staticClasses,
} from 'decky-frontend-lib';
import { ConfirmModal, ModalRoot, QuickAccessTab, Router, showModal, sleep, staticClasses } from 'decky-frontend-lib';
import { FC, lazy } from 'react';
import { FaCog, FaExclamationCircle, FaPlug } from 'react-icons/fa';
@@ -19,8 +10,10 @@ import NotificationBadge from './components/NotificationBadge';
import PluginView from './components/PluginView';
import WithSuspense from './components/WithSuspense';
import Logger from './logger';
import MenuHook from './menu-hook';
import { Plugin } from './plugin';
import RouterHook from './router-hook';
import { deinitSteamFixes, initSteamFixes } from './steamfixes';
import { checkForUpdates } from './store';
import TabsHook from './tabs-hook';
import OldTabsHook from './tabs-hook.old';
@@ -33,13 +26,10 @@ const SettingsPage = lazy(() => import('./components/settings'));
const FilePicker = lazy(() => import('./components/modals/filepicker'));
declare global {
interface Window {}
}
class PluginLoader extends Logger {
private plugins: Plugin[] = [];
private tabsHook: TabsHook | OldTabsHook = document.title == 'SP' ? new OldTabsHook() : new TabsHook();
private menuHook: MenuHook = new MenuHook();
// private windowHook: WindowHook = new WindowHook();
private routerHook: RouterHook = new RouterHook();
public toaster: Toaster = new Toaster();
@@ -49,11 +39,10 @@ class PluginLoader extends Logger {
// stores a list of plugin names which requested to be reloaded
private pluginReloadQueue: { name: string; version?: string }[] = [];
private focusWorkaroundPatch?: Patch;
constructor() {
super(PluginLoader.name);
this.tabsHook.init();
this.menuHook.init();
this.log('Initialized');
const TabBadge = () => {
@@ -92,6 +81,8 @@ class PluginLoader extends Logger {
);
});
initSteamFixes();
initFilepickerPatches();
this.updateVersion();
@@ -184,8 +175,8 @@ class PluginLoader extends Logger {
public deinit() {
this.routerHook.removeRoute('/decky/store');
this.routerHook.removeRoute('/decky/settings');
deinitSteamFixes();
deinitFilepickerPatches();
this.focusWorkaroundPatch?.unpatch();
}
public unloadPlugin(name: string) {
@@ -322,6 +313,7 @@ class PluginLoader extends Logger {
createPluginAPI(pluginName: string) {
return {
menuHook: this.menuHook,
routerHook: this.routerHook,
toaster: this.toaster,
callServerMethod: this.callServerMethod,
+13 -5
View File
@@ -120,6 +120,8 @@ class RouterHook extends Logger {
return <>{renderedComponents}</>;
};
let globalComponents: any;
this.wrapperPatch = afterPatch(this.gamepadWrapper, 'render', (_: any, ret: any) => {
if (ret?.props?.children?.props?.children?.length == 5 || ret?.props?.children?.props?.children?.length == 4) {
const idx = ret?.props?.children?.props?.children?.length == 4 ? 1 : 2;
@@ -143,11 +145,17 @@ class RouterHook extends Logger {
this.memoizedRouter = memo(this.router.type);
this.memoizedRouter.isDeckyRouter = true;
}
ret.props.children.props.children.push(
<DeckyGlobalComponentsStateContextProvider deckyGlobalComponentsState={this.globalComponentsState}>
<DeckyGlobalComponentsWrapper />
</DeckyGlobalComponentsStateContextProvider>,
);
if (!globalComponents) {
globalComponents = (
<DeckyGlobalComponentsStateContextProvider deckyGlobalComponentsState={this.globalComponentsState}>
<DeckyGlobalComponentsWrapper />
</DeckyGlobalComponentsStateContextProvider>
);
}
ret.props.children.props.children.push(globalComponents);
ret.props.children.props.children[idx].props.children[0].type = this.memoizedRouter;
}
}
+13
View File
@@ -0,0 +1,13 @@
## What's this?
`steamfixes` contains various fixes and workaround for things Valve has broken that cause Decky issues.
## Current fixes:
- StartRestart() -> StartShutdown(false) override:
StartRestart() breaks CEF debugging, StartShutdown(false) doesn't. We can safely replace StartRestart() with StartShutdown(false) as gamescope-session will automatically restart the steam client anyway if it shuts down, bypassing the broken restart codepath. Added 12/29/2022
- ExecuteSteamURL UI reload fix:
Starting sometime in November 2022, Valve broke reloading the Steam UI pages via location.reload, as it won't properly start the UI. We can manually trigger UI startup if we detect no active input contexts by calling `SteamClient.URL.ExecuteSteamURL("steam://open/settings/")` Added 12/29/2022
+12
View File
@@ -0,0 +1,12 @@
import reloadFix from './reload';
import restartFix from './restart';
let fixes: Function[] = [];
export function deinitSteamFixes() {
fixes.forEach((deinit) => deinit());
}
export async function initSteamFixes() {
fixes.push(reloadFix());
fixes.push(await restartFix());
}
+14
View File
@@ -0,0 +1,14 @@
import Logger from '../logger';
const logger = new Logger('ReloadSteamFix');
export default function reloadFix() {
// Hack to unbreak the ui when reloading it
if (window.FocusNavController?.m_rgAllContexts?.length == 0) {
SteamClient.URL.ExecuteSteamURL('steam://open/settings');
logger.log('Applied UI reload fix.');
}
// This steamfix does not need to deinit.
return () => {};
}
+60
View File
@@ -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 () => {};
}
-1
View File
@@ -7,7 +7,6 @@ import Logger from './logger';
declare global {
interface Window {
__TABS_HOOK_INSTANCE: any;
securitystore: any;
}
}