@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 28 lines 1.09 KB
Raw
1 import { PreviewCaptureFailure, type PreviewCaptureFailureEncoded } from "@t3tools/contracts";
2 import * as Option from "effect/Option";
3 import * as Schema from "effect/Schema";
4
5 const decodeCaptureFailure = Schema.decodeUnknownOption(PreviewCaptureFailure);
6
7 // Decode here because contextBridge strips custom properties from rejected Errors.
8 function unwrapPreviewCaptureResult<A>(result: A | PreviewCaptureFailureEncoded): A {
9 const failure = decodeCaptureFailure(result);
10 if (Option.isSome(failure)) throw failure.value;
11 return result as A;
12 }
13
14 const nativePreviewBridge =
15 typeof window === "undefined" ? null : (window.desktopBridge?.preview ?? null);
16
17 export const previewBridge = nativePreviewBridge
18 ? {
19 ...nativePreviewBridge,
20 captureScreenshot: async (tabId: string) =>
21 unwrapPreviewCaptureResult(await nativePreviewBridge.captureScreenshot(tabId)),
22 recording: {
23 ...nativePreviewBridge.recording,
24 startScreencast: async (tabId: string) =>
25 unwrapPreviewCaptureResult(await nativePreviewBridge.recording.startScreencast(tabId)),
26 },
27 }
28 : null;