Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

preview-pip-preload.ts

17 lines860 Bytes

1// @effect-diagnostics globalDate:off - This isolated Electron preload does not run inside an Effect runtime.
2import type { DesktopPreviewRecordingFrame } from "@t3tools/contracts";
3import { contextBridge, ipcRenderer } from "electron";
4​
5import { PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL } from "./ipc/channels.ts";
6​
7contextBridge.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});