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
| 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 interface ShowcaseNavigationTarget { |
| 31 | readonly requestedScene: ShowcaseScene; |
| 32 | readonly scene: ShowcaseScene | null; |
| 33 | /** The showcase thread shell; a new shell (or environment) is a new target to navigate to. */ |
| 34 | readonly thread: object; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Whether to dispatch the navigation for `next`, given the target last dispatched. A target is |
| 39 | * dispatched once, and again whenever any part of it changes, so a dispatch that did not move |
| 40 | * the route is retried when the thread shell or route updates. |
| 41 | */ |
| 42 | export function shouldNavigateToShowcaseScene( |
| 43 | last: ShowcaseNavigationTarget | null, |
| 44 | next: ShowcaseNavigationTarget, |
| 45 | ): boolean { |
| 46 | return ( |
| 47 | next.scene !== next.requestedScene && |
| 48 | (last === null || |
| 49 | last.requestedScene !== next.requestedScene || |
| 50 | last.scene !== next.scene || |
| 51 | last.thread !== next.thread) |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | export function isShowcaseThemeApplied(input: { |
| 56 | readonly launchRequestRead: boolean; |
| 57 | readonly requestedTheme: MobileThemeId | null; |
| 58 | readonly themeIds: MobileThemeIds; |
| 59 | }): boolean { |
| 60 | if (input.requestedTheme === null) return input.launchRequestRead; |
| 61 | return ( |
| 62 | input.themeIds.light === input.requestedTheme && input.themeIds.dark === input.requestedTheme |
| 63 | ); |
| 64 | } |
| 65 | |
| 66 | export interface ShowcaseReadinessInput { |
| 67 | readonly scene: ShowcaseScene | null; |
| 68 | readonly requestedScene: ShowcaseScene | null; |
| 69 | readonly hasFixture: boolean; |
| 70 | readonly orientationSettled: boolean; |
| 71 | readonly themeApplied: boolean; |
| 72 | readonly agentActivityStaged: boolean; |
| 73 | readonly themeId: MobileThemeId; |
| 74 | readonly renderSignal: ShowcaseRenderSignal | null; |
| 75 | /** Counts render-signal changes; a redraw report restarts the settle delay. */ |
| 76 | readonly renderReports: number; |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * The capture key for a scene that is ready to be marked, or null while any |
| 81 | * precondition is missing. A changed key restarts the settle delay. |
| 82 | */ |
| 83 | export function showcaseReadinessKey(input: ShowcaseReadinessInput): string | null { |
| 84 | const { scene } = input; |
| 85 | if ( |
| 86 | scene === null || |
| 87 | scene !== input.requestedScene || |
| 88 | !input.hasFixture || |
| 89 | !input.orientationSettled || |
| 90 | !input.themeApplied || |
| 91 | (scene === "agent-activity" && !input.agentActivityStaged) || |
| 92 | !isShowcaseNativeContentReady({ |
| 93 | scene, |
| 94 | themeId: input.themeId, |
| 95 | renderSignal: input.renderSignal, |
| 96 | }) |
| 97 | ) { |
| 98 | return null; |
| 99 | } |
| 100 | return [scene, input.themeId, input.renderReports].join("|"); |
| 101 | } |