From 02db20f846857374b9b5f1e7dbd475befdf47b71 Mon Sep 17 00:00:00 2001 From: AAGaming Date: Sat, 21 Nov 2026 21:14:41 -0500 Subject: esmodule support base --- frontend/src/components/Toast.tsx | 47 +++++++++++-------- frontend/src/components/store/Store.tsx | 8 +--- frontend/src/errorboundary-hook.tsx | 2 +- frontend/src/index.ts | 82 ++++++++++++++++++++++----------- frontend/src/plugin-loader.tsx | 2 +- frontend/src/router-hook.tsx | 19 ++------ frontend/src/tabs-hook.tsx | 4 +- frontend/src/toaster.tsx | 5 +- 8 files changed, 96 insertions(+), 73 deletions(-) (limited to 'frontend/src') diff --git a/frontend/src/components/Toast.tsx b/frontend/src/components/Toast.tsx index e86e9337..aa2e665f 100644 --- a/frontend/src/components/Toast.tsx +++ b/frontend/src/components/Toast.tsx @@ -1,5 +1,5 @@ import type { ToastData } from '@decky/api'; -import { Focusable, Navigation, findClassModule, joinClassNames } from '@decky/ui'; +import { Focusable, Navigation, joinClassNames, toastClasses } from '@decky/ui'; import { FC, memo } from 'react'; import Logger from '../logger'; @@ -23,7 +23,14 @@ interface ToastRendererProps extends ToastProps { location: ToastLocation; } -const templateClasses = findClassModule((m) => m.ShortTemplate) || {}; +const popupClasses = { + "ShortTemplate": "kg8VJS07NZk-", + "Content": "vjeKRorxqWY-", + "Header": "UWjdKshdhD8-", + "Icon": "q9vQBNOskjU-", + "Title": "RZ1644uUH-k-", + "Body": "_5LTIC-a3DVw-" +} // These are memoized as they like to randomly rerender @@ -32,15 +39,15 @@ const GamepadUIPopupToast: FC> = memo(({ toast
- {toast.logo &&
{toast.logo}
} -
-
- {toast.icon &&
{toast.icon}
} -
{toast.title}
+ {toast.logo &&
{toast.logo}
} +
+
+ {toast.icon &&
{toast.icon}
} +
{toast.title}
-
{toast.body}
+
{toast.body}
); @@ -55,30 +62,30 @@ const GamepadUIQAMToast: FC = memo(({ toast, newIndicator }) => { Navigation.CloseSideMenus(); }} className={joinClassNames( - templateClasses.StandardTemplateContainer, + toastClasses.StandardTemplateContainer, toast.className || '', 'DeckyGamepadUIQAMToast', )} > -
- {toast.logo &&
{toast.logo}
} -
-
- {toast.icon &&
{toast.icon}
} - {toast.title &&
{toast.title}
} +
+ {toast.logo &&
{toast.logo}
} +
+
+ {toast.icon &&
{toast.icon}
} + {toast.title &&
{toast.title}
} {/* timestamp should always be defined by toaster */} {/* TODO check how valve does this */} {toast.timestamp && ( -
+
{toast.timestamp.toLocaleTimeString(undefined, { timeStyle: 'short' })}
)}
- {toast.body &&
{toast.body}
} - {toast.subtext &&
{toast.subtext}
} + {toast.body &&
{toast.body}
} + {toast.subtext &&
{toast.subtext}
}
{newIndicator && ( -
+
diff --git a/frontend/src/components/store/Store.tsx b/frontend/src/components/store/Store.tsx index cfa83aff..da909fd7 100644 --- a/frontend/src/components/store/Store.tsx +++ b/frontend/src/components/store/Store.tsx @@ -7,7 +7,7 @@ import { SteamSpinner, Tabs, TextField, - findModule, + tabsClasses } from '@decky/ui'; import { Dispatch, FC, SetStateAction, useEffect, useMemo, useState } from 'react'; import { useTranslation } from 'react-i18next'; @@ -32,10 +32,6 @@ const logger = new Logger('Store'); const StorePage: FC<{}> = () => { const [currentTabRoute, setCurrentTabRoute] = useState('browse'); const [pluginCount, setPluginCount] = useState(null); - const { TabCount } = findModule((m) => { - if (m?.TabCount && m?.TabTitle) return true; - return false; - }); const { t } = useTranslation(); @@ -58,7 +54,7 @@ const StorePage: FC<{}> = () => { title: t('Store.store_tabs.title'), content: , id: 'browse', - renderTabAddon: () => {pluginCount}, + renderTabAddon: () => {pluginCount}, }, { title: t('Store.store_tabs.about'), diff --git a/frontend/src/errorboundary-hook.tsx b/frontend/src/errorboundary-hook.tsx index 9dbe9dcd..2bbecc58 100644 --- a/frontend/src/errorboundary-hook.tsx +++ b/frontend/src/errorboundary-hook.tsx @@ -26,7 +26,7 @@ class ErrorBoundaryHook extends Logger { // valve writes only the sanest of code const exp = /^\(\)=>\([\w$]+\|\|(?:[\w$]+\(|\([\w$]+=)new [\w$]+\),[\w$]+\)$/; const initErrorReportingStore = findModuleExport( - (e) => typeof e == 'function' && e?.toString && exp.test(e.toString()), + (e) => typeof e == 'function' && e?.toString && (exp.test(e.toString()) || e.toString() == "()=>(store||=new CErrorReportingStore,store)"), ); if (!initErrorReportingStore) { diff --git a/frontend/src/index.ts b/frontend/src/index.ts index 67b30d15..162e8f36 100644 --- a/frontend/src/index.ts +++ b/frontend/src/index.ts @@ -1,5 +1,12 @@ // Sets up DFL, then loads start.ts which starts up the loader +interface Window { + _deckyModuleResolverInternals: { + scopes: Map>, + scopedObjects: Map + } +} + interface SteamAppInitialization { BFinishedInitBeforeLogin?: () => boolean; BFinishedInitStageOne?: () => boolean; @@ -13,42 +20,65 @@ const isSteamAppInitialized = () => { (async () => { console.debug('[Decky:Boot] Frontend init'); + console.debug('[Decky:Boot] Authenticating with Decky backend...'); + window.deckyAuthToken = await fetch('http://127.0.0.1:1337/auth/token').then((r) => r.text()); + console.debug('[Decky:Boot] Connecting to Decky backend...'); + const ws = window.DeckyBackend = new (await import('./wsrouter')).WSRouter(); + await ws.connect(); + console.time('[Decky:Boot] Waiting for SteamApp init stage 1 to finish...'); while (!isSteamAppInitialized()) { await new Promise((r) => setTimeout(r, 0)); // Can't use DFL sleep here. } - console.timeEnd('[Decky:Boot] Waiting for SteamApp init stage 1 to finish...'); - - if (!window.SP_REACT) { - console.debug('[Decky:Boot] Setting up Webpack & React globals...'); - // deliberate partial import - const DFLWebpack = await import('@decky/ui/dist/webpack'); - window.SP_REACT = DFLWebpack.findModule((m) => m.Component && m.PureComponent && m.useLayoutEffect); - window.SP_REACTDOM = - DFLWebpack.findModule((m) => m.createPortal && m.createRoot) || - DFLWebpack.findModule((m) => m.createPortal && m.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE); - - console.debug('[Decky:Boot] Setting up JSX internals...'); - const jsxModule = DFLWebpack.findModule((m) => (m.jsx && m.jsxs) || (m.jsx && Object.keys(m).length == 1)); - if (jsxModule.jsxs) { - window.SP_JSX = jsxModule; - } else { - window.SP_JSX = { - jsx: jsxModule.jsx, - jsxs: jsxModule.jsx, - Fragment: window.SP_REACT.Fragment, - }; + console.debug('[Decky:Boot] Setting up Module System & React globals...'); + + let moduleId = 0; + const int = window._deckyModuleResolverInternals = { + scopes: new Map(), + scopedObjects: new Map() + }; + const resolveThroughBackend = ws.callable<[objectKey: number]>("instrumentation/resolve_scope"); + async function resolveModuleScope(objectFromScope: any, moduleForDebug?: string) { + let ret; + const id = ++moduleId; + try { + int.scopedObjects.set(id, objectFromScope) + await resolveThroughBackend(id); + ret = int.scopes.get(id); + } catch(e) { + console.debug(`[Decky:Instrumentation] Scope resolution failed for module ${moduleForDebug}`, e); + } finally { + int.scopes.delete(id); + int.scopedObjects.delete(id); } + return ret; + } + + // deliberate partial import + const DFLModules = await import('@decky/ui/dist/module-system'); + await DFLModules.initModules(resolveModuleScope); + // @ts-ignore + window.DFLModules = DFLModules; + window.SP_REACT = DFLModules.findModule((m) => m.Component && m.PureComponent && m.useLayoutEffect); + window.SP_REACTDOM = + DFLModules.findModule((m) => m.createPortal && m.createRoot) || + DFLModules.findModule((m) => m.createPortal && m.__DOM_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE); + + console.debug('[Decky:Boot] Setting up JSX internals...'); + const jsxModule = DFLModules.findModule((m) => (m.jsx && m.jsxs) || (m.jsx && Object.keys(m).length == 1)); + if (jsxModule?.jsxs) { + window.SP_JSX = jsxModule; + } else { + window.SP_JSX = { + jsx: jsxModule.jsx, + jsxs: jsxModule.jsx, + Fragment: window.SP_REACT.Fragment, + }; } console.debug('[Decky:Boot] Setting up @decky/ui...'); window.DFL = await import('@decky/ui'); - console.debug('[Decky:Boot] Authenticating with Decky backend...'); - window.deckyAuthToken = await fetch('http://127.0.0.1:1337/auth/token').then((r) => r.text()); - console.debug('[Decky:Boot] Connecting to Decky backend...'); - window.DeckyBackend = new (await import('./wsrouter')).WSRouter(); - await DeckyBackend.connect(); console.debug('[Decky:Boot] Starting Decky!'); await import('./start'); })(); diff --git a/frontend/src/plugin-loader.tsx b/frontend/src/plugin-loader.tsx index 81b96dcc..49f5734b 100644 --- a/frontend/src/plugin-loader.tsx +++ b/frontend/src/plugin-loader.tsx @@ -554,7 +554,7 @@ class PluginLoader extends Logger { -
+
typeof e == 'string' && e == 'router-backstack', 20); - if (reactRouterStackModule) { - this.Route = - Object.values(reactRouterStackModule).find( - (e) => typeof e == 'function' && /routePath:[\w$]+\.match\?\.path./.test(e.toString()), - ) || - Object.values(reactRouterStackModule).find( - (e) => typeof e == 'function' && /routePath:null===\(.=.\.match\)/.test(e.toString()), - ); - if (!this.Route) { - this.error('Failed to find Route component'); - } - } else { - this.error('Failed to find router stack module'); + this.Route = findVar((e) => /routePath:[\w$]+\.match\?\.path./.test(e.toString())) + if (!this.Route) { + this.error('Failed to find Route component'); } this.modeChangeRegistration = SteamClient.UI.RegisterForUIModeChanged((mode: EUIMode) => { diff --git a/frontend/src/tabs-hook.tsx b/frontend/src/tabs-hook.tsx index ecb60f30..5098834c 100644 --- a/frontend/src/tabs-hook.tsx +++ b/frontend/src/tabs-hook.tsx @@ -6,7 +6,7 @@ import { afterPatch, createReactTreePatcher, findInReactTree, - findModuleByExport, + findModuleScopeByVar, getReactRoot, } from '@decky/ui'; @@ -41,7 +41,7 @@ class TabsHook extends Logger { } init() { - const qamModule = findModuleByExport((e) => e?.type?.toString?.()?.includes('QuickAccessMenuBrowserView')); + const qamModule = findModuleScopeByVar((e) => e?.type?.toString?.()?.includes('QuickAccessMenuBrowserView')); const qamBrowserViewRenderer = Object.values(qamModule).find((e: any) => e?.type?.toString?.()?.includes('QuickAccessMenuBrowserView'), ); diff --git a/frontend/src/toaster.tsx b/frontend/src/toaster.tsx index e5b2d986..572a1bba 100644 --- a/frontend/src/toaster.tsx +++ b/frontend/src/toaster.tsx @@ -4,7 +4,7 @@ import { ErrorBoundary, Patch, callOriginal, - findModuleExport, + findVar, injectFCTrampoline, replacePatch, } from '@decky/ui'; @@ -27,7 +27,8 @@ class Toaster extends Logger { window.__TOASTER_INSTANCE?.deinit?.(); window.__TOASTER_INSTANCE = this; - const ValveToastRenderer = findModuleExport((e) => e?.toString?.()?.includes(`controller:"notification",method:`)); + // TODO regex? + const ValveToastRenderer = findVar((e) => e?.toString?.()?.includes(`controller:\`notification\`,method:`)); // TODO find a way to undo this if possible? const patchedRenderer = injectFCTrampoline(ValveToastRenderer); this.toastPatch = replacePatch(patchedRenderer, 'component', (args: any[]) => { -- cgit v1.2.3