From e2fde3c3394724191c5a4b2ee0d7bd4e23365999 Mon Sep 17 00:00:00 2001 From: Josh Gratton Date: Tue, 16 Jun 2026 09:48:50 -0400 Subject: [PATCH] desktop: show connecting splash in WSL-only mode In WSL-only mode the renderer is served by the WSL backend (distro IP), so the main window cannot load until WSL has cold-booted. That left the app with no window at all for several seconds after launch, which reads as a hang. Show a lightweight frameless "Connecting to WSL" splash window as soon as bootstrap starts (gated on wslOnly + wslBackendEnabled), and dismiss it the moment the real main window reveals. Dual mode opens fast off the Windows primary, so no splash is shown there. - DesktopWindow: add showConnectingSplash, tracked in its own splashWindowRef so currentMainOrFirst and createMainIfBackendReady never mistake the splash for the real main window; dismiss on reveal. - DesktopApp bootstrap: trigger the splash before primary start when the persisted settings select WSL-only mode. - Drop the now-unused DesktopState import left over from the backendReadyRef refactor. --- apps/desktop/src/app/DesktopApp.ts | 9 ++ .../src/backend/DesktopBackendPool.test.ts | 1 + .../src/window/DesktopApplicationMenu.test.ts | 1 + apps/desktop/src/window/DesktopWindow.ts | 86 ++++++++++++++++++- 4 files changed, 94 insertions(+), 3 deletions(-) diff --git a/apps/desktop/src/app/DesktopApp.ts b/apps/desktop/src/app/DesktopApp.ts index 5d9782600c..848f264271 100644 --- a/apps/desktop/src/app/DesktopApp.ts +++ b/apps/desktop/src/app/DesktopApp.ts @@ -13,6 +13,7 @@ import { installDesktopIpcHandlers } from "../ipc/DesktopIpcHandlers.ts"; import * as DesktopAppIdentity from "./DesktopAppIdentity.ts"; import * as DesktopCloudAuth from "./DesktopCloudAuth.ts"; import * as DesktopApplicationMenu from "../window/DesktopApplicationMenu.ts"; +import * as DesktopWindow from "../window/DesktopWindow.ts"; import * as DesktopBackendPool from "../backend/DesktopBackendPool.ts"; import * as DesktopEnvironment from "./DesktopEnvironment.ts"; import * as DesktopLifecycle from "./DesktopLifecycle.ts"; @@ -140,6 +141,7 @@ const bootstrap = Effect.gen(function* () { const desktopSettings = yield* DesktopAppSettings.DesktopAppSettings; const serverExposure = yield* DesktopServerExposure.DesktopServerExposure; const wslBackend = yield* DesktopWslBackend.DesktopWslBackend; + const desktopWindow = yield* DesktopWindow.DesktopWindow; yield* logBootstrapInfo("bootstrap start"); if (environment.isDevelopment && Option.isNone(environment.configuredBackendPort)) { @@ -183,6 +185,13 @@ const bootstrap = Effect.gen(function* () { yield* logBootstrapInfo("bootstrap ipc handlers registered"); if (!(yield* Ref.get(state.quitting))) { + // In wsl-only mode the renderer is served by the WSL backend, which can be + // slow to cold-boot — show a "Connecting to WSL" splash immediately so the + // app feels responsive instead of presenting no window until WSL is ready. + // (Dual mode opens fast off the Windows primary, so no splash there.) + if (settings.wslOnly === true && settings.wslBackendEnabled === true) { + yield* desktopWindow.showConnectingSplash; + } yield* primaryBackend.start; yield* logBootstrapInfo("bootstrap backend start requested"); // Bring up the WSL backend if the user previously enabled it. The diff --git a/apps/desktop/src/backend/DesktopBackendPool.test.ts b/apps/desktop/src/backend/DesktopBackendPool.test.ts index fcb1116503..c58371170e 100644 --- a/apps/desktop/src/backend/DesktopBackendPool.test.ts +++ b/apps/desktop/src/backend/DesktopBackendPool.test.ts @@ -73,6 +73,7 @@ function makePoolLayer( revealOrCreateMain: Effect.die("unexpected window reveal"), activate: Effect.die("unexpected window activate"), createMainIfBackendReady: Effect.die("unexpected window create"), + showConnectingSplash: Effect.void, handleBackendReady: () => Effect.void, handleBackendNotReady: Effect.void, dispatchMenuAction: () => Effect.die("unexpected menu action"), diff --git a/apps/desktop/src/window/DesktopApplicationMenu.test.ts b/apps/desktop/src/window/DesktopApplicationMenu.test.ts index cb1db0de73..510804eb5c 100644 --- a/apps/desktop/src/window/DesktopApplicationMenu.test.ts +++ b/apps/desktop/src/window/DesktopApplicationMenu.test.ts @@ -73,6 +73,7 @@ const makeDesktopWindowLayer = (selectedAction: Deferred.Deferred) => revealOrCreateMain: Effect.die("unexpected revealOrCreateMain"), activate: Effect.void, createMainIfBackendReady: Effect.void, + showConnectingSplash: Effect.void, handleBackendReady: () => Effect.void, handleBackendNotReady: Effect.void, dispatchMenuAction: (action) => Deferred.succeed(selectedAction, action).pipe(Effect.asVoid), diff --git a/apps/desktop/src/window/DesktopWindow.ts b/apps/desktop/src/window/DesktopWindow.ts index 812da2482c..13adad2e2f 100644 --- a/apps/desktop/src/window/DesktopWindow.ts +++ b/apps/desktop/src/window/DesktopWindow.ts @@ -10,7 +10,6 @@ import type * as Electron from "electron"; import * as DesktopAssets from "../app/DesktopAssets.ts"; import * as DesktopEnvironment from "../app/DesktopEnvironment.ts"; import * as DesktopObservability from "../app/DesktopObservability.ts"; -import * as DesktopState from "../app/DesktopState.ts"; import * as PreviewManager from "../preview/Manager.ts"; import * as ElectronMenu from "../electron/ElectronMenu.ts"; import * as ElectronShell from "../electron/ElectronShell.ts"; @@ -58,6 +57,10 @@ export interface DesktopWindowShape { readonly revealOrCreateMain: Effect.Effect; readonly activate: Effect.Effect; readonly createMainIfBackendReady: Effect.Effect; + // Show a lightweight "Connecting to WSL" splash window immediately (wsl-only + // mode), before the WSL backend that serves the renderer is ready. It is + // dismissed automatically once the real main window reveals. + readonly showConnectingSplash: Effect.Effect; // The pool tells us not just "primary backend is ready" but also // *where* the renderer should load from. In wsl-only mode that's the // WSL distro IP (e.g. http://172.27.152.141:3773), not the local @@ -107,6 +110,18 @@ function getInitialWindowBackgroundColor(shouldUseDarkColors: boolean): string { return shouldUseDarkColors ? "#0a0a0a" : "#ffffff"; } +// A self-contained "Connecting to WSL" splash, shown immediately in wsl-only +// mode while the WSL backend (which serves the renderer) cold-boots. Inlined as +// a data URL so it needs no bundled asset and no backend — pure CSS, no JS. +function buildConnectingSplashDataUrl(shouldUseDarkColors: boolean): string { + const background = getInitialWindowBackgroundColor(shouldUseDarkColors); + const label = shouldUseDarkColors ? "#9ca3af" : "#6b7280"; + const accent = shouldUseDarkColors ? "#f8fafc" : "#1f2937"; + const track = shouldUseDarkColors ? "rgba(248,250,252,0.18)" : "rgba(31,41,55,0.18)"; + const html = `
Connecting to WSL…
`; + return `data:text/html;charset=utf-8,${encodeURIComponent(html)}`; +} + export function isSameOriginRendererNavigation(input: { readonly applicationUrl: string; readonly navigationUrl: string; @@ -194,9 +209,19 @@ const make = Effect.gen(function* () { // backendConfig because in wsl-only mode the primary doesn't bind on // the local exposure URL — the WSL backend listens on the distro IP. const backendHttpUrlRef = yield* Ref.make>(Option.none()); + // The transient "Connecting to WSL" splash window, tracked separately so it + // is never mistaken for the real main window. + const splashWindowRef = yield* Ref.make>(Option.none()); const context = yield* Effect.context(); const runPromise = Effect.runPromiseWith(context); + const dismissConnectingSplash = Effect.gen(function* () { + const splash = yield* Ref.getAndSet(splashWindowRef, Option.none()); + if (Option.isSome(splash) && !splash.value.isDestroyed()) { + splash.value.close(); + } + }); + const createWindow = Effect.fn("desktop.window.createWindow")(function* ( backendHttpUrl: URL, ): Effect.fn.Return { @@ -348,7 +373,9 @@ const make = Effect.gen(function* () { revealSubscribers.push((fire) => window.webContents.once("did-finish-load", fire)); } bindFirstRevealTrigger(revealSubscribers, () => { - void runPromise(electronWindow.reveal(window)); + // Reveal the real window, then close the connecting splash (if any) so the + // two don't overlap and there's no blank gap between them. + void runPromise(Effect.andThen(electronWindow.reveal(window), dismissConnectingSplash)); }); if (environment.isDevelopment) { @@ -394,10 +421,62 @@ const make = Effect.gen(function* () { const backendReady = yield* Ref.get(backendReadyRef); if (!backendReady) return; const existingWindow = yield* electronWindow.currentMainOrFirst; - if (Option.isSome(existingWindow)) return; + const splash = yield* Ref.get(splashWindowRef); + // currentMainOrFirst falls back to "any first window", which would be the + // connecting splash — ignore it so the real main window still gets created. + const hasRealMainWindow = + Option.isSome(existingWindow) && + !(Option.isSome(splash) && existingWindow.value === splash.value); + if (hasRealMainWindow) return; yield* createMain; }).pipe(Effect.withSpan("desktop.window.createMainIfBackendReady")); + const showConnectingSplash = Effect.gen(function* () { + // Only when nothing is shown yet: no real window, no existing splash. + const existingSplash = yield* Ref.get(splashWindowRef); + if (Option.isSome(existingSplash)) return; + const existingWindow = yield* electronWindow.currentMainOrFirst; + if (Option.isSome(existingWindow)) return; + + const shouldUseDarkColors = yield* electronTheme.shouldUseDarkColors; + const splash = yield* electronWindow.create({ + width: 360, + height: 220, + resizable: false, + minimizable: false, + maximizable: false, + fullscreenable: false, + frame: false, + center: true, + show: false, + skipTaskbar: false, + backgroundColor: getInitialWindowBackgroundColor(shouldUseDarkColors), + title: environment.displayName, + webPreferences: { + contextIsolation: true, + nodeIntegration: false, + sandbox: true, + }, + }); + yield* Ref.set(splashWindowRef, Option.some(splash)); + splash.once("closed", () => { + void runPromise(Ref.set(splashWindowRef, Option.none())); + }); + splash.once("ready-to-show", () => { + if (!splash.isDestroyed()) { + splash.show(); + } + }); + void splash.loadURL(buildConnectingSplashDataUrl(shouldUseDarkColors)); + yield* logWindowInfo("connecting splash shown"); + }).pipe( + // The splash is best-effort UX — never let it fail startup. + Effect.catch((error) => + logWindowWarning("failed to show connecting splash", { message: error.message }), + ), + Effect.withSpan("desktop.window.showConnectingSplash"), + ); + return DesktopWindow.of({ createMain, ensureMain, @@ -411,6 +490,7 @@ const make = Effect.gen(function* () { } }).pipe(Effect.withSpan("desktop.window.activate")), createMainIfBackendReady, + showConnectingSplash, handleBackendReady: Effect.fn("desktop.window.handleBackendReady")(function* (httpBaseUrl) { yield* Ref.set(backendHttpUrlRef, Option.some(httpBaseUrl)); yield* Ref.set(backendReadyRef, true);