@@ -3,7 +3,7 @@ import type { DevicePlatform, DeviceServiceState, EnvironmentId } from "@t3tools
33import { Check } from "lucide-react" ;
44import { Check as CheckGlyph , CircleAlert } from "lucide" ;
55import { AuthSettingsWriteScope } from "@t3tools/contracts" ;
6- import { useState } from "react" ;
6+ import { useEffect , useState } from "react" ;
77
88import { Button } from "~/components/ui/button" ;
99import { DialogClose } from "~/components/ui/dialog" ;
@@ -23,20 +23,42 @@ export const deviceHubDescription =
2323export const agentDeviceDescription =
2424 "Allow new agent sessions in this environment to start and control local and remote devices, with required tools set up automatically." ;
2525
26+ /**
27+ * `hostStatus` only tracks this machine. A machine without simulator tooling never
28+ * starts its own hub, so setup and the panel must also count remote device hosts.
29+ */
30+ export function deviceHubReadiness ( state : DeviceServiceState ) {
31+ const statuses = Object . values ( state . hostStatuses ) . map ( ( host ) => host . status ) ;
32+ const ready = state . hostStatus === "ready" || statuses . includes ( "ready" ) ;
33+ const busy =
34+ ! ready &&
35+ [ state . hostStatus , ...statuses ] . some (
36+ ( status ) => status === "installing" || status === "starting" ,
37+ ) ;
38+ return { ready, busy } ;
39+ }
40+
2641export function platformSetupStatus ( state : DeviceServiceState , platform : DevicePlatform ) {
27- const availability = state . hosts
28- . flatMap ( ( host ) => host . platforms )
29- . find ( ( candidate ) => candidate . platform === platform ) ;
30- if ( ! availability ?. available ) {
42+ const availabilities = state . hosts . flatMap ( ( host ) =>
43+ host . platforms
44+ . filter ( ( candidate ) => candidate . platform === platform )
45+ . map ( ( candidate ) => ( { ...candidate , host } ) ) ,
46+ ) ;
47+ const supportingHosts = availabilities
48+ . filter ( ( candidate ) => candidate . available )
49+ . map ( ( candidate ) => candidate . host ) ;
50+ if ( supportingHosts . length === 0 ) {
3151 return {
3252 ready : false ,
33- message : availability ?. reason ?? `${ platformName ( platform ) } support was not detected.` ,
53+ message : availabilities [ 0 ] ?. reason ?? `${ platformName ( platform ) } support was not detected.` ,
3454 } ;
3555 }
36- if (
37- state . hostStatus === "ready" &&
38- ! state . devices . some ( ( device ) => device . platform === platform )
39- ) {
56+ const readyHosts = supportingHosts . filter (
57+ ( host ) =>
58+ state . hostStatuses [ host . id ] ?. status === "ready" ||
59+ ( host . kind === "local" && state . hostStatus === "ready" ) ,
60+ ) ;
61+ if ( readyHosts . length > 0 && ! state . devices . some ( ( device ) => device . platform === platform ) ) {
4062 return {
4163 ready : false ,
4264 message :
@@ -45,12 +67,16 @@ export function platformSetupStatus(state: DeviceServiceState, platform: DeviceP
4567 : "The Android SDK is installed, but no virtual device exists. Create one in Android Studio → Device Manager." ,
4668 } ;
4769 }
70+ const remoteHost = supportingHosts . every ( ( host ) => host . kind !== "local" )
71+ ? supportingHosts [ 0 ]
72+ : undefined ;
73+ const location = remoteHost ? ` on ${ remoteHost . label } ` : "" ;
4874 return {
4975 ready : true ,
5076 message :
5177 platform === "ios"
52- ? " Xcode and iOS Simulator are available."
53- : " The Android SDK and Emulator are available." ,
78+ ? ` Xcode and iOS Simulator are available${ location } .`
79+ : ` The Android SDK and Emulator are available${ location } .` ,
5480 } ;
5581}
5682
@@ -65,11 +91,16 @@ export function DeviceSetup(props: {
6591 const [ pending , setPending ] = useState < "hub" | "check" | "agent" | "complete" | null > ( null ) ;
6692 const [ step , setStep ] = useState ( 0 ) ;
6793 const enabled = props . state . hostStatus !== "disabled" ;
68- const busy = props . state . hostStatus === "installing" || props . state . hostStatus === "starting" ;
94+ const { ready , busy } = deviceHubReadiness ( props . state ) ;
6995 const localPlatformsUnavailable = props . state . hosts . some (
7096 ( host ) => host . kind === "local" && ! host . platforms . some ( ( platform ) => platform . available ) ,
7197 ) ;
7298
99+ // Remote hosts report platforms only after a probe, like the Device panel's refresh on open.
100+ useEffect ( ( ) => {
101+ if ( enabled ) void list ( { environmentId : props . environmentId , input : { } } ) ;
102+ } , [ enabled , list , props . environmentId ] ) ;
103+
73104 const update = async (
74105 kind : NonNullable < typeof pending > ,
75106 input : { enabled ?: boolean ; agentAccessEnabled ?: boolean ; onboardingCompleted ?: boolean } ,
@@ -181,15 +212,12 @@ export function DeviceSetup(props: {
181212 </ Button >
182213 ) }
183214 { step < 2 ? (
184- < Button
185- disabled = { props . state . hostStatus !== "ready" || pending !== null }
186- onClick = { ( ) => setStep ( step + 1 ) }
187- >
215+ < Button disabled = { ! ready || pending !== null } onClick = { ( ) => setStep ( step + 1 ) } >
188216 Continue
189217 </ Button >
190218 ) : (
191219 < Button
192- disabled = { ! canConfigure || props . state . hostStatus !== " ready" || pending !== null }
220+ disabled = { ! canConfigure || ! ready || pending !== null }
193221 onClick = { ( ) => void update ( "complete" , { onboardingCompleted : true } ) }
194222 >
195223 { pending === "complete" ? "Saving…" : "Done" }
@@ -209,7 +237,7 @@ export function DeviceHubSetupStatus({
209237 readonly pending : boolean ;
210238 readonly compact ?: boolean ;
211239} ) {
212- if ( ! pending && state . hostStatus !== " ready" ) return null ;
240+ if ( ! pending && ! deviceHubReadiness ( state ) . ready ) return null ;
213241 return (
214242 < p role = "status" className = "flex items-center gap-2 text-xs text-muted-foreground" >
215243 { pending ? < Spinner size = "xs" /> : < Check className = "size-3 text-success" /> }
@@ -278,7 +306,7 @@ export function AgentDeviceSetupStatus(props: {
278306 }
279307 if (
280308 props . state . agentAccessEnabled &&
281- props . state . hostStatus === " ready" &&
309+ deviceHubReadiness ( props . state ) . ready &&
282310 props . state . hosts . some ( ( host ) => host . agentDeviceInstalled )
283311 ) {
284312 return (
0 commit comments