Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
fix(desktop): boot the main window unthrottled so cold start paints at full speed (#7460)
Theo Browneefcf7d1ac03e
diff --git a/apps/desktop/src/window/DesktopWindow.test.ts b/apps/desktop/src/window/DesktopWindow.test.tsindex cb7741f11..036eddd8d 100644--- a/apps/desktop/src/window/DesktopWindow.test.ts+++ b/apps/desktop/src/window/DesktopWindow.test.ts@@ -80,6 +80,7 @@ function makeFakeBrowserWindow() {reload: vi.fn(),replaceMisspelling: vi.fn(),send: vi.fn(),+ setBackgroundThrottling: vi.fn(),setWindowOpenHandler: vi.fn(),};@@ -124,6 +125,7 @@ function makeFakeBrowserWindow() {reload: webContents.reload,send: webContents.send,setZoomLevel: webContents.setZoomLevel,+ setBackgroundThrottling: webContents.setBackgroundThrottling,setAutoHideCursor: window.setAutoHideCursor,webContentsListeners,windowListeners,@@ -455,7 +457,7 @@ describe("DesktopWindow", () => {assert.isUndefined(createdWindowOptions[0]?.x);assert.isUndefined(createdWindowOptions[0]?.y);assert.isTrue(createdWindowOptions[0]?.disableAutoHideCursor);- assert.isUndefined(createdWindowOptions[0]?.webPreferences?.backgroundThrottling);+ assert.isFalse(createdWindowOptions[0]?.webPreferences?.backgroundThrottling);assert.deepEqual(fakeWindow.setAutoHideCursor.mock.calls, [[false]]);assert.deepEqual(fakeWindow.loadURL.mock.calls[0], ["t3code-dev://app/"]);assert.equal(fakeWindow.openDevTools.mock.calls.length, 1);@@ -604,6 +606,35 @@ describe("DesktopWindow", () => {}),);+ // The window boots hidden with throttling disabled so first paint runs at+ // full speed; the first reveal must hand it back to normal hidden-window+ // throttling or a minimized window stays expensive forever.+ it.effect("re-enables background throttling on first reveal", () =>+ Effect.gen(function* () {+ const fakeWindow = makeFakeBrowserWindow();+ const createCount = yield* Ref.make(0);+ const mainWindow = yield* Ref.make<Option.Option<Electron.BrowserWindow>>(Option.none());+ const layer = makeTestLayer({+ window: fakeWindow.window,+ createCount,+ mainWindow,+ });++ yield* Effect.gen(function* () {+ const desktopWindow = yield* DesktopWindow.DesktopWindow;+ yield* desktopWindow.handleBackendReady(new URL("http://127.0.0.1:3773"));++ assert.equal(fakeWindow.setBackgroundThrottling.mock.calls.length, 0);+ const readyToShow = fakeWindow.windowListeners.get("ready-to-show");+ if (!readyToShow) {+ return yield* Effect.die("window ready-to-show listener was not registered");+ }+ readyToShow();+ assert.deepEqual(fakeWindow.setBackgroundThrottling.mock.calls, [[true]]);+ }).pipe(Effect.provide(layer));+ }),+ );+it.effect("debounces move and resize bounds updates", () =>Effect.gen(function* () {const fakeWindow = makeFakeBrowserWindow();diff --git a/apps/desktop/src/window/DesktopWindow.ts b/apps/desktop/src/window/DesktopWindow.tsindex 9954875f8..56411711e 100644--- a/apps/desktop/src/window/DesktopWindow.ts+++ b/apps/desktop/src/window/DesktopWindow.ts@@ -359,6 +359,12 @@ export const make = Effect.gen(function* () {...getWindowTitleBarOptions(shouldUseDarkColors, environment.platform),webPreferences: {preload: environment.preloadPath,+ // The window boots hidden (show: false until ready-to-show), and+ // Chromium throttles hidden renderers: timers coalesce and rAF stops,+ // which stalls first paint. Boot unthrottled; the first-reveal trigger+ // re-enables throttling so a hidden or minimized window goes back to+ // being cheap after it has been shown once.+ backgroundThrottling: false,contextIsolation: true,nodeIntegration: false,sandbox: true,@@ -725,6 +731,11 @@ export const make = Effect.gen(function* () {revealSubscribers.push((fire) => window.webContents.once("did-finish-load", fire));}bindFirstRevealTrigger(revealSubscribers, () => {+ // Boot is done; hand the window back to normal hidden-window throttling+ // (see the backgroundThrottling comment on the create options above).+ if (!window.isDestroyed()) {+ window.webContents.setBackgroundThrottling(true);+ }// 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.if (persistedSettings.mainWindowMaximized) {