Open History to see the last commit
1import { requireOptionalNativeModule } from "expo";
2
3export const SHOWCASE_SCENES = ["threads", "thread", "terminal", "review", "environments"] as const;
4export type ShowcaseScene = (typeof SHOWCASE_SCENES)[number];
5
6interface NativeShowcaseControls {
7 readonly getShowcasePairingUrl?: () => string | null;
8 readonly getShowcaseScene?: () => string | null;
9 readonly prepareShowcaseCapture?: () => void;
10 readonly markShowcaseReady?: (scene: ShowcaseScene) => void;
11}
12
13function nativeShowcaseControls(): NativeShowcaseControls | null {
14 return requireOptionalNativeModule<NativeShowcaseControls>("T3NativeControls");
15}
16
17export function getNativeShowcasePairingUrls(): ReadonlyArray<string> {
18 try {
19 let raw = nativeShowcaseControls()?.getShowcasePairingUrl?.()?.trim();
20 if (!raw) return [];
21 if (raw.startsWith("json-uri:")) {
22 try {
23 raw = decodeURIComponent(raw.slice("json-uri:".length));
24 } catch {
25 return [];
26 }
27 }
28 try {
29 const parsed: unknown = JSON.parse(raw);
30 if (Array.isArray(parsed)) {
31 return parsed.filter(
32 (candidate): candidate is string =>
33 typeof candidate === "string" && candidate.trim().length > 0,
34 );
35 }
36 } catch {
37 // Older runners pass a single URL rather than a JSON array.
38 }
39 return [raw];
40 } catch {
41 return [];
42 }
43}
44
45export function getNativeShowcaseScene(): ShowcaseScene | null {
46 try {
47 const scene = nativeShowcaseControls()?.getShowcaseScene?.()?.trim();
48 return SHOWCASE_SCENES.find((candidate) => candidate === scene) ?? null;
49 } catch {
50 return null;
51 }
52}
53
54export function prepareNativeShowcaseCapture(): void {
55 try {
56 nativeShowcaseControls()?.prepareShowcaseCapture?.();
57 } catch {
58 // The harness still works when a development build predates this helper.
59 }
60}
61
62export function markNativeShowcaseReady(scene: ShowcaseScene): void {
63 try {
64 nativeShowcaseControls()?.markShowcaseReady?.(scene);
65 } catch {
66 // The readiness marker is capture-runner metadata, never app functionality.
67 }
68}