diff --git a/apps/renderer/src/App.tsx b/apps/renderer/src/App.tsx index 83b734ff71..eb14eb15f9 100644 --- a/apps/renderer/src/App.tsx +++ b/apps/renderer/src/App.tsx @@ -60,6 +60,45 @@ function BootstrapRouter() { return null; } +function RuntimeHealthRouter() { + const api = readNativeApi(); + const { dispatch } = useStore(); + + useEffect(() => { + if (!api) return; + let cancelled = false; + + const checkHealth = async () => { + try { + await api.app.health(); + if (cancelled) return; + dispatch({ type: "SET_RUNTIME_ERROR", error: null }); + } catch (error) { + if (cancelled) return; + dispatch({ + type: "SET_RUNTIME_ERROR", + error: + error instanceof Error + ? error.message + : "Could not connect to the local t3 runtime.", + }); + } + }; + + void checkHealth(); + const interval = window.setInterval(() => { + void checkHealth(); + }, 8_000); + + return () => { + cancelled = true; + window.clearInterval(interval); + }; + }, [api, dispatch]); + + return null; +} + function Layout() { const api = readNativeApi(); const { state } = useStore(); @@ -78,6 +117,7 @@ function Layout() { return (