diff options
| author | AAGaming <aagaming@riseup.net> | 2024-09-16 16:17:20 -0400 |
|---|---|---|
| committer | AAGaming <aagaming@riseup.net> | 2024-09-16 16:17:20 -0400 |
| commit | f69eb72df9e2730201ae3017883a6f99b35d2f24 (patch) | |
| tree | 4fad7beb460c5a80234e0c331e4712458b1c2086 /frontend | |
| parent | 24215c0732dba17a85cbe7776a05ca1f3bd1aa58 (diff) | |
| download | decky-loader-f69eb72df9e2730201ae3017883a6f99b35d2f24.tar.gz decky-loader-f69eb72df9e2730201ae3017883a6f99b35d2f24.zip | |
wait for SteamApp init stage 1 to finish before loading decky's frontend bundle
should fix the startup race condition
Diffstat (limited to 'frontend')
| -rw-r--r-- | frontend/src/index.ts | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/frontend/src/index.ts b/frontend/src/index.ts index 8d67f175..212f81d0 100644 --- a/frontend/src/index.ts +++ b/frontend/src/index.ts @@ -2,32 +2,22 @@ interface Window { // Shut up TS SP_REACTDOM: any; + App: any; // TODO type BFinishedInitStageOne in @decky/ui } (async () => { - // Wait for main webpack chunks to definitely be loaded - console.time('[Decky:Boot] Waiting for main Webpack chunks...'); - while (!window.webpackChunksteamui || window.webpackChunksteamui.length < 5) { - await new Promise((r) => setTimeout(r, 10)); // Can't use DFL sleep here. - } - console.timeEnd('[Decky:Boot] Waiting for main Webpack chunks...'); + console.debug('[Decky:Boot] Frontend init'); + + console.time('[Decky:Boot] Waiting for SteamApp init stage 1 to finish...'); - // Wait for the React root to be mounted - console.time('[Decky:Boot] Waiting for React root mount...'); - let root; - while ( - // Does React root node exist? - !(root = document.getElementById('root')) || - // Does it have a child element? - !(root as any)[Object.keys(root).find((k) => k.startsWith('__reactContainer$')) as string].child - ) { - await new Promise((r) => setTimeout(r, 10)); // Can't use DFL sleep here. + while (!window.App?.BFinishedInitStageOne()) { + await new Promise((r) => setTimeout(r, 0)); // Can't use DFL sleep here. } - console.timeEnd('[Decky:Boot] Waiting for React root mount...'); + + 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...'); - await new Promise((r) => setTimeout(r, 500)); // Can't use DFL sleep here. // deliberate partial import const DFLWebpack = await import('@decky/ui/dist/webpack'); window.SP_REACT = DFLWebpack.findModule((m) => m.Component && m.PureComponent && m.useLayoutEffect); |
