From ddb3d03864434a4893e9667b0b4abba643999a85 Mon Sep 17 00:00:00 2001 From: "Timothy Z." Date: Sun, 14 Jun 2026 15:00:01 +0300 Subject: [PATCH] fix: delay shell app-ready --- src/App/App.js | 8 +++++++- src/common/Platform/shell/shell.d.ts | 1 + src/common/Platform/shell/useShell.ts | 14 +++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/App/App.js b/src/App/App.js index 4906a5921..ecd6fabbb 100644 --- a/src/App/App.js +++ b/src/App/App.js @@ -26,6 +26,7 @@ const App = () => { const { i18n } = useTranslation(); const { shell } = usePlatform(); const [gamepadSupportEnabled, setGamepadSupportEnabled] = React.useState(false); + const appReadySent = React.useRef(false); const onPathNotMatch = React.useCallback(() => { return NotFound; }, []); @@ -126,10 +127,15 @@ const App = () => { shell.on('open-media', onOpenMedia); + if (shell.state.initialized && !appReadySent.current) { + appReadySent.current = true; + shell.send('app-ready'); + } + return () => { shell.off('open-media', onOpenMedia); }; - }, []); + }, [shell.state.initialized]); React.useEffect(() => { if (typeof profile.settings?.interfaceLanguage === 'string') { diff --git a/src/common/Platform/shell/shell.d.ts b/src/common/Platform/shell/shell.d.ts index 3d8d47e23..bf7b25ca5 100644 --- a/src/common/Platform/shell/shell.d.ts +++ b/src/common/Platform/shell/shell.d.ts @@ -21,6 +21,7 @@ interface Shell { } type ShellState = { + initialized: boolean; version: string | null; windowClosed: boolean; windowHidden: boolean; diff --git a/src/common/Platform/shell/useShell.ts b/src/common/Platform/shell/useShell.ts index cad232540..55775578d 100644 --- a/src/common/Platform/shell/useShell.ts +++ b/src/common/Platform/shell/useShell.ts @@ -36,6 +36,7 @@ type ShellMessage = { const useShell = (): Shell => { const [state, setState] = useState({ + initialized: false, version: null, windowClosed: false, windowHidden: false, @@ -81,11 +82,6 @@ const useShell = (): Shell => { }, []); useEffect(() => { - IPC?.postMessage(JSON.stringify({ - id: 0, - type: ShellEventType.INIT, - })); - const onMessage = (message: ShellMessage) => { try { const event = JSON.parse(message.data) as ShellEvent; @@ -94,8 +90,7 @@ const useShell = (): Shell => { const { data } = event as ShellEventInit; const [, [,,, version]] = data.transport.properties; - setState((state) => ({ ...state, version })); - send('app-ready'); + setState((state) => ({ ...state, initialized: true, version })); } if (event.type === ShellEventType.SIGNAL) { @@ -109,6 +104,11 @@ const useShell = (): Shell => { }; IPC?.addEventListener('message', onMessage); + IPC?.postMessage(JSON.stringify({ + id: 0, + type: ShellEventType.INIT, + })); + return () => IPC?.removeEventListener('message', onMessage); }, []);