fix(desktop): improve server detection & connection logic (#7962)

This commit is contained in:
Brendan Allan
2026-01-12 17:58:13 +08:00
committed by GitHub
parent 087473be6e
commit ebbb4dd88a
5 changed files with 181 additions and 199 deletions

View File

@@ -13,7 +13,7 @@ import { AsyncStorage } from "@solid-primitives/storage"
import { fetch as tauriFetch } from "@tauri-apps/plugin-http"
import { Store } from "@tauri-apps/plugin-store"
import { Logo } from "@opencode-ai/ui/logo"
import { Suspense, createResource, ParentProps } from "solid-js"
import { Accessor, JSX, createResource } from "solid-js"
import { UPDATER_ENABLED } from "./updater"
import { createMenu } from "./menu"
@@ -283,7 +283,9 @@ render(() => {
)}
<AppBaseProviders>
<ServerGate>
<AppInterface />
{serverUrl =>
<AppInterface defaultUrl={serverUrl()} />
}
</ServerGate>
</AppBaseProviders>
</PlatformProvider>
@@ -291,26 +293,21 @@ render(() => {
}, root!)
// Gate component that waits for the server to be ready
function ServerGate(props: ParentProps) {
const [status] = createResource(async () => {
if (window.__OPENCODE__?.serverReady) return
return await invoke("ensure_server_started")
})
function ServerGate(props: { children: (url: Accessor<string>) => JSX.Element }) {
const [serverUrl] = createResource<string>(() => invoke("ensure_server_ready"))
return (
// Not using suspense as not all components are compatible with it (undefined refs)
<Show
when={status.state !== "pending"}
when={serverUrl.state !== "pending" && serverUrl()}
fallback={
<div class="h-screen w-screen flex flex-col items-center justify-center bg-background-base">
<Logo class="w-xl opacity-12 animate-pulse" />
<div class="mt-8 text-14-regular text-text-weak">Starting server...</div>
<div class="mt-8 text-14-regular text-text-weak">Initializing...</div>
</div>
}
>
{/* Trigger error boundary without rendering the returned value */}
{(status(), null)}
{props.children}
{serverUrl => props.children(serverUrl)}
</Show>
)
}