| @@ -80,6 +80,7 @@ function makeFakeBrowserWindow() { · 79 unmodified lines |
| 80 | 80 | reload: vi.fn(), |
| 81 | 81 | replaceMisspelling: vi.fn(), |
| 82 | 82 | send: vi.fn(), |
| 83 | + setBackgroundThrottling: vi.fn(), |
| 83 | 84 | setWindowOpenHandler: vi.fn(), |
| 84 | 85 | }; |
| 85 | 86 | |
| @@ -124,6 +125,7 @@ function makeFakeBrowserWindow() { · 38 unmodified lines |
| 124 | 125 | reload: webContents.reload, |
| 125 | 126 | send: webContents.send, |
| 126 | 127 | setZoomLevel: webContents.setZoomLevel, |
| 128 | + setBackgroundThrottling: webContents.setBackgroundThrottling, |
| 127 | 129 | setAutoHideCursor: window.setAutoHideCursor, |
| 128 | 130 | webContentsListeners, |
| 129 | 131 | windowListeners, |
| @@ -455,7 +457,7 @@ describe("DesktopWindow", () => { · 325 unmodified lines |
| 455 | 457 | assert.isUndefined(createdWindowOptions[0]?.x); |
| 456 | 458 | assert.isUndefined(createdWindowOptions[0]?.y); |
| 457 | 459 | assert.isTrue(createdWindowOptions[0]?.disableAutoHideCursor); |
| 458 | | − assert.isUndefined(createdWindowOptions[0]?.webPreferences?.backgroundThrottling); |
| 460 | + assert.isFalse(createdWindowOptions[0]?.webPreferences?.backgroundThrottling); |
| 459 | 461 | assert.deepEqual(fakeWindow.setAutoHideCursor.mock.calls, [[false]]); |
| 460 | 462 | assert.deepEqual(fakeWindow.loadURL.mock.calls[0], ["t3code-dev://app/"]); |
| 461 | 463 | assert.equal(fakeWindow.openDevTools.mock.calls.length, 1); |
| @@ -604,6 +606,35 @@ describe("DesktopWindow", () => { · 142 unmodified lines |
| 604 | 606 | }), |
| 605 | 607 | ); |
| 606 | 608 | |
| 609 | + // The window boots hidden with throttling disabled so first paint runs at |
| 610 | + // full speed; the first reveal must hand it back to normal hidden-window |
| 611 | + // throttling or a minimized window stays expensive forever. |
| 612 | + it.effect("re-enables background throttling on first reveal", () => |
| 613 | + Effect.gen(function* () { |
| 614 | + const fakeWindow = makeFakeBrowserWindow(); |
| 615 | + const createCount = yield* Ref.make(0); |
| 616 | + const mainWindow = yield* Ref.make<Option.Option<Electron.BrowserWindow>>(Option.none()); |
| 617 | + const layer = makeTestLayer({ |
| 618 | + window: fakeWindow.window, |
| 619 | + createCount, |
| 620 | + mainWindow, |
| 621 | + }); |
| 622 | + |
| 623 | + yield* Effect.gen(function* () { |
| 624 | + const desktopWindow = yield* DesktopWindow.DesktopWindow; |
| 625 | + yield* desktopWindow.handleBackendReady(new URL("http://127.0.0.1:3773")); |
| 626 | + |
| 627 | + assert.equal(fakeWindow.setBackgroundThrottling.mock.calls.length, 0); |
| 628 | + const readyToShow = fakeWindow.windowListeners.get("ready-to-show"); |
| 629 | + if (!readyToShow) { |
| 630 | + return yield* Effect.die("window ready-to-show listener was not registered"); |
| 631 | + } |
| 632 | + readyToShow(); |
| 633 | + assert.deepEqual(fakeWindow.setBackgroundThrottling.mock.calls, [[true]]); |
| 634 | + }).pipe(Effect.provide(layer)); |
| 635 | + }), |
| 636 | + ); |
| 637 | + |
| 607 | 638 | it.effect("debounces move and resize bounds updates", () => |
| 608 | 639 | Effect.gen(function* () { |
| 609 | 640 | const fakeWindow = makeFakeBrowserWindow(); |