Add background preview capture and picture-in-picture support #4397
Mergedjuliusmarmingemerged 32 commits into
main fromrefs/pull/4397/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -1750,0 +1833,21 @@1833+ if (pictureInPictureWindow && !pictureInPictureWindow.isDestroyed()) {1834+ deliveries.push(1835+ Effect.gen(function* () {1836+ const previousAspectRatio = (yield* Ref.get(pictureInPictureAspectRatiosRef)).get(1837+ tabId,1838+ );1839+ const aspectRatio = frame.width / frame.height;1840+ if (previousAspectRatio !== aspectRatio) {1841+ yield* attempt(1842+ {1843+ operation: "pictureInPicture.setAspectRatio",1844+ tabId,1845+ webContentsId: wc.id,1846+ },1847+ () => pictureInPictureWindow.setAspectRatio(aspectRatio),1848+ );1849+ yield* Ref.update(pictureInPictureAspectRatiosRef, (aspectRatios) =>1850+ replaceMap(aspectRatios, (copy) => {1851+ copy.set(tabId, aspectRatio);1852+ }),1853+ );apps/desktop/src/preview/Manager.ts line 2439OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1773,0 +2061,21 @@2061+ {2062+ operation: "pictureInPicture.load",2063+ tabId,2064+ webContentsId: wc.id,2065+ },2066+ () => pictureInPictureWindow.loadURL(buildPreviewPictureInPictureDataUrl()),2067+ );2068+ yield* startFrameCapture(tabId, "picture-in-picture");2069+ yield* attempt(2070+ {2071+ operation: "pictureInPicture.show",2072+ tabId,2073+ webContentsId: wc.id,2074+ },2075+ () => pictureInPictureWindow.showInactive(),2076+ );2077+ yield* update(tabId, { pictureInPicture: true });2078+ });2079+ yield* initialize.pipe(2080+ Effect.onError(() => releasePictureInPicture(tabId, pictureInPictureWindow, true)),2081+ );apps/desktop/src/preview/Manager.ts line 2368OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1771,0 +2037,21 @@2037+ operation: "pictureInPicture.configure",2038+ tabId,2039+ webContentsId: wc.id,2040+ },2041+ () => {2042+ pictureInPictureWindow.once("closed", onClosed);2043+ pictureInPictureWindow.setAlwaysOnTop(2044+ true,2045+ hostPlatform === "darwin" ? "floating" : "normal",2046+ );2047+ if (hostPlatform === "darwin") {2048+ pictureInPictureWindow.setVisibleOnAllWorkspaces(true, {2049+ visibleOnFullScreen: true,2050+ });2051+ }2052+ },2053+ );2054+ yield* SynchronizedRef.update(pictureInPictureWindowsRef, (windows) =>2055+ replaceMap(windows, (copy) => {2056+ copy.set(tabId, pictureInPictureWindow);2057+ }),apps/web/src/browser/HostedBrowserWebview.tsx line 66Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -59,8 +57,3 @@5957 );6058 usePreviewBridge({ threadRef, tabId });615962- useEffect(() => {63- if (presentation.visible || activeRecordingTabId !== tabId) return;64- void stopBrowserRecording(tabId).catch(() => undefined);65- }, [activeRecordingTabId, presentation.visible, tabId]);66-
- apps/web/src/browser/desktopTabLifetime.ts line 13OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -8,3 +10,4 @@810911 const leases = new Map<string, DesktopTabLease>();101213+const closeReleasedDesktopTab = async (tabId: string): Promise<void> => {
- apps/web/src/browser/desktopTabLifetime.ts line 31Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -8,3 +10,8 @@810911 const leases = new Map<string, DesktopTabLease>();101213+const closeReleasedDesktopTab = async (tabId: string): Promise<void> => {14+ await stopBrowserRecording(tabId).catch(() => null);15+ if (leases.has(tabId)) return;16+ await previewBridge?.closeTab(tabId);17+};@@ -1827,0 +2155,21 @@2155+ yield* startFrameCapture(tabId, "picture-in-picture");2156+ yield* attempt(2157+ {2158+ operation: "pictureInPicture.show",2159+ tabId,2160+ webContentsId: wc.id,2161+ },2162+ () => pictureInPictureWindow.showInactive(),2163+ );2164+ yield* update(tabId, { pictureInPicture: true });2165+ });2166+ yield* initialize.pipe(2167+ Effect.onError(() => releasePictureInPicture(tabId, pictureInPictureWindow, true)),2168+ );2169+ },2170+ );2171+2172+ const openPictureInPicture = Effect.fn("PreviewManager.openPictureInPicture")(function* (2173+ tabId: string,2174+ ) {2175+ yield* pictureInPictureMutationSemaphore.withPermit(openPictureInPictureUnlocked(tabId));
- @@ -1833,3 +2077,19 @@2077+ );2078+2079+ const openPictureInPicture = Effect.fn("PreviewManager.openPictureInPicture")(function* (2080+ tabId: string,2081+ ) {18332082 const wc = yield* requireWebContents(tabId);1834- yield* withControlSession(tabId, wc, "recording.stop", (send) =>1835- send("Page.stopScreencast").pipe(Effect.asVoid),2083+ const pictureInPictureSession = yield* pictureInPictureMutationSemaphore.withPermit(2084+ Effect.gen(function* () {2085+ const existing = (yield* SynchronizedRef.get(pictureInPictureSessionsRef)).get(tabId);2086+ if (existing && !existing.window.isDestroyed()) {2087+ yield* attempt({ operation: "pictureInPicture.showExisting", tabId }, () =>2088+ existing.window.showInactive(),2089+ );2090+ return null;2091+ }2092+ if (existing) {2093+ yield* releasePictureInPicture(tabId, existing, false);2094+ }2095+ const title = wc.getTitle().trim();@@ -1833,3 +2072,19 @@2072+ yield* Effect.forEach(sessions.keys(), closePictureInPicture, {2073+ concurrency: "unbounded",2074+ discard: true,2075+ });2076+ },2077+ );2078+2079+ const openPictureInPicture = Effect.fn("PreviewManager.openPictureInPicture")(function* (2080+ tabId: string,2081+ ) {18332082 const wc = yield* requireWebContents(tabId);1834- yield* withControlSession(tabId, wc, "recording.stop", (send) =>1835- send("Page.stopScreencast").pipe(Effect.asVoid),2083+ const pictureInPictureSession = yield* pictureInPictureMutationSemaphore.withPermit(2084+ Effect.gen(function* () {2085+ const existing = (yield* SynchronizedRef.get(pictureInPictureSessionsRef)).get(tabId);2086+ if (existing && !existing.window.isDestroyed()) {2087+ yield* attempt({ operation: "pictureInPicture.showExisting", tabId }, () =>2088+ existing.window.showInactive(),2089+ );2090+ return null;
- @@ -1827,0 +2241,21 @@2241+ tabId,2242+ webContentsId: pictureInPictureSession.webContentsId,2243+ },2244+ () => pictureInPictureSession.window.showInactive(),2245+ );2246+ yield* update(tabId, { pictureInPicture: true });2247+ });2248+ const initializationExit = yield* Effect.gen(function* () {2249+ const initializationFiber = yield* Effect.forkIn(2250+ initialize,2251+ pictureInPictureSession.initializationScope,2252+ );2253+ return yield* Fiber.await(initializationFiber);2254+ }).pipe(2255+ Effect.onInterrupt(() =>2256+ pictureInPictureMutationSemaphore.withPermit(2257+ releasePictureInPicture(tabId, pictureInPictureSession, true),2258+ ),2259+ ),2260+ );2261+ yield* Deferred.done(pictureInPictureSession.ready, initializationExit);
- @@ -1308,4 +1351,14 @@13081351 const closeTab = Effect.fn("PreviewManager.closeTab")(function* (tabId: string) {13091352 const tab = (yield* SynchronizedRef.get(tabsRef)).get(tabId);13101353 if (!tab) return;1311- yield* cancelPickElement(tabId);1354+ yield* Effect.all(1355+ [1356+ cancelPickElement(tabId),1357+ closePictureInPicture(tabId),1358+ stopFrameCapture(tabId, "recording"),1359+ ],1360+ {1361+ concurrency: 3,1362+ discard: true,1363+ },1364+ );@@ -1814 +1984,21 @@1984+ consumers: new Set([...current.consumers, consumer]),1985+ });1986+ }),1987+ ] as const);1988+ }1989+ return Effect.gen(function* () {1990+ const scope = yield* Scope.fork(parentScope, "sequential");1991+ return [1992+ true,1993+ replaceMap(sessions, (copy) => {1994+ copy.set(tabId, {1995+ scope,1996+ consumers: new Set([consumer]),1997+ });1998+ }),1999+ ] as const;2000+ });18142001 });2002+ if (!created) return;2003+ const session = (yield* SynchronizedRef.get(frameCaptureSessionsRef)).get(tabId);2004+ if (!session) return;@@ -198,10 +190,10 @@198190 export async function startBrowserRecording(tabId: string): Promise<string> {199191 const bridge = previewBridge;200192 if (!bridge) throw new BrowserRecordingUnavailableError({ tabId });201- if (active) {202- if (active.tabId === tabId && active.lifecycle.phase === "recording") {203- return active.startedAt;193+ const activeRecording = activeRecordings.get(tabId);194+ if (activeRecording) {195+ if (activeRecording.lifecycle.phase === "recording") {196+ return activeRecording.startedAt;204197 }205198 throw new BrowserRecordingConflictError({206199 requestedTabId: tabId,207- activeTabId: active.tabId,
- apps/web/src/browser/browserRecording.ts line 163Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -130,7 +118,18 @@130- if (!recording || recording.tabId !== frame.tabId) return;118+ const recording = activeRecordings.get(frame.tabId);119+ if (!recording) return;120+ if (121+ !Number.isFinite(frame.width) ||122+ !Number.isFinite(frame.height) ||123+ frame.width <= 0 ||124+ frame.height <= 0125+ ) {126+ return;127+ }128+ const width = Math.max(1, Math.round(frame.width));129+ const height = Math.max(1, Math.round(frame.height));130+ const frameSequence = ++recording.frameSequence;131131 const image = new Image();132132 image.addEventListener(133133 "load",134134 () => {135- if (active !== recording) return;136- recording.context.drawImage(image, 0, 0, recording.canvas.width, recording.canvas.height);135+ if (
- @@ -131,6 +125,19 @@125+ ) {126+ return;127+ }128+ const width = Math.max(1, Math.round(frame.width));129+ const height = Math.max(1, Math.round(frame.height));130+ const frameSequence = ++recording.frameSequence;131131 const image = new Image();132132 image.addEventListener(133133 "load",134134 () => {135- if (active !== recording) return;136- recording.context.drawImage(image, 0, 0, recording.canvas.width, recording.canvas.height);135+ if (136+ activeRecordings.get(frame.tabId) !== recording ||137+ recording.frameSequence !== frameSequence138+ ) {139+ return;140+ }141+ if (recording.canvas.width !== width) recording.canvas.width = width;142+ if (recording.canvas.height !== height) recording.canvas.height = height;143+ recording.context.drawImage(image, 0, 0, width, height);
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- @@ -168,4 +223,17 @@168223 });169224170225 const isRecordingStarting = (recording: ActiveRecording): boolean =>171- active === recording && recording.lifecycle.phase === "starting";226+ activeRecordings.get(recording.tabId) === recording && recording.lifecycle.phase === "starting";227+228+const waitForFirstFrameSize = async (recording: ActiveRecording): Promise<void> => {229+ if (recording.frameSizeEstablished) return;230+ let timeout: ReturnType<typeof setTimeout> | null = null;231+ await Promise.race([232+ recording.firstFrameSize,233+ new Promise<void>((resolve) => {234+ timeout = setTimeout(resolve, BROWSER_RECORDING_FIRST_FRAME_SIZE_TIMEOUT_MS);235+ }),236+ ]);237+ if (timeout !== null) clearTimeout(timeout);238+ recording.frameSizeEstablished = true;239+};
- apps/web/src/components/preview/ThreadPreviewMiniPlayer.tsx line 81Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +66,21 @@66+ toastManager.add({67+ type: "error",68+ title: "Unable to update popped-out preview",69+ description: error instanceof Error ? error.message : "An error occurred.",70+ });71+ });72+ }, [desktopOverlay?.pictureInPicture, tabId]);73+74+ const clampAndMove = useCallback(() => {75+ const root = rootRef.current;76+ const parent = root?.offsetParent;77+ if (!root || !(parent instanceof HTMLElement)) return;78+ const next = clampPreviewMiniPlayerPosition(79+ position ?? { x: root.offsetLeft, y: root.offsetTop },80+ { width: parent.clientWidth, height: parent.clientHeight },81+ { width: root.offsetWidth, height: root.offsetHeight },82+ );83+ usePreviewMiniPlayerStore.getState().move(threadRef, tabId, next);84+ }, [position, tabId, threadRef]);85+86+ useLayoutEffect(() => {apps/web/src/browser/HostedBrowserWebview.tsx line 103OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -102,3 +98,6 @@10298 }10399 })();104100 };101+ const recoverGuest = () => {102+ if (disposed) return;103+ setWebviewGeneration((generation) => generation + 1);
- @@ -1805,0 +1970,21 @@1970+ webContentsId: wc.id,1971+ },1972+ () => {1973+ pictureInPictureWindow.webContents.send(1974+ PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL,1975+ frame,1976+ );1977+ },1978+ );1979+ }).pipe(1980+ Effect.catch((error) =>1981+ Effect.logWarning("Picture-in-picture frame delivery failed.", {1982+ tabId,1983+ error,1984+ }),1985+ ),1986+ ),1987+ );1988+ }1989+ }1990+ yield* Effect.all(deliveries, { concurrency: 2, discard: true });@@ -1805,0 +2030,21 @@2030+ return [2031+ true,2032+ replaceMap(sessions, (copy) => {2033+ copy.set(tabId, {2034+ scope,2035+ consumers: new Set([consumer]),2036+ });2037+ }),2038+ ] as const;2039+ });2040+ });2041+ if (!created) return;2042+ yield* capturePreviewFrame(tabId).pipe(2043+ Effect.catch((error) =>2044+ Effect.logWarning("Initial background preview frame was not ready; capture will retry.", {2045+ tabId,2046+ consumer,2047+ error,2048+ }),2049+ ),2050+ );@@ -2593,3 +3085,4 @@25933085 setColorScheme,25943086 setMainWindow,25953087 startRecording,3088+ closePictureInPicture,@@ -518,9 +513,3 @@518513 };519514 }520515 case "recordingStop": {521- const recordingTabId = readActiveBrowserRecordingTabId();522- const stopTabId = resolveBrowserRecordingStopTarget(523- recordingTabId,524- request.tabIdExplicit ? request.tabId : undefined,525- );526- const artifact = stopTabId ? await stopBrowserRecording(stopTabId) : null;@@ -350,17 +372,20 @@350372 function* (input) {351373 const createdAt = yield* currentIsoTimestamp;352- const events = yield* SynchronizedRef.modify(stateRef, (state) => {374+ yield* SynchronizedRef.modifyEffect(stateRef, (state) => {353375 const eventsToEmit: PreviewEvent[] = [];354376 const sessions = new Map(state.sessions);355377 const targets = input.tabId356378 ? [state.sessions.get(compositeKey(input.threadId, input.tabId))].filter(357379 (entry): entry is PreviewSessionState => entry !== undefined,358380 )359381 : sessionsForThread(state, input.threadId);382+ const revision = targets.length > 0 ? state.revision + 1 : state.revision;360383 for (const target of targets) {361384 sessions.delete(compositeKey(target.threadId, target.tabId));362385 eventsToEmit.push({363386 type: "closed",364387 threadId: target.threadId,365388 tabId: target.tabId,366389 createdAt,390+ serverEpoch,391+ revision,
- @@ -1334,10 +1402,19 @@1402+ yield* emit(tabId, closed);1403+ }).pipe(1404+ Effect.ensuring(1405+ Ref.update(closingTabIdsRef, (closingTabIds) => {1406+ if (!closingTabIds.has(tabId)) return closingTabIds;1407+ const next = new Set(closingTabIds);1408+ next.delete(tabId);1409+ return next;1410+ }),1411+ ),13341412 );1335- yield* emit(tabId, closed);13361413 });1337141413381415 const registerWebview = Effect.fn("PreviewManager.registerWebview")(function* (13391416 tabId: string,13401417 webContentsId: number,13411418 ) {13421419 const tab = (yield* SynchronizedRef.get(tabsRef)).get(tabId);1343- if (!tab) {1420+ if (!tab || (yield* Ref.get(closingTabIdsRef)).has(tabId)) {
- @@ -518,9 +518,16 @@518518 };519519 }520520 case "recordingStop": {521- const recordingTabId = readActiveBrowserRecordingTabId();521+ const threadTabIds = new Set(Object.keys(state.sessions));522+ const activeTabIds = new Set(523+ Array.from(readActiveBrowserRecordingTabIds()).filter((activeTabId) =>524+ threadTabIds.has(activeTabId),525+ ),526+ );522527 const stopTabId = resolveBrowserRecordingStopTarget(523- recordingTabId,528+ activeTabIds,529+ tabId,524530 request.tabIdExplicit ? request.tabId : undefined,525531 );532+ tabId = stopTabId ?? tabId;526533 const artifact = stopTabId ? await stopBrowserRecording(stopTabId) : null;
- @@ -448,0 +509,21 @@509+ tabId: string,510+ effect: Effect.Effect<A, E, R>,511+ ): Effect.Effect<A, E, R> =>512+ Effect.suspend(() => {513+ const lifecycle = tabLifecycleLocks.get(tabId) ?? {514+ semaphore: Semaphore.makeUnsafe(1),515+ users: 0,516+ };517+ lifecycle.users += 1;518+ tabLifecycleLocks.set(tabId, lifecycle);519+ return lifecycle.semaphore.withPermit(effect).pipe(520+ Effect.ensuring(521+ Effect.sync(() => {522+ lifecycle.users -= 1;523+ if (lifecycle.users === 0 && tabLifecycleLocks.get(tabId) === lifecycle) {524+ tabLifecycleLocks.delete(tabId);525+ }526+ }),527+ ),528+ );529+ });
- apps/server/src/auth/utils.ts line 23OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -13,5 +13,11 @@1313 export function resolveSessionCookieName(input: {1414 readonly mode: "web" | "desktop";1515 readonly port: number;16+ readonly host: string | undefined;17+ readonly instanceKey: string;1618 }): string {17- if (input.mode !== "desktop") {19+ if (input.mode === "desktop") {20+ return `${SESSION_COOKIE_NAME}_${input.port}`;21+ }22+23+ if (isRemoteReachableHost(input.host)) {
- apps/web/src/components/preview/previewMiniPlayerLayout.ts line 7Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1,7 @@1+import type { PreviewMiniPlayerPosition, PreviewMiniPlayerSize } from "~/previewMiniPlayerStore";2+3+export const PREVIEW_MINI_PLAYER_EDGE_GAP = 12;4+export const PREVIEW_MINI_PLAYER_DEFAULT_SIZE = { width: 360, height: 239 } as const;5+export const PREVIEW_MINI_PLAYER_MIN_SIZE = { width: 280, height: 194 } as const;6+7+export function clampPreviewMiniPlayerSize(
- @@ -361,15 +489,7 @@489+ });490+ }491+ throw startupError;361492 }362- try {363- const blob = new Blob(recording.chunks, { type: recording.mimeType });364- const artifact = await bridge.recording.save(365- tabId,366- recording.mimeType,367- new Uint8Array(await blob.arrayBuffer()),368- );369- result = { _tag: "Success", artifact };370- } catch (cause) {371- throw new BrowserRecordingOperationError({372- operation: "save-artifact",373- tabId,374- cause,375- });493+ if (stopScreencastError) throw stopScreencastError;494+ if (!recording.recorder || !recording.mimeType) {495+ result = { _tag: "Success", artifact: null };@@ -37,6 +52,7 @@3752 observer.disconnect();3853 window.removeEventListener("resize", update);3954 window.removeEventListener("scroll", update, true);55+ if (updateRef.current === update) updateRef.current = null;4056 lease.release();4157 };42- }, [tabId, visible]);58+ }, [fitSourceContent, tabId]);@@ -1390,8 +1518,5 @@13901518 wc.getZoomFactor(),13911519 );13921520 yield* attachListeners(tabId, wc);1393- runFork(restoreControlSession(tabId, wc));13941521 const registeredAt = yield* currentIso;1395- const registration = yield* SynchronizedRef.modify(tabsRef, (tabs) => {1396- const current = tabs.get(tabId);1397- if (!current) {1522+ const registration = yield* SynchronizedRef.modifyEffect(tabsRef, (tabs) =>@@ -201,5 +247,6 @@201247 />202248 ) : null}203249 <webview250+ key={webviewGeneration}204251 ref={setWebviewRef}205- src={initialSrc}252+ src={webviewGeneration === 0 ? initialSrc : (initialUrl ?? initialSrc)}
- @@ -37,6 +52,7 @@3752 observer.disconnect();3853 window.removeEventListener("resize", update);3954 window.removeEventListener("scroll", update, true);55+ if (updateRef.current === update) updateRef.current = null;4056 lease.release();4157 };42- }, [tabId, visible]);58+ }, [fitSourceContent, tabId, visible]);@@ -297,15 +357,11 @@297- }357+ clearActiveRecording(recording);298358 throw new BrowserRecordingOperationError({299359 operation: "start-screencast",300360 tabId,301- cause:302- cleanupCause === undefined303- ? cause304- : new AggregateError(305- [cause, cleanupCause],306- `Browser recording start and cleanup failed for tab ${tabId}.`,307- { cause },308- ),361+ cause,309362 });310363 }311- if (!isRecordingStarting(recording)) {364+ const throwIfStartupCancelled = async (): Promise<void> => {365+ // A stop requested during startup should let startup finish so the366+ // caller receives a real artifact. Only replacement/removal cancels it.367+ if (activeRecordings.get(tabId) === recording) return;
- apps/web/src/browser/BrowserSurfaceSlot.tsx line 57Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -25,5 +38,20 @@2538 width: Math.max(1, Math.round(rect.width)),2639 height: Math.max(1, Math.round(rect.height)),2740 },28- visible && rect.width > 0 && rect.height > 0,41+ presentation.visible && rect.width > 0 && rect.height > 0,42+ presentation.cornerRadius,2943 );44+ if (presentation.visible && !presented) {45+ lease.release();46+ lease = acquireBrowserSurface(tabId, fitSourceContent);47+ lease.present(48+ {49+ x: Math.round(rect.x),50+ y: Math.round(rect.y),51+ width: Math.max(1, Math.round(rect.width)),52+ height: Math.max(1, Math.round(rect.height)),53+ },54+ rect.width > 0 && rect.height > 0,55+ presentation.cornerRadius,56+ );57+ }
- @@ -1805,0 +2069,21 @@2069+ deliveries.push(2070+ Effect.gen(function* () {2071+ const previousAspectRatio = (yield* Ref.get(pictureInPictureAspectRatiosRef)).get(2072+ tabId,2073+ );2074+ const aspectRatio = frame.width / frame.height;2075+ if (previousAspectRatio !== aspectRatio) {2076+ yield* attempt(2077+ {2078+ operation: "pictureInPicture.setAspectRatio",2079+ tabId,2080+ webContentsId: wc.id,2081+ },2082+ () => {2083+ const contentSize = fitPictureInPictureContentSize(2084+ pictureInPictureWindow.getContentSize(),2085+ aspectRatio,2086+ );2087+ pictureInPictureWindow.setContentSize(contentSize[0], contentSize[1], false);2088+ pictureInPictureWindow.setAspectRatio(aspectRatio);2089+ },
- apps/server/src/mcp/toolkits/preview/handlers.ts lines 18 to 28Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -14,3 +15,12 @@1415 import * as PreviewAutomationBroker from "../../PreviewAutomationBroker.ts";1516 import { PreviewSnapshotToolkit, PreviewStandardToolkit, PreviewToolkit } from "./tools.ts";161718+export function normalizePreviewOpenInput(19+ input: PreviewAutomationOpenInput,20+): PreviewAutomationOpenInput {21+ return {22+ ...input,23+ open: input.open ?? input.show ?? true,24+ reuseExistingTab: input.reuseExistingTab ?? true,25+ };26+}
- apps/web/src/components/preview/ThreadPreviewMiniPlayer.tsx line 231OutdatedResolvedby juliusmarminge@@ -0,0 +211,21 @@211+ if (!snapshot || miniPlayer?.tabId !== tabId) return null;212+213+ return (214+ <section215+ ref={rootRef}216+ aria-label="Floating browser preview"217+ data-preview-mini-player={tabId}218+ className="pointer-events-none absolute select-none"219+ style={220+ position221+ ? { left: position.x, top: position.y, width: size.width, height: size.height }222+ : {223+ right: 16,224+ top: 16,225+ width: size.width,226+ height: size.height,227+ }228+ }229+ >230+ <div231+ className="pointer-events-auto absolute right-2 top-2 z-[34] flex h-8 cursor-grab items-center gap-0.5 rounded-lg border border-border/80 bg-popover/92 p-0.5 opacity-0 shadow-lg/20 backdrop-blur-xl transition-opacity hover:opacity-100 focus-within:opacity-100 active:cursor-grabbing"apps/web/src/components/preview/ThreadPreviewMiniPlayer.tsx line 231OutdatedResolvedby juliusmarminge@@ -0,0 +211,21 @@211+ if (!snapshot || miniPlayer?.tabId !== tabId) return null;212+213+ return (214+ <section215+ ref={rootRef}216+ aria-label="Floating browser preview"217+ data-preview-mini-player={tabId}218+ className="pointer-events-none absolute select-none"219+ style={220+ position221+ ? { left: position.x, top: position.y, width: size.width, height: size.height }222+ : {223+ right: 16,224+ top: 16,225+ width: size.width,226+ height: size.height,227+ }228+ }229+ >230+ <div231+ className="pointer-events-auto absolute right-2 top-2 z-[34] flex h-8 cursor-grab items-center gap-0.5 rounded-lg border border-border/80 bg-popover/92 p-0.5 opacity-0 shadow-lg/20 backdrop-blur-xl transition-opacity hover:opacity-100 focus-within:opacity-100 active:cursor-grabbing"@@ -378,5 +381,5 @@378381 activeSnapshot = snapshot;379382 tabId = activeTabId;380383 }381- if (input.show ?? true) {382- useRightPanelStore.getState().openBrowser(threadRef, activeTabId);384+ if (shouldOpenPreviewMiniPlayer(input)) {385+ usePreviewMiniPlayerStore.getState().open(threadRef, activeTabId);
- @@ -150,0 +186,21 @@186+ 1,187+ Math.round(188+ presentation.fittedSourceContent.width /189+ presentation.fittedSourceContent.scale /190+ normalizedZoomFactor,191+ ),192+ ),193+ height: Math.max(194+ 1,195+ Math.round(196+ presentation.fittedSourceContent.height /197+ presentation.fittedSourceContent.scale /198+ normalizedZoomFactor,199+ ),200+ ),201+ }202+ : {203+ _tag: "freeform" as const,204+ width: viewport._tag === "fill" ? 1280 : viewport.width,205+ height: viewport._tag === "fill" ? 800 : viewport.height,206+ }@@ -178,3 +239,3 @@178239179240 const wrapperStyle = resolveHostedBrowserWebviewWrapperStyle({180241 active,
- apps/desktop/src/preview/Manager.ts line 2020OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1805,0 +2000,21 @@2000+ const wc = yield* requireWebContents(tabId);2001+ const image = yield* attemptPromise(2002+ {2003+ operation: "frameCapture.capturePage",2004+ tabId,2005+ webContentsId: wc.id,2006+ },2007+ () => wc.capturePage(),2008+ );2009+ const captureStillCurrent = yield* Effect.all(2010+ [SynchronizedRef.get(frameCaptureSessionsRef), SynchronizedRef.get(tabsRef)],2011+ { concurrency: 2 },2012+ ).pipe(2013+ Effect.map(2014+ ([captureSessions, tabs]) =>2015+ captureSessions.get(tabId) === captureSession &&2016+ tabs.get(tabId)?.webContentsId === wc.id &&2017+ !wc.isDestroyed(),2018+ ),2019+ );2020+ if (!captureStillCurrent) return;apps/desktop/src/preview/Manager.ts line 2456Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1827,0 +2430,21 @@2430+ pictureInPictureMutationSemaphore.withPermit(2431+ releasePictureInPicture(tabId, pictureInPictureSession, true),2432+ ),2433+ ),2434+ );2435+ if (Exit.isSuccess(initializationExit)) {2436+ const published = yield* pictureInPictureMutationSemaphore.withPermit(2437+ Effect.gen(function* () {2438+ const current = (yield* SynchronizedRef.get(pictureInPictureSessionsRef)).get(tabId);2439+ if (current !== pictureInPictureSession || pictureInPictureSession.window.isDestroyed()) {2440+ if (current === pictureInPictureSession) {2441+ yield* releasePictureInPicture(tabId, pictureInPictureSession, false);2442+ }2443+ return false;2444+ }2445+ yield* Deferred.done(pictureInPictureSession.ready, initializationExit);2446+ return true;2447+ }),2448+ );2449+ if (published) return;2450+ return yield* Deferred.await(pictureInPictureSession.ready);
juliusmarminge merged thisf4c3943
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
a8a26b55-7631-4337-b970-d0f6275eaf15You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment `@coderabbitai help` to get the list of available commands.