diff --git a/packages/desktop-electron/src/main/index.ts b/packages/desktop-electron/src/main/index.ts index 56c9c943fd..d3b617f863 100644 --- a/packages/desktop-electron/src/main/index.ts +++ b/packages/desktop-electron/src/main/index.ts @@ -142,7 +142,16 @@ async function initialize() { const password = randomUUID() logger.log("spawning sidecar", { url }) - const { listener, health } = await spawnLocalServer(hostname, port, password) + localServer.setRuntime({ key: "local:windows", mode: "windows", distro: null }) + localServer.setStatus({ kind: "running", step: null }) + const { listener, health } = await spawnLocalServer(hostname, port, password).catch((error) => { + localServer.setStatus({ + kind: "failed", + step: null, + message: error instanceof Error ? error.message : String(error), + }) + throw error + }) server = listener serverReady.resolve({ url, @@ -169,9 +178,18 @@ async function initialize() { delay(30_000).then(() => { throw new Error("Sidecar health check timed out") }), - ]).catch((error) => { - logger.error("sidecar health check failed", error) - }) + ]) + .then(() => { + localServer.setStatus({ kind: "ready" }) + }) + .catch((error) => { + localServer.setStatus({ + kind: "failed", + step: null, + message: error instanceof Error ? error.message : String(error), + }) + logger.error("sidecar health check failed", error) + }) logger.log("loading task finished") })() diff --git a/packages/desktop-electron/src/main/local-server.ts b/packages/desktop-electron/src/main/local-server.ts index ee48a6656a..843eb1deab 100644 --- a/packages/desktop-electron/src/main/local-server.ts +++ b/packages/desktop-electron/src/main/local-server.ts @@ -26,6 +26,11 @@ export function createLocalServerController() { for (const listener of listeners) listener(event) } + const update = (next: LocalServerState) => { + state = next + emit({ type: "state", state }) + } + return { getState() { return state @@ -33,13 +38,27 @@ export function createLocalServerController() { setConfig(config: LocalServerConfig) { const next = normalizeLocalServerConfig(config) store.set(LOCAL_SERVER_KEY, next) - state = toState(next, state) - emit({ type: "state", state }) + update({ + ...state, + config: next, + }) }, subscribe(listener: (event: LocalServerEvent) => void) { listeners.add(listener) return () => listeners.delete(listener) }, + setRuntime(runtime: LocalServerState["runtime"]) { + update({ + ...state, + runtime, + }) + }, + setStatus(status: LocalServerState["status"]) { + update({ + ...state, + status, + }) + }, } } @@ -50,11 +69,7 @@ function readLocalServerConfig() { function toState(config: LocalServerConfig, current?: LocalServerState): LocalServerState { return { config, - runtime: { - key: localServerKey(config), - mode: config.mode, - distro: config.distro, - }, + runtime: current?.runtime ?? windowsRuntime(), status: current?.status ?? { kind: "idle" }, job: current?.job ?? null, } @@ -114,3 +129,14 @@ function localServerKey(config: LocalServerConfig) { if (!config.distro) return "local:wsl" return `local:wsl:${config.distro}` } + +function windowsRuntime(): LocalServerState["runtime"] { + return { + key: localServerKey({ + ...defaultLocalServerConfig(), + mode: "windows", + }), + mode: "windows", + distro: null, + } +}