summaryrefslogtreecommitdiff
path: root/frontend/src/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'frontend/src/index.ts')
-rw-r--r--frontend/src/index.ts82
1 files changed, 56 insertions, 26 deletions
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<string, Record<string, any>>,
+ scopedObjects: Map<number, any>
+ }
+}
+
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');
})();