Skip to content

Commit 7837404

Browse files
fix(web): device setup lets you through with only a remote device host
The setup wizard waited for the local hub to be ready, so a machine without simulator tooling stayed stuck even when a remote host was ready and listing devices. Readiness and platform support now consider every device host. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 727b4e7 commit 7837404

4 files changed

Lines changed: 98 additions & 30 deletions

File tree

‎apps/web/src/components/device/DevicePanel.tsx‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { deviceEnvironment, useDeviceState } from "~/state/device";
2020
import { formatEnvironmentQueryError } from "~/state/query";
2121
import { useAtomCommand } from "~/state/use-atom-command";
2222
import { DeviceLoadingView } from "./DeviceLoadingView";
23-
import { DeviceSetup } from "./DeviceSetup";
23+
import { DeviceSetup, deviceHubReadiness } from "./DeviceSetup";
2424
import { DeviceWorkspace } from "./DeviceWorkspace";
2525
import { PreviewPanelShell, type PreviewPanelMode } from "../preview/PreviewPanelShell";
2626

@@ -138,12 +138,7 @@ export function DevicePanel(props: {
138138

139139
const bootingDevices =
140140
state.bootingDevices?.filter((device) => device.threadId === threadId) ?? [];
141-
const hostReady = Object.values(state.hostStatuses).some((host) => host.status === "ready");
142-
const hostBusy =
143-
!hostReady &&
144-
Object.values(state.hostStatuses).some(
145-
(host) => host.status === "installing" || host.status === "starting",
146-
);
141+
const { ready: hostReady, busy: hostBusy } = deviceHubReadiness(state);
147142
const unavailablePlatforms = state.hosts.flatMap((host) =>
148143
host.platforms
149144
.filter((platform) => !platform.available)

‎apps/web/src/components/device/DeviceSetup.tsx‎

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { DevicePlatform, DeviceServiceState, EnvironmentId } from "@t3tools
33
import { Check } from "lucide-react";
44
import { Check as CheckGlyph, CircleAlert } from "lucide";
55
import { AuthSettingsWriteScope } from "@t3tools/contracts";
6-
import { useState } from "react";
6+
import { useEffect, useState } from "react";
77

88
import { Button } from "~/components/ui/button";
99
import { DialogClose } from "~/components/ui/dialog";
@@ -23,20 +23,42 @@ export const deviceHubDescription =
2323
export 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+
2641
export 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 (

‎apps/web/src/components/settings/IntegrationsSettings.test.tsx‎

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ vi.mock("./SettingsScopeContext", () => ({
6868
}));
6969

7070
import { IntegrationsSettingsPanel } from "./IntegrationsSettings";
71-
import { platformSetupStatus } from "../device/DeviceSetup";
71+
import { deviceHubReadiness, platformSetupStatus } from "../device/DeviceSetup";
7272

7373
let renderer: ReactTestRenderer | undefined;
7474

@@ -163,4 +163,48 @@ describe("device setup guidance", () => {
163163
});
164164
expect(platformSetupStatus(state, "android").message).toBe("Android Emulator is missing.");
165165
});
166+
167+
it("counts a remote device host when this machine has no simulator tooling", () => {
168+
const state = deviceState({
169+
hostStatus: "idle",
170+
hostStatuses: { macmini: { status: "ready" } },
171+
hosts: [
172+
{
173+
...deviceState().hosts[0]!,
174+
platforms: [
175+
{ platform: "ios", available: false, reason: "Xcode was not found." },
176+
{ platform: "android", available: false, reason: "Android SDK was not found." },
177+
],
178+
},
179+
{
180+
id: "macmini",
181+
kind: "ssh",
182+
label: "Mac Mini",
183+
hubInstalled: true,
184+
agentDeviceInstalled: true,
185+
platforms: [
186+
{ platform: "ios", available: true },
187+
{ platform: "android", available: false, reason: "Android SDK was not found." },
188+
],
189+
},
190+
],
191+
devices: [
192+
{
193+
hostId: "macmini",
194+
id: "iphone",
195+
platform: "ios",
196+
name: "iPhone 16 Pro",
197+
version: "iOS 27.0",
198+
booted: true,
199+
physical: false,
200+
},
201+
],
202+
});
203+
expect(deviceHubReadiness(state).ready).toBe(true);
204+
expect(platformSetupStatus(state, "ios")).toEqual({
205+
ready: true,
206+
message: "Xcode and iOS Simulator are available on Mac Mini.",
207+
});
208+
expect(platformSetupStatus(state, "android").ready).toBe(false);
209+
});
166210
});

‎apps/web/src/components/settings/IntegrationsSettings.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"
5858
import {
5959
AgentDeviceSetupStatus,
6060
DeviceHubSetupStatus,
61+
deviceHubReadiness,
6162
PlatformStatus,
6263
platformSetupStatus,
6364
deviceHubDescription,
@@ -691,7 +692,7 @@ function DeviceIntegrationControls({
691692
const [pending, setPending] = useState<
692693
"hub" | "check" | "agent" | "update-hub" | "update-agent" | null
693694
>(null);
694-
const busy = state.hostStatus === "installing" || state.hostStatus === "starting";
695+
const { ready: hubReady, busy } = deviceHubReadiness(state);
695696
const localPlatformsUnavailable = state.hosts.some(
696697
(host) => host.kind === "local" && !host.platforms.some((platform) => platform.available),
697698
);
@@ -701,7 +702,7 @@ function DeviceIntegrationControls({
701702
if (
702703
enabled &&
703704
!platformsRevealed &&
704-
(state.hostStatus === "ready" || localPlatformsUnavailable) &&
705+
(hubReady || localPlatformsUnavailable) &&
705706
pending !== "hub"
706707
) {
707708
setPlatformsRevealed(true);

0 commit comments

Comments
 (0)