Files
t3code/apps/web/src/lib/desktopSnapShot.ts
T
299404a754 feat(desktop): add cross-platform window capture (#8103)
Co-authored-by: Dara Adedeji <[email protected]>
Co-authored-by: Dara Adedeji <[email protected]>
Co-authored-by: Wout Stiens <[email protected]>
Co-authored-by: Julius Marminge <[email protected]>
Co-authored-by: Julius Marminge <[email protected]>
Co-authored-by: Claude Fable 5.1 <[email protected]>
2026-09-07 18:21:53 -07:00

45 lines
1.6 KiB
TypeScript

import type { DesktopBridge } from "@t3tools/contracts";
const SNAP_SHOT_FOCUS_EVENT = "t3code:focus-composer";
export function dispatchSnapShotComposerFocus(): void {
if (typeof window === "undefined") return;
window.dispatchEvent(new Event(SNAP_SHOT_FOCUS_EVENT));
}
export function subscribeSnapShotComposerFocus(listener: () => void): () => void {
if (typeof window === "undefined") return () => {};
window.addEventListener(SNAP_SHOT_FOCUS_EVENT, listener);
return () => window.removeEventListener(SNAP_SHOT_FOCUS_EVENT, listener);
}
type SnapShotMethods =
| "requestSnapShotPermissions"
| "getSnapShotState"
| "checkSnapShotShortcut"
| "setSnapShotShortcutSuppressed"
| "listPendingSnapShots"
| "readSnapShot"
| "acknowledgeSnapShot"
| "onSnapShotEvent";
export type DesktopSnapShotBridge = DesktopBridge & Required<Pick<DesktopBridge, SnapShotMethods>>;
export function getDesktopSnapShotBridge(): DesktopSnapShotBridge | undefined {
const bridge = typeof window === "undefined" ? undefined : window.desktopBridge;
if (
typeof bridge?.requestSnapShotPermissions !== "function" ||
typeof bridge?.getSnapShotState !== "function" ||
typeof bridge.checkSnapShotShortcut !== "function" ||
typeof bridge.setSnapShotShortcutSuppressed !== "function" ||
typeof bridge.listPendingSnapShots !== "function" ||
typeof bridge.readSnapShot !== "function" ||
typeof bridge.acknowledgeSnapShot !== "function" ||
typeof bridge.onSnapShotEvent !== "function"
) {
return undefined;
}
return bridge as DesktopSnapShotBridge;
}