mirror of
https://github.com/SteamDeckHomebrew/decky-loader.git
synced 2026-06-17 08:47:49 +00:00
wait for SteamApp init stage 1 to finish before loading decky's frontend bundle
should fix the startup race condition
This commit is contained in:
+8
-18
@@ -2,32 +2,22 @@
|
|||||||
interface Window {
|
interface Window {
|
||||||
// Shut up TS
|
// Shut up TS
|
||||||
SP_REACTDOM: any;
|
SP_REACTDOM: any;
|
||||||
|
App: any; // TODO type BFinishedInitStageOne in @decky/ui
|
||||||
}
|
}
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
// Wait for main webpack chunks to definitely be loaded
|
console.debug('[Decky:Boot] Frontend init');
|
||||||
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...');
|
|
||||||
|
|
||||||
// Wait for the React root to be mounted
|
console.time('[Decky:Boot] Waiting for SteamApp init stage 1 to finish...');
|
||||||
console.time('[Decky:Boot] Waiting for React root mount...');
|
|
||||||
let root;
|
while (!window.App?.BFinishedInitStageOne()) {
|
||||||
while (
|
await new Promise((r) => setTimeout(r, 0)); // Can't use DFL sleep here.
|
||||||
// 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.
|
|
||||||
}
|
}
|
||||||
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) {
|
if (!window.SP_REACT) {
|
||||||
console.debug('[Decky:Boot] Setting up Webpack & React globals...');
|
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
|
// deliberate partial import
|
||||||
const DFLWebpack = await import('@decky/ui/dist/webpack');
|
const DFLWebpack = await import('@decky/ui/dist/webpack');
|
||||||
window.SP_REACT = DFLWebpack.findModule((m) => m.Component && m.PureComponent && m.useLayoutEffect);
|
window.SP_REACT = DFLWebpack.findModule((m) => m.Component && m.PureComponent && m.useLayoutEffect);
|
||||||
|
|||||||
Reference in New Issue
Block a user