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 22, 14:30 UTC
refactor(mobile): showcase capture readiness is a tested pure model (#25816)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 27, 2026 at 02:12 UTC
a24b109bc394bc00567c2a6ebe745e75a7c0f897
4 files changed
+209
-62
apps/mobile/src/features/showcase/ShowcaseCaptureCoordinator.tsx
+35
-56
@@ -1,4 +1,4 @@
1
-import { useEffect, useRef, useState, useSyncExternalStore } from "react";
1
+import { useEffect, useEffectEvent, useRef, useState, useSyncExternalStore } from "react";
2
import { Keyboard, View } from "react-native";
3
import { CommonActions, StackActions, useNavigation } from "@react-navigation/native";
4
import { AsyncResult } from "effect/reactivity";
@@ -25,11 +25,16 @@ import {
25
SHOWCASE_PENDING_TASK_DEFINITIONS,
26
} from "./showcasePendingTasks";
27
import { buildShowcaseAgentActivity } from "./showcaseAgentActivity";
28
+import {
29
+ isShowcaseThemeApplied,
30
+ SHOWCASE_THREAD_ID,
31
+ showcaseReadinessKey,
32
+ showcaseSceneOnScreen,
33
+} from "./showcaseCaptureModel";
34
import { retryShowcaseOperation } from "./showcaseRetry";
35
import {
36
clearShowcaseRenderSignal,
31
- getShowcaseRenderSignal,
32
- isShowcaseNativeContentReady,
37
+ getShowcaseRenderSnapshot,
38
subscribeToShowcaseRenderSignal,
39
} from "./showcaseRenderSignal";
40
import { stageShowcaseAgentActivity } from "./stageShowcaseAgentActivity";
@@ -37,19 +42,6 @@ import { openSettings } from "../settings/settings-navigation";
42
import { selectWorkspaceDetail } from "../workspace/workspace-detail-selection";
43
44
const SHOWCASE_ENABLED = process.env.EXPO_PUBLIC_SHOWCASE === "1";
40
-const SHOWCASE_THREAD_ID = "remote-command-center";
41
-
42
-function sceneFromPathname(pathname: string): ShowcaseScene | null {
43
- const routePath = pathname.split(/[?#]/u, 1)[0] ?? pathname;
44
- if (routePath === "/settings" || routePath.endsWith("/settings/environments")) {
45
- return "environments";
46
- }
47
- if (routePath.endsWith("/terminal")) return "terminal";
48
- if (routePath.endsWith("/review")) return "review";
49
- if (routePath.startsWith("/threads/")) return "thread";
50
- if (routePath === "/") return "threads";
51
- return null;
52
-}
45
46
export function ShowcaseCaptureCoordinator(props: { readonly pathname: string }) {
47
if (!SHOWCASE_ENABLED) return null;
@@ -92,14 +84,11 @@ function EnabledShowcaseCaptureCoordinator(props: { readonly pathname: string })
84
const [agentActivityStaged, setAgentActivityStaged] = useState(false);
85
const requestedSceneRef = useRef<ShowcaseScene | null>(null);
86
// Read current entities without restarting on shell updates and re-entering open permission prompts.
95
- const entitiesRef = useRef({ threads, projects });
96
- useEffect(() => {
97
- entitiesRef.current = { threads, projects };
98
- }, [projects, threads]);
99
- const renderSignal = useSyncExternalStore(
87
+ const readFixtureEntities = useEffectEvent(() => ({ threads, projects }));
88
+ const { signal: renderSignal, reports: renderReports } = useSyncExternalStore(
89
subscribeToShowcaseRenderSignal,
101
- getShowcaseRenderSignal,
102
- getShowcaseRenderSignal,
90
+ getShowcaseRenderSnapshot,
91
+ getShowcaseRenderSnapshot,
92
);
93
94
useEffect(() => {
@@ -152,10 +141,11 @@ function EnabledShowcaseCaptureCoordinator(props: { readonly pathname: string })
141
return () => clearInterval(interval);
142
}, []);
143
155
- const themeApplied =
156
- requestedTheme === null
157
- ? themeRequestSettled
158
- : themeIds.light === requestedTheme && themeIds.dark === requestedTheme;
144
+ const themeApplied = isShowcaseThemeApplied({
145
+ launchRequestRead: themeRequestSettled,
146
+ requestedTheme,
147
+ themeIds,
148
+ });
149
150
useEffect(() => {
151
if (requestedTheme === null || themeApplied || !appearancePreferencesReady) {
@@ -184,9 +174,7 @@ function EnabledShowcaseCaptureCoordinator(props: { readonly pathname: string })
174
};
175
}, [connectPairingUrl, pairingUrls]);
176
187
- const routeScene = sceneFromPathname(props.pathname);
188
- const scene =
189
- requestedScene === "agent-activity" && routeScene === "threads" ? "agent-activity" : routeScene;
177
+ const scene = showcaseSceneOnScreen(requestedScene, props.pathname);
178
const hasServerFixture =
179
workspace.state.hasReadyEnvironment &&
180
workspace.environments.length >= 3 &&
@@ -264,7 +252,7 @@ function EnabledShowcaseCaptureCoordinator(props: { readonly pathname: string })
252
void retryShowcaseOperation(
253
async () => {
254
const now = Date.now();
267
- const { threads: latestThreads, projects: latestProjects } = entitiesRef.current;
255
+ const { threads: latestThreads, projects: latestProjects } = readFixtureEntities();
256
const activity = buildShowcaseAgentActivity(latestThreads, latestProjects, now);
257
const outcome =
258
activity === null
@@ -285,21 +273,22 @@ function EnabledShowcaseCaptureCoordinator(props: { readonly pathname: string })
273
};
274
}, [agentActivityStaged, hasFixture, scene]);
275
276
+ const readinessKey = showcaseReadinessKey({
277
+ scene,
278
+ requestedScene,
279
+ hasFixture,
280
+ orientationSettled,
281
+ themeApplied,
282
+ agentActivityStaged,
283
+ themeId,
284
+ renderSignal,
285
+ renderReports,
286
+ });
287
+ // Losing readiness hides the marker. A redraw or theme change while ready keeps it and re-settles.
288
+ if (readinessKey === null && readyScene !== null) setReadyScene(null);
289
+
290
useEffect(() => {
289
- if (
290
- scene === null ||
291
- requestedScene === null ||
292
- scene !== requestedScene ||
293
- !hasFixture ||
294
- !orientationSettled ||
295
- !themeApplied ||
296
- (scene === "agent-activity" && !agentActivityStaged) ||
297
- !isShowcaseNativeContentReady({ scene, themeId, renderSignal })
298
- ) {
299
- // oxlint-disable-next-line react/set-state-in-effect -- Capture readiness clears while the scene, fixture, or native content is not ready.
300
- setReadyScene(null);
301
- return;
302
- }
291
+ if (readinessKey === null || scene === null) return;
292
if (scene === "terminal") Keyboard.dismiss();
293
294
let renderFrame: number | null = null;
@@ -317,19 +306,9 @@ function EnabledShowcaseCaptureCoordinator(props: { readonly pathname: string })
306
if (renderFrame !== null) cancelAnimationFrame(renderFrame);
307
if (readyFrame !== null) cancelAnimationFrame(readyFrame);
308
};
320
- }, [
321
- agentActivityStaged,
322
- hasFixture,
323
- orientationSettled,
324
- renderSignal,
325
- requestedScene,
326
- scene,
327
- themeApplied,
328
- themeId,
329
- ]);
309
+ }, [readinessKey, scene]);
310
311
if (readyScene === null) return null;
332
-
312
return (
313
<View
314
pointerEvents="none"
apps/mobile/src/features/showcase/showcaseCaptureModel.test.ts
new
+86
@@ -0,0 +1,86 @@
1
+import { describe, expect, it } from "vite-plus/test";
2
+
3
+import {
4
+ isShowcaseThemeApplied,
5
+ showcaseReadinessKey,
6
+ showcaseSceneOnScreen,
7
+ type ShowcaseReadinessInput,
8
+} from "./showcaseCaptureModel";
9
+
10
+const ready: ShowcaseReadinessInput = {
11
+ scene: "thread",
12
+ requestedScene: "thread",
13
+ hasFixture: true,
14
+ orientationSettled: true,
15
+ themeApplied: true,
16
+ agentActivityStaged: false,
17
+ themeId: "t3-code",
18
+ renderSignal: null,
19
+ renderReports: 0,
20
+};
21
+
22
+describe("showcaseSceneOnScreen", () => {
23
+ it("treats the threads list as the agent activity scene only when that scene is requested", () => {
24
+ expect(showcaseSceneOnScreen("agent-activity", "/")).toBe("agent-activity");
25
+ expect(showcaseSceneOnScreen("threads", "/")).toBe("threads");
26
+ expect(showcaseSceneOnScreen("agent-activity", "/threads/env/thread")).toBe("thread");
27
+ expect(showcaseSceneOnScreen(null, "/threads/env/thread/review?x=1")).toBe("review");
28
+ });
29
+});
30
+
31
+describe("isShowcaseThemeApplied", () => {
32
+ it("waits for the launch request when no theme is requested", () => {
33
+ const themeIds = { light: "t3-code", dark: "t3-code" } as const;
34
+ expect(
35
+ isShowcaseThemeApplied({ launchRequestRead: false, requestedTheme: null, themeIds }),
36
+ ).toBe(false);
37
+ expect(
38
+ isShowcaseThemeApplied({ launchRequestRead: true, requestedTheme: null, themeIds }),
39
+ ).toBe(true);
40
+ });
41
+
42
+ it("requires both appearances to use the requested theme", () => {
43
+ expect(
44
+ isShowcaseThemeApplied({
45
+ launchRequestRead: true,
46
+ requestedTheme: "t3-code",
47
+ themeIds: { light: "t3-code", dark: "material-you" },
48
+ }),
49
+ ).toBe(false);
50
+ });
51
+});
52
+
53
+describe("showcaseReadinessKey", () => {
54
+ it("is null until every precondition holds", () => {
55
+ expect(showcaseReadinessKey(ready)).not.toBeNull();
56
+ expect(showcaseReadinessKey({ ...ready, requestedScene: "terminal" })).toBeNull();
57
+ expect(showcaseReadinessKey({ ...ready, hasFixture: false })).toBeNull();
58
+ expect(showcaseReadinessKey({ ...ready, orientationSettled: false })).toBeNull();
59
+ expect(showcaseReadinessKey({ ...ready, themeApplied: false })).toBeNull();
60
+ });
61
+
62
+ it("waits for agent activity to be staged", () => {
63
+ const agentActivity = {
64
+ ...ready,
65
+ scene: "agent-activity",
66
+ requestedScene: "agent-activity",
67
+ } as const;
68
+ expect(showcaseReadinessKey(agentActivity)).toBeNull();
69
+ expect(showcaseReadinessKey({ ...agentActivity, agentActivityStaged: true })).not.toBeNull();
70
+ });
71
+
72
+ it("waits for review to report a draw in the current theme, and changes key when it redraws", () => {
73
+ const review = { ...ready, scene: "review", requestedScene: "review" } as const;
74
+ expect(showcaseReadinessKey(review)).toBeNull();
75
+ expect(
76
+ showcaseReadinessKey({
77
+ ...review,
78
+ renderSignal: { scene: "review", themeId: "material-you" },
79
+ }),
80
+ ).toBeNull();
81
+ const drawn = { ...review, renderSignal: { scene: "review", themeId: "t3-code" } } as const;
82
+ const firstDraw = showcaseReadinessKey({ ...drawn, renderReports: 1 });
83
+ expect(firstDraw).not.toBeNull();
84
+ expect(showcaseReadinessKey({ ...drawn, renderReports: 2 })).not.toBe(firstDraw);
85
+ });
86
+});
apps/mobile/src/features/showcase/showcaseCaptureModel.ts
new
+76
@@ -0,0 +1,76 @@
1
+import type { MobileThemeId, MobileThemeIds } from "../../lib/mobileTheme";
2
+import type { ShowcaseScene } from "./nativeShowcaseScene";
3
+import { isShowcaseNativeContentReady, type ShowcaseRenderSignal } from "./showcaseRenderSignal";
4
+
5
+export const SHOWCASE_THREAD_ID = "remote-command-center";
6
+
7
+function sceneFromPathname(pathname: string): ShowcaseScene | null {
8
+ const routePath = pathname.split(/[?#]/u, 1)[0] ?? pathname;
9
+ if (routePath === "/settings" || routePath.endsWith("/settings/environments")) {
10
+ return "environments";
11
+ }
12
+ if (routePath.endsWith("/terminal")) return "terminal";
13
+ if (routePath.endsWith("/review")) return "review";
14
+ if (routePath.startsWith("/threads/")) return "thread";
15
+ if (routePath === "/") return "threads";
16
+ return null;
17
+}
18
+
19
+/** Agent activity is staged on the threads list, so that route counts as the scene. */
20
+export function showcaseSceneOnScreen(
21
+ requestedScene: ShowcaseScene | null,
22
+ pathname: string,
23
+): ShowcaseScene | null {
24
+ const routeScene = sceneFromPathname(pathname);
25
+ return requestedScene === "agent-activity" && routeScene === "threads"
26
+ ? "agent-activity"
27
+ : routeScene;
28
+}
29
+
30
+export function isShowcaseThemeApplied(input: {
31
+ readonly launchRequestRead: boolean;
32
+ readonly requestedTheme: MobileThemeId | null;
33
+ readonly themeIds: MobileThemeIds;
34
+}): boolean {
35
+ if (input.requestedTheme === null) return input.launchRequestRead;
36
+ return (
37
+ input.themeIds.light === input.requestedTheme && input.themeIds.dark === input.requestedTheme
38
+ );
39
+}
40
+
41
+export interface ShowcaseReadinessInput {
42
+ readonly scene: ShowcaseScene | null;
43
+ readonly requestedScene: ShowcaseScene | null;
44
+ readonly hasFixture: boolean;
45
+ readonly orientationSettled: boolean;
46
+ readonly themeApplied: boolean;
47
+ readonly agentActivityStaged: boolean;
48
+ readonly themeId: MobileThemeId;
49
+ readonly renderSignal: ShowcaseRenderSignal | null;
50
+ /** Counts render-signal changes; a redraw report restarts the settle delay. */
51
+ readonly renderReports: number;
52
+}
53
+
54
+/**
55
+ * The capture key for a scene that is ready to be marked, or null while any
56
+ * precondition is missing. A changed key restarts the settle delay.
57
+ */
58
+export function showcaseReadinessKey(input: ShowcaseReadinessInput): string | null {
59
+ const { scene } = input;
60
+ if (
61
+ scene === null ||
62
+ scene !== input.requestedScene ||
63
+ !input.hasFixture ||
64
+ !input.orientationSettled ||
65
+ !input.themeApplied ||
66
+ (scene === "agent-activity" && !input.agentActivityStaged) ||
67
+ !isShowcaseNativeContentReady({
68
+ scene,
69
+ themeId: input.themeId,
70
+ renderSignal: input.renderSignal,
71
+ })
72
+ ) {
73
+ return null;
74
+ }
75
+ return [scene, input.themeId, input.renderReports].join("|");
76
+}
apps/mobile/src/features/showcase/showcaseRenderSignal.ts
+12
-6
@@ -7,10 +7,16 @@ export type ShowcaseRenderSignal = Readonly<{
7
}>;
8
9
const listeners = new Set<() => void>();
10
-let renderSignal: ShowcaseRenderSignal | null = null;
10
+export type ShowcaseRenderSnapshot = Readonly<{
11
+ signal: ShowcaseRenderSignal | null;
12
+ // A redraw can repeat the same scene and theme; counting reports lets it restart the settle delay.
13
+ reports: number;
14
+}>;
15
+
16
+let snapshot: ShowcaseRenderSnapshot = { signal: null, reports: 0 };
17
12
-export function getShowcaseRenderSignal(): ShowcaseRenderSignal | null {
13
- return renderSignal;
18
+export function getShowcaseRenderSnapshot(): ShowcaseRenderSnapshot {
19
+ return snapshot;
20
}
21
22
export function subscribeToShowcaseRenderSignal(listener: () => void): () => void {
@@ -19,13 +25,13 @@ export function subscribeToShowcaseRenderSignal(listener: () => void): () => voi
25
}
26
27
export function reportShowcaseSceneRendered(signal: ShowcaseRenderSignal): void {
22
- renderSignal = signal;
28
+ snapshot = { signal, reports: snapshot.reports + 1 };
29
for (const listener of listeners) listener();
30
}
31
32
export function clearShowcaseRenderSignal(): void {
27
- if (renderSignal === null) return;
28
- renderSignal = null;
33
+ if (snapshot.signal === null) return;
34
+ snapshot = { signal: null, reports: snapshot.reports + 1 };
35
for (const listener of listeners) listener();
36
}
37