| 1 | import type { DesktopPreviewRecordingFrame } from "@t3tools/contracts"; |
| 2 | import { contextBridge, ipcRenderer } from "electron"; |
| 3 | |
| 4 | import { PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL } from "./ipc/channels.ts"; |
| 5 | |
| 6 | contextBridge.exposeInMainWorld("previewPictureInPicture", { |
| 7 | onFrame: (listener: (frame: DesktopPreviewRecordingFrame) => void) => { |
| 8 | const wrappedListener = (_event: Electron.IpcRendererEvent, frame: unknown) => { |
| 9 | if (typeof frame !== "object" || frame === null) return; |
| 10 | listener(frame as DesktopPreviewRecordingFrame); |
| 11 | }; |
| 12 | ipcRenderer.on(PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL, wrappedListener); |
| 13 | return () => |
| 14 | ipcRenderer.removeListener(PREVIEW_PICTURE_IN_PICTURE_FRAME_CHANNEL, wrappedListener); |
| 15 | }, |
| 16 | }); |