Skip to content

Commit ae45ccd

Browse files
Batuhan1999claude
andauthored
fix(desktop): a stalled capture no longer freezes picture-in-picture (#24057)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent fb412b6 commit ae45ccd

2 files changed

Lines changed: 49 additions & 7 deletions

File tree

‎apps/desktop/src/preview/Manager.test.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,48 @@ describe("PreviewManager", () => {
22012201
),
22022202
);
22032203

2204+
effectIt.effect("shows picture-in-picture and keeps capturing after stalled captures", () =>
2205+
withManager((manager) =>
2206+
Effect.gen(function* () {
2207+
const image = {
2208+
toJPEG: () => Buffer.from("preview-frame"),
2209+
getSize: () => ({ width: 1280, height: 720 }),
2210+
};
2211+
const stalledInitial = Promise.withResolvers<typeof image>();
2212+
const stalledLoop = Promise.withResolvers<typeof image>();
2213+
const capturePage = vi
2214+
.fn<() => Promise<typeof image>>()
2215+
.mockImplementationOnce(() => stalledInitial.promise)
2216+
.mockImplementationOnce(() => stalledLoop.promise)
2217+
.mockResolvedValue(image);
2218+
fromId.mockReturnValue(makeTestPreviewWebContents(capturePage));
2219+
const { pictureInPictureWindow, send } = makeTestPictureInPictureWindow();
2220+
browserWindowConstructor.mockImplementation(function () {
2221+
return pictureInPictureWindow;
2222+
});
2223+
yield* manager.createTab("tab_pip_stalled_capture");
2224+
yield* manager.registerWebview("tab_pip_stalled_capture", 42);
2225+
2226+
try {
2227+
const open = yield* manager
2228+
.openPictureInPicture("tab_pip_stalled_capture")
2229+
.pipe(Effect.forkChild({ startImmediately: true }));
2230+
yield* TestClock.adjust(1_000);
2231+
expect(pictureInPictureWindow.showInactive).toHaveBeenCalledOnce();
2232+
yield* Fiber.join(open);
2233+
2234+
expect(send).not.toHaveBeenCalled();
2235+
yield* TestClock.adjust(500);
2236+
expect(send).toHaveBeenCalled();
2237+
} finally {
2238+
// Release stalled native calls after a failing assertion against unchanged base.
2239+
stalledInitial.resolve(image);
2240+
stalledLoop.resolve(image);
2241+
}
2242+
}),
2243+
),
2244+
);
2245+
22042246
effectIt.effect("rejects picture-in-picture when its webview changes during initialization", () =>
22052247
withManager((manager) =>
22062248
Effect.gen(function* () {

‎apps/desktop/src/preview/Manager.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2426,13 +2426,13 @@ const makeNativeOperations = Effect.fn("PreviewManager.makeOperations")(function
24262426
if (!captureSession?.consumers.has("picture-in-picture") || captureSession.scope === null)
24272427
return;
24282428
const wc = yield* requireWebContents(tabId);
2429-
const image = yield* attemptPromise(
2430-
{
2431-
operation: "frameCapture.capturePage",
2432-
tabId,
2433-
webContentsId: wc.id,
2434-
},
2435-
() => wc.capturePage(),
2429+
const captureContext = { operation: "frameCapture.capturePage", tabId, webContentsId: wc.id };
2430+
const image = yield* attemptPromise(captureContext, () => wc.capturePage()).pipe(
2431+
Effect.timeout(CAPTURE_PAGE_ATTEMPT_TIMEOUT_MS),
2432+
Effect.catchTags({
2433+
TimeoutError: (cause) =>
2434+
Effect.fail(new PreviewOperationError({ ...captureContext, cause })),
2435+
}),
24362436
);
24372437
const currentCaptureSession = yield* Effect.all(
24382438
[SynchronizedRef.get(frameCaptureSessionsRef), SynchronizedRef.get(tabsRef)],

0 commit comments

Comments
 (0)