Skip to content

Commit 771acda

Browse files
committed
perf(desktop): show connecting splash while the local backend starts
On Windows (and macOS/Linux) the main window is only created once the primary backend reports ready, and the connecting splash was only shown for wsl-only mode. Every other launch showed no window at all for the 1-3s the backend takes to boot. Show the existing connecting splash before the primary backend starts on every platform. It is replaced when the main window's first reveal fires (the same path as before) and closed with the app if startup fails. The label now names the backend being waited on: "Connecting to WSL" only in wsl-only mode, "Starting T3 Code" otherwise. Model: Claude Haiku 5.5 via pi (T3 Code)
1 parent ec1313c commit 771acda

3 files changed

Lines changed: 75 additions & 20 deletions

File tree

‎apps/desktop/src/app/DesktopApp.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,10 @@ const bootstrap = Effect.gen(function* () {
243243
}
244244

245245
if (!(yield* Ref.get(state.quitting))) {
246-
// The main window waits for the primary backend. In wsl-only mode that is
247-
// the WSL backend, which can be slow to cold-boot — show a "Connecting to
248-
// WSL" splash immediately so the app feels responsive instead of presenting
249-
// no window until WSL is ready. (Dual mode opens fast off the Windows
250-
// primary, so no splash there.)
251-
if (settings.wslOnly === true && settings.wslBackendEnabled === true) {
252-
yield* desktopWindow.showConnectingSplash;
253-
}
246+
// The main window waits for the primary backend, which takes a moment to
247+
// boot on every platform. Show the connecting splash first so the app is
248+
// visibly starting instead of presenting no window until the backend is ready.
249+
yield* desktopWindow.showConnectingSplash;
254250
yield* primaryBackend.start;
255251
yield* logBootstrapInfo("bootstrap backend start requested");
256252
yield* appActivation.start.pipe(

‎apps/desktop/src/window/DesktopWindow.test.ts‎

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function makeFakeBrowserWindow() {
109109
isMaximized: vi.fn(() => false),
110110
isMinimized: vi.fn(() => false),
111111
isVisible: vi.fn(() => true),
112-
loadURL: vi.fn(() => Promise.resolve()),
112+
loadURL: vi.fn((_url: string) => Promise.resolve()),
113113
maximize: vi.fn(),
114114
on: vi.fn((eventName: string, listener: (...args: readonly unknown[]) => void) => {
115115
windowListeners.set(eventName, listener);
@@ -137,6 +137,7 @@ function makeFakeBrowserWindow() {
137137
isFullScreen: window.isFullScreen,
138138
isMaximized: window.isMaximized,
139139
isMinimized: window.isMinimized,
140+
close: window.close,
140141
loadURL: window.loadURL,
141142
maximize: window.maximize,
142143
openDevTools: webContents.openDevTools,
@@ -352,7 +353,10 @@ function layerTest(input: {
352353
// currentMainOrFirst mirrors the real fallback to the first live window (the
353354
// splash, before any main is registered). Reveal targets are recorded so tests
354355
// can assert what activation actually surfaced.
355-
const makeSplashScenario = (createOutcomes: readonly (Electron.BrowserWindow | null)[]) =>
356+
const makeSplashScenario = (
357+
createOutcomes: readonly (Electron.BrowserWindow | null)[],
358+
settings: DesktopAppSettings.DesktopSettings = DesktopAppSettings.DEFAULT_DESKTOP_SETTINGS,
359+
) =>
356360
Effect.gen(function* () {
357361
const createdWindows = yield* Ref.make<Electron.BrowserWindow[]>([]);
358362
const createCalls = yield* Ref.make(0);
@@ -427,7 +431,7 @@ const makeSplashScenario = (createOutcomes: readonly (Electron.BrowserWindow | n
427431
shutdown: Effect.void,
428432
}),
429433
layerDesktopEnvironment,
430-
DesktopAppSettings.layerTest(),
434+
DesktopAppSettings.layerTest(settings),
431435
layerDesktopClientSettings,
432436
layerDesktopServerExposure,
433437
layerElectronApp,
@@ -1494,6 +1498,56 @@ describe("DesktopWindow", () => {
14941498
}),
14951499
);
14961500

1501+
it.effect("closes the connecting splash once the real main window reveals", () =>
1502+
Effect.gen(function* () {
1503+
const splash = makeFakeBrowserWindow();
1504+
const main = makeFakeBrowserWindow();
1505+
const scenario = yield* makeSplashScenario([splash.window, main.window]);
1506+
1507+
yield* Effect.gen(function* () {
1508+
const desktopWindow = yield* DesktopWindow.DesktopWindow;
1509+
yield* desktopWindow.showConnectingSplash;
1510+
yield* desktopWindow.handleBackendReady(new URL("http://127.0.0.1:3773"));
1511+
1512+
assert.equal(splash.close.mock.calls.length, 0);
1513+
const readyToShow = main.windowListeners.get("ready-to-show");
1514+
if (!readyToShow) {
1515+
return yield* Effect.die("main ready-to-show listener was not registered");
1516+
}
1517+
readyToShow();
1518+
assert.equal(splash.close.mock.calls.length, 1);
1519+
}).pipe(Effect.provide(scenario.layer));
1520+
}),
1521+
);
1522+
1523+
it.effect("labels the connecting splash for the backend it is waiting on", () =>
1524+
Effect.gen(function* () {
1525+
const primarySplash = makeFakeBrowserWindow();
1526+
const primaryScenario = yield* makeSplashScenario([primarySplash.window]);
1527+
yield* Effect.gen(function* () {
1528+
const desktopWindow = yield* DesktopWindow.DesktopWindow;
1529+
yield* desktopWindow.showConnectingSplash;
1530+
}).pipe(Effect.provide(primaryScenario.layer));
1531+
1532+
const wslSplash = makeFakeBrowserWindow();
1533+
const wslScenario = yield* makeSplashScenario([wslSplash.window], {
1534+
...DesktopAppSettings.DEFAULT_DESKTOP_SETTINGS,
1535+
wslOnly: true,
1536+
wslBackendEnabled: true,
1537+
});
1538+
yield* Effect.gen(function* () {
1539+
const desktopWindow = yield* DesktopWindow.DesktopWindow;
1540+
yield* desktopWindow.showConnectingSplash;
1541+
}).pipe(Effect.provide(wslScenario.layer));
1542+
1543+
const splashText = (splash: ReturnType<typeof makeFakeBrowserWindow>) =>
1544+
decodeURIComponent(splash.loadURL.mock.calls[0]?.[0] ?? "");
1545+
assert.include(splashText(primarySplash), "Starting T3 Code…");
1546+
assert.notInclude(splashText(primarySplash), "WSL");
1547+
assert.include(splashText(wslSplash), "Connecting to WSL…");
1548+
}),
1549+
);
1550+
14971551
it.effect(
14981552
"re-reveals the connecting splash on activate while the backend is still cold-booting",
14991553
() =>

‎apps/desktop/src/window/DesktopWindow.ts‎

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ export class DesktopWindow extends Context.Service<
106106
readonly revealOrCreateMain: Effect.Effect<Electron.BrowserWindow, DesktopWindowError>;
107107
readonly activate: Effect.Effect<void, DesktopWindowError>;
108108
readonly createMainIfBackendReady: Effect.Effect<void, DesktopWindowError>;
109-
// Show a lightweight "Connecting to WSL" splash window immediately (wsl-only
110-
// mode), before the WSL backend that acts as the primary is ready. It is
111-
// dismissed automatically once the real main window reveals.
109+
// Show a lightweight connecting splash window immediately, before the primary
110+
// backend is ready. It is dismissed automatically once the real main window reveals.
112111
readonly showConnectingSplash: Effect.Effect<void>;
113112
// Marks the primary backend as ready so `createMainIfBackendReady` and the
114113
// macOS "activate without windows" path may open the real main window. The
@@ -207,15 +206,14 @@ export function resolveInitialMainWindowBounds(
207206
return DesktopAppSettings.DEFAULT_MAIN_WINDOW_SIZE;
208207
}
209208

210-
// A self-contained "Connecting to WSL" splash, shown immediately in wsl-only
211-
// mode while the WSL backend (which serves the renderer) cold-boots. Inlined as
212-
// a data URL so it needs no bundled asset and no backend — pure CSS, no JS.
213-
function buildConnectingSplashDataUrl(shouldUseDarkColors: boolean): string {
209+
// A self-contained connecting splash, shown immediately while the primary backend
210+
// boots. Inlined as a data URL so it needs no bundled asset and no backend — pure CSS, no JS.
211+
function buildConnectingSplashDataUrl(shouldUseDarkColors: boolean, text: string): string {
214212
const background = getInitialWindowBackgroundColor(shouldUseDarkColors);
215213
const label = shouldUseDarkColors ? "#9ca3af" : "#6b7280";
216214
const accent = shouldUseDarkColors ? "#f8fafc" : "#1f2937";
217215
const track = shouldUseDarkColors ? "rgba(248,250,252,0.18)" : "rgba(31,41,55,0.18)";
218-
const html = `<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'"><style>html,body{margin:0;height:100%}body{background:${background};color:${label};font-family:system-ui,-apple-system,'Segoe UI',sans-serif;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;-webkit-user-select:none;user-select:none;-webkit-app-region:drag}.spinner{width:26px;height:26px;border:3px solid ${track};border-top-color:${accent};border-radius:50%;animation:spin .8s linear infinite}.label{font-size:13px}@keyframes spin{to{transform:rotate(360deg)}}</style></head><body><div class="spinner"></div><div class="label">Connecting to WSL…</div></body></html>`;
216+
const html = `<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'unsafe-inline'"><style>html,body{margin:0;height:100%}body{background:${background};color:${label};font-family:system-ui,-apple-system,'Segoe UI',sans-serif;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;-webkit-user-select:none;user-select:none;-webkit-app-region:drag}.spinner{width:26px;height:26px;border:3px solid ${track};border-top-color:${accent};border-radius:50%;animation:spin .8s linear infinite}.label{font-size:13px}@keyframes spin{to{transform:rotate(360deg)}}</style></head><body><div class="spinner"></div><div class="label">${text}</div></body></html>`;
219217
return `data:text/html;charset=utf-8,${encodeURIComponent(html)}`;
220218
}
221219

@@ -914,6 +912,13 @@ export const make = Effect.gen(function* () {
914912
if (Option.isSome(existingWindow)) return;
915913

916914
const shouldUseDarkColors = yield* electronTheme.shouldUseDarkColors;
915+
const settings = yield* desktopSettings.get;
916+
// Name the backend the user is actually waiting on: the WSL backend is the
917+
// primary only in wsl-only mode.
918+
const label =
919+
settings.wslOnly === true && settings.wslBackendEnabled === true
920+
? "Connecting to WSL…"
921+
: "Starting T3 Code…";
917922
const splash = yield* electronWindow.create({
918923
width: 360,
919924
height: 220,
@@ -943,7 +948,7 @@ export const make = Effect.gen(function* () {
943948
splash.show();
944949
}
945950
});
946-
void splash.loadURL(buildConnectingSplashDataUrl(shouldUseDarkColors));
951+
void splash.loadURL(buildConnectingSplashDataUrl(shouldUseDarkColors, label));
947952
yield* logWindowInfo("connecting splash shown");
948953
}).pipe(
949954
// The splash is best-effort UX — never let it fail startup.

0 commit comments

Comments
 (0)