@devries-cameron20 / t3code Mirror · read-only / commits / 3925267688
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

fix(desktop): a phone can watch an agent's hidden browser tab while Windows is locked (#39198)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Nov 21, 2026 at 01:56 UTC 392526768806ab7b36854ad9a401955c4bec6a85
2 files changed +42 -3
apps/desktop/src/preview/Manager.test.ts
+21 -3
@@ -2415,10 +2415,18 @@ describe("PreviewManager", () => {
2415 Effect.gen(function* () {
2416 const host = yield* DesktopBrowserHost.DesktopBrowserHost;
2417 const serverTab = { threadId: "thread-1", tabId: "server-tab-1" };
2418 + const windowThrottling = vi.fn<(enabled: boolean) => void>();
2419 + const mainWebContents = Object.assign(makeTestHostWebContents(), {
2420 + setBackgroundThrottling: windowThrottling,
2421 + });
2422 const contents = Object.assign(
2419 - makeTestPreviewWebContents(async () => {
2420 - throw new Error("unused");
2421 - }, 42),
2423 + makeTestPreviewWebContents(
2424 + async () => {
2425 + throw new Error("unused");
2426 + },
2427 + 42,
2428 + mainWebContents,
2429 + ),
2430 {
2431 isDevToolsOpened: () => false,
2432 getUserAgent: () => "Electron",
@@ -2431,6 +2439,11 @@ describe("PreviewManager", () => {
2439 ) as unknown as typeof contents.debugger.sendCommand;
2440 fromId.mockReturnValue(contents);
2441 const manager = yield* PreviewManager.PreviewManager;
2442 + yield* manager.setMainWindow({
2443 + isDestroyed: () => false,
2444 + once: vi.fn(),
2445 + webContents: mainWebContents,
2446 + } as never);
2447 const capturing = yield* Queue.unbounded<boolean>();
2448 yield* manager.subscribeStateChanges((_tabId, state) =>
2449 Queue.offer(capturing, state.capturing).pipe(Effect.asVoid),
@@ -2463,9 +2476,14 @@ describe("PreviewManager", () => {
2476 }),
2477 );
2478 expect(yield* Queue.take(capturing)).toBe(true);
2479 + // A locked or covered window paints a guest it had hidden only while unthrottled.
2480 + expect(windowThrottling.mock.calls).toEqual([[false]]);
2481 + expect(contents.setBackgroundThrottling.mock.calls).toEqual([[false]]);
2482 yield* manager.setCaptureDrawn("tab_1", true);
2483 screenshot.resolve({ data: "" });
2484 expect(yield* Queue.take(capturing)).toBe(false);
2485 + expect(windowThrottling.mock.calls).toEqual([[false], [true]]);
2486 + expect(contents.setBackgroundThrottling.mock.calls).toEqual([[false], [true]]);
2487 }).pipe(Effect.provide(managerLayer())),
2488 );
2489
apps/desktop/src/preview/Manager.ts
+21
@@ -3623,6 +3623,8 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
3623 { discard: true },
3624 );
3625 });
3626 + // A hidden or locked window draws no frames, so a guest it hid stays unpainted until unthrottled.
3627 + const serverCaptureLeases = new Map<string, { readonly tabId: string; readonly lease: symbol }>();
3628 const updateServerTabCapturing = Effect.fn("PreviewManager.updateServerTabCapturing")(
3629 function* (painting: {
3630 readonly key: { readonly threadId: string; readonly tabId: string };
@@ -3633,6 +3635,25 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
3635 candidate.serverTab?.threadId === painting.key.threadId &&
3636 candidate.serverTab.tabId === painting.key.tabId,
3637 );
3638 + const key = `${painting.key.threadId}\u0000${painting.key.tabId}`;
3639 + const held = serverCaptureLeases.get(key);
3640 + if (!painting.active && held) {
3641 + serverCaptureLeases.delete(key);
3642 + yield* stopFrameCapture(held.tabId, held.lease);
3643 + } else if (painting.active && !held && tab) {
3644 + const lease = Symbol("server-capture");
3645 + yield* startFrameCapture(tab.tabId, lease).pipe(
3646 + Effect.andThen(
3647 + Effect.sync(() => serverCaptureLeases.set(key, { tabId: tab.tabId, lease })),
3648 + ),
3649 + Effect.catch((error) =>
3650 + Effect.logWarning("Failed to unthrottle a server tab for its capture.", {
3651 + tabId: tab.tabId,
3652 + error,
3653 + }),
3654 + ),
3655 + );
3656 + }
3657 if (tab && tab.capturing !== painting.active) {
3658 yield* update(tab.tabId, { capturing: painting.active });
3659 }