Skip to content
This repository was archived by the owner on Oct 10, 2026. It is now read-only.

Commit f4c3943

Browse files
Add background preview capture and picture-in-picture support (pingdotgg#4397)
Co-authored-by: codex <[email protected]>
1 parent 2b06c08 commit f4c3943

60 files changed

Lines changed: 4103 additions & 594 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/desktop/src/electron/ElectronWindow.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ describe("ElectronWindow", () => {
9494
webPreferences: {
9595
preload: "/tmp/preload.js",
9696
partition: "persist:t3code-preview-test",
97+
backgroundThrottling: null,
9798
sandbox: true,
9899
contextIsolation: true,
99100
nodeIntegration: false,

‎apps/desktop/src/electron/ElectronWindow.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const ElectronWindowCreateOptions = Schema.Struct({
2222
webPreferences: Schema.Struct({
2323
preload: Schema.NullOr(Schema.String),
2424
partition: Schema.NullOr(Schema.String),
25+
backgroundThrottling: Schema.NullOr(Schema.Boolean),
2526
sandbox: Schema.NullOr(Schema.Boolean),
2627
contextIsolation: Schema.NullOr(Schema.Boolean),
2728
nodeIntegration: Schema.NullOr(Schema.Boolean),
@@ -179,6 +180,7 @@ export const make = Effect.gen(function* () {
179180
webPreferences: {
180181
preload: webPreferences?.preload ?? null,
181182
partition: webPreferences?.partition ?? null,
183+
backgroundThrottling: webPreferences?.backgroundThrottling ?? null,
182184
sandbox: webPreferences?.sandbox ?? null,
183185
contextIsolation: webPreferences?.contextIsolation ?? null,
184186
nodeIntegration: webPreferences?.nodeIntegration ?? null,

‎apps/desktop/src/ipc/channels.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ export const PREVIEW_CANCEL_PICK_ELEMENT_CHANNEL = "desktop:preview-cancel-pick-
6161
export const PREVIEW_CAPTURE_SCREENSHOT_CHANNEL = "desktop:preview-capture-screenshot";
6262
export const PREVIEW_REVEAL_ARTIFACT_CHANNEL = "desktop:preview-reveal-artifact";
6363
export const PREVIEW_COPY_ARTIFACT_CHANNEL = "desktop:preview-copy-artifact";
64+
export const PREVIEW_PICTURE_IN_PICTURE_OPEN_CHANNEL = "desktop:preview-pip-open";
65+
export const PREVIEW_PICTURE_IN_PICTURE_CLOSE_CHANNEL = "desktop:preview-pip-close";
66+
export const PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL = "desktop:preview-pip-frame";
6467
export const PREVIEW_AUTOMATION_STATUS_CHANNEL = "desktop:preview-automation-status";
6568
export const PREVIEW_AUTOMATION_SNAPSHOT_CHANNEL = "desktop:preview-automation-snapshot";
6669
export const PREVIEW_AUTOMATION_CLICK_CHANNEL = "desktop:preview-automation-click";

‎apps/desktop/src/ipc/methods/preview.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ export const stopRecording = tabMethod(
168168
"desktop.ipc.preview.stopRecording",
169169
(manager, tabId) => manager.stopRecording(tabId),
170170
);
171+
export const openPictureInPicture = tabMethod(
172+
IpcChannels.PREVIEW_PICTURE_IN_PICTURE_OPEN_CHANNEL,
173+
"desktop.ipc.preview.openPictureInPicture",
174+
(manager, tabId) => manager.openPictureInPicture(tabId),
175+
);
176+
export const closePictureInPicture = tabMethod(
177+
IpcChannels.PREVIEW_PICTURE_IN_PICTURE_CLOSE_CHANNEL,
178+
"desktop.ipc.preview.closePictureInPicture",
179+
(manager, tabId) => manager.closePictureInPicture(tabId),
180+
);
171181

172182
export const clearCookies = DesktopIpc.makeIpcMethod({
173183
channel: IpcChannels.PREVIEW_CLEAR_COOKIES_CHANNEL,
@@ -367,6 +377,8 @@ export const methods = [
367377
captureScreenshot,
368378
revealArtifact,
369379
copyArtifactToClipboard,
380+
openPictureInPicture,
381+
closePictureInPicture,
370382
automationStatus,
371383
automationSnapshot,
372384
automationClick,

‎apps/desktop/src/preload.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ contextBridge.exposeInMainWorld("desktopBridge", {
179179
ipcRenderer.invoke(IpcChannels.PREVIEW_REVEAL_ARTIFACT_CHANNEL, { path }),
180180
copyArtifactToClipboard: (path) =>
181181
ipcRenderer.invoke(IpcChannels.PREVIEW_COPY_ARTIFACT_CHANNEL, { path }),
182+
pictureInPicture: {
183+
open: (tabId) =>
184+
ipcRenderer.invoke(IpcChannels.PREVIEW_PICTURE_IN_PICTURE_OPEN_CHANNEL, { tabId }),
185+
close: (tabId) =>
186+
ipcRenderer.invoke(IpcChannels.PREVIEW_PICTURE_IN_PICTURE_CLOSE_CHANNEL, { tabId }),
187+
},
182188
recording: {
183189
startScreencast: (tabId) =>
184190
ipcRenderer.invoke(IpcChannels.PREVIEW_RECORDING_START_CHANNEL, { tabId }),
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// @effect-diagnostics globalDate:off - This isolated Electron preload does not run inside an Effect runtime.
2+
import type { DesktopPreviewRecordingFrame } from "@t3tools/contracts";
3+
import { contextBridge, ipcRenderer } from "electron";
4+
5+
import { PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL } from "./ipc/channels.ts";
6+
7+
contextBridge.exposeInMainWorld("previewPictureInPicture", {
8+
onFrame: (listener: (frame: DesktopPreviewRecordingFrame) => void) => {
9+
const wrappedListener = (_event: Electron.IpcRendererEvent, frame: unknown) => {
10+
if (typeof frame !== "object" || frame === null) return;
11+
listener(frame as DesktopPreviewRecordingFrame);
12+
};
13+
ipcRenderer.on(PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL, wrappedListener);
14+
return () =>
15+
ipcRenderer.removeListener(PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL, wrappedListener);
16+
},
17+
});

0 commit comments

Comments
 (0)