1- import { useEffect , useRef , useState , useSyncExternalStore } from "react" ;
1+ import { useEffect , useEffectEvent , useRef , useState , useSyncExternalStore } from "react" ;
22import { Keyboard , View } from "react-native" ;
33import { CommonActions , StackActions , useNavigation } from "@react-navigation/native" ;
44import { AsyncResult } from "effect/reactivity" ;
@@ -25,31 +25,24 @@ import {
2525 SHOWCASE_PENDING_TASK_DEFINITIONS ,
2626} from "./showcasePendingTasks" ;
2727import { buildShowcaseAgentActivity } from "./showcaseAgentActivity" ;
28+ import {
29+ isShowcaseThemeApplied ,
30+ SHOWCASE_THREAD_ID ,
31+ showcaseReadinessKey ,
32+ showcaseSceneOnScreen ,
33+ } from "./showcaseCaptureModel" ;
2834import { retryShowcaseOperation } from "./showcaseRetry" ;
2935import {
3036 clearShowcaseRenderSignal ,
37+ getShowcaseRenderReports ,
3138 getShowcaseRenderSignal ,
32- isShowcaseNativeContentReady ,
3339 subscribeToShowcaseRenderSignal ,
3440} from "./showcaseRenderSignal" ;
3541import { stageShowcaseAgentActivity } from "./stageShowcaseAgentActivity" ;
3642import { openSettings } from "../settings/settings-navigation" ;
3743import { selectWorkspaceDetail } from "../workspace/workspace-detail-selection" ;
3844
3945const 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- }
5346
5447export function ShowcaseCaptureCoordinator ( props : { readonly pathname : string } ) {
5548 if ( ! SHOWCASE_ENABLED ) return null ;
@@ -87,20 +80,25 @@ function EnabledShowcaseCaptureCoordinator(props: { readonly pathname: string })
8780 const [ requestedScene , setRequestedScene ] = useState < ShowcaseScene | null > ( null ) ;
8881 const [ requestedTheme , setRequestedTheme ] = useState < MobileThemeId | null > ( null ) ;
8982 const [ themeRequestSettled , setThemeRequestSettled ] = useState ( false ) ;
90- const [ readyScene , setReadyScene ] = useState < ShowcaseScene | null > ( null ) ;
83+ const [ marked , setMarked ] = useState < {
84+ readonly key : string ;
85+ readonly scene : ShowcaseScene ;
86+ } | null > ( null ) ;
9187 const [ orientationSettled , setOrientationSettled ] = useState ( false ) ;
9288 const [ agentActivityStaged , setAgentActivityStaged ] = useState ( false ) ;
9389 const requestedSceneRef = useRef < ShowcaseScene | null > ( null ) ;
9490 // 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 ] ) ;
91+ const readFixtureEntities = useEffectEvent ( ( ) => ( { threads, projects } ) ) ;
9992 const renderSignal = useSyncExternalStore (
10093 subscribeToShowcaseRenderSignal ,
10194 getShowcaseRenderSignal ,
10295 getShowcaseRenderSignal ,
10396 ) ;
97+ const renderReports = useSyncExternalStore (
98+ subscribeToShowcaseRenderSignal ,
99+ getShowcaseRenderReports ,
100+ getShowcaseRenderReports ,
101+ ) ;
104102
105103 useEffect ( ( ) => {
106104 if ( pairingUrls . length > 0 ) return ;
@@ -152,10 +150,11 @@ function EnabledShowcaseCaptureCoordinator(props: { readonly pathname: string })
152150 return ( ) => clearInterval ( interval ) ;
153151 } , [ ] ) ;
154152
155- const themeApplied =
156- requestedTheme === null
157- ? themeRequestSettled
158- : themeIds . light === requestedTheme && themeIds . dark === requestedTheme ;
153+ const themeApplied = isShowcaseThemeApplied ( {
154+ launchRequestRead : themeRequestSettled ,
155+ requestedTheme,
156+ themeIds,
157+ } ) ;
159158
160159 useEffect ( ( ) => {
161160 if ( requestedTheme === null || themeApplied || ! appearancePreferencesReady ) {
@@ -184,9 +183,7 @@ function EnabledShowcaseCaptureCoordinator(props: { readonly pathname: string })
184183 } ;
185184 } , [ connectPairingUrl , pairingUrls ] ) ;
186185
187- const routeScene = sceneFromPathname ( props . pathname ) ;
188- const scene =
189- requestedScene === "agent-activity" && routeScene === "threads" ? "agent-activity" : routeScene ;
186+ const scene = showcaseSceneOnScreen ( requestedScene , props . pathname ) ;
190187 const hasServerFixture =
191188 workspace . state . hasReadyEnvironment &&
192189 workspace . environments . length >= 3 &&
@@ -264,7 +261,7 @@ function EnabledShowcaseCaptureCoordinator(props: { readonly pathname: string })
264261 void retryShowcaseOperation (
265262 async ( ) => {
266263 const now = Date . now ( ) ;
267- const { threads : latestThreads , projects : latestProjects } = entitiesRef . current ;
264+ const { threads : latestThreads , projects : latestProjects } = readFixtureEntities ( ) ;
268265 const activity = buildShowcaseAgentActivity ( latestThreads , latestProjects , now ) ;
269266 const outcome =
270267 activity === null
@@ -285,21 +282,23 @@ function EnabledShowcaseCaptureCoordinator(props: { readonly pathname: string })
285282 } ;
286283 } , [ agentActivityStaged , hasFixture , scene ] ) ;
287284
285+ const readinessKey = showcaseReadinessKey ( {
286+ scene,
287+ requestedScene,
288+ hasFixture,
289+ orientationSettled,
290+ themeApplied,
291+ agentActivityStaged,
292+ themeId,
293+ renderSignal,
294+ renderReports,
295+ } ) ;
296+ // A marker belongs to the readiness it was settled for; any change hides it until it settles again.
297+ if ( marked !== null && marked . key !== readinessKey ) setMarked ( null ) ;
298+ const readyScene = marked ?. scene ?? null ;
299+
288300 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- }
301+ if ( readinessKey === null || scene === null ) return ;
303302 if ( scene === "terminal" ) Keyboard . dismiss ( ) ;
304303
305304 let renderFrame : number | null = null ;
@@ -308,7 +307,7 @@ function EnabledShowcaseCaptureCoordinator(props: { readonly pathname: string })
308307 renderFrame = requestAnimationFrame ( ( ) => {
309308 readyFrame = requestAnimationFrame ( ( ) => {
310309 markNativeShowcaseReady ( scene ) ;
311- setReadyScene ( scene ) ;
310+ setMarked ( { key : readinessKey , scene } ) ;
312311 } ) ;
313312 } ) ;
314313 } , 500 ) ;
@@ -317,19 +316,9 @@ function EnabledShowcaseCaptureCoordinator(props: { readonly pathname: string })
317316 if ( renderFrame !== null ) cancelAnimationFrame ( renderFrame ) ;
318317 if ( readyFrame !== null ) cancelAnimationFrame ( readyFrame ) ;
319318 } ;
320- } , [
321- agentActivityStaged ,
322- hasFixture ,
323- orientationSettled ,
324- renderSignal ,
325- requestedScene ,
326- scene ,
327- themeApplied ,
328- themeId ,
329- ] ) ;
319+ } , [ readinessKey , scene ] ) ;
330320
331321 if ( readyScene === null ) return null ;
332-
333322 return (
334323 < View
335324 pointerEvents = "none"
0 commit comments