@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 27 lines 989 Bytes
Raw
1 import type { PreviewAnnotationPayload } from "@t3tools/contracts";
2
3 import { dataUrlToFile } from "./imageCompression";
4
5 export type PreviewAnnotationCapture =
6 | { readonly status: "captured"; readonly file: File }
7 | { readonly status: "none" }
8 | { readonly status: "failed" };
9
10 const PNG_DATA_URL_PREFIX = "data:image/png;base64,";
11
12 /** Decode Electron's PNG crop locally; fetching a data URL violates desktop connect-src. */
13 export function capturePreviewAnnotationScreenshot(
14 annotation: PreviewAnnotationPayload,
15 ): PreviewAnnotationCapture {
16 if (!annotation.screenshot) return { status: "none" };
17 try {
18 const { dataUrl } = annotation.screenshot;
19 if (!dataUrl.startsWith(PNG_DATA_URL_PREFIX)) {
20 return { status: "failed" };
21 }
22 const file = dataUrlToFile(dataUrl, `preview-annotation-${annotation.id}.png`, "image/png");
23 return file.size > 0 ? { status: "captured", file } : { status: "failed" };
24 } catch {
25 return { status: "failed" };
26 }
27 }