Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/web/src/components/device/DeviceChips.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ export function DeviceChips(props: {
aria-label={`${chip.name} menu`}
className={cn(
"flex h-full w-5 shrink-0 items-center justify-center rounded-md focus-ring",
// Always there on the shown chip and on touch; on hover elsewhere.
!selected && "can-hover:opacity-0 can-hover:group-hover/chip:opacity-100",
// Always there on the shown chip, keyboard focus, and touch; on hover elsewhere.
!selected &&
"can-hover:opacity-0 can-hover:group-hover/chip:opacity-100 can-hover:focus-visible:opacity-100",
)}
/>
}
Expand Down
21 changes: 14 additions & 7 deletions apps/web/src/components/device/DeviceFloatingWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function DeviceFloatingWindow(props: {
{float && device && column
? createPortal(
<FloatingDevice
key={`${environmentId}\u0000${device.id}`}
key={`${threadKey}\u0000${device.id}`}
environmentId={environmentId}
threadKey={threadKey}
device={device}
Expand Down Expand Up @@ -168,6 +168,7 @@ function FloatingDevice(props: {
});
// Held while a gesture runs, so the store only hears where it ends.
const [live, setLive] = useState<DeviceFloatRect | null>(null);
const liveRef = useRef<DeviceFloatRect | null>(null);
const rect =
live ??
fitDeviceFloat({
Expand All @@ -192,11 +193,12 @@ function FloatingDevice(props: {
if (!held || held.gesture.pointerId !== event.pointerId) return;
const dx = event.clientX - held.gesture.x;
const dy = event.clientY - held.gesture.y;
setLive(
const nextRect =
held.gesture.kind === "drag"
? dragDeviceFloat(held.start, dx, dy, aspect, viewport)
: resizeDeviceFloat(held.start, held.gesture.edge, dx, dy, aspect, viewport),
);
: resizeDeviceFloat(held.start, held.gesture.edge, dx, dy, aspect, viewport);
liveRef.current = nextRect;
setLive(nextRect);
};
const end = (event: PointerEvent<HTMLElement>) => {
const held = gesture.current;
Expand All @@ -205,10 +207,12 @@ function FloatingDevice(props: {
if (event.currentTarget.hasPointerCapture(event.pointerId)) {
event.currentTarget.releasePointerCapture(event.pointerId);
}
if (live) {
const settled = liveRef.current;
liveRef.current = null;
if (settled) {
placeDeviceFloat(threadKey, device.id, {
position: { x: live.x, y: live.y },
width: live.width,
position: { x: settled.x, y: settled.y },
width: settled.width,
});
}
setLive(null);
Expand Down Expand Up @@ -275,6 +279,9 @@ function FloatingDevice(props: {
deviceDescription={device.version}
stream={stream}
state={state}
deviceId={device.id}
model={device.model}
physical={device.physical}
/>
</div>
{EDGES.map(({ edge, className }) => (
Expand Down
37 changes: 37 additions & 0 deletions apps/web/src/components/device/DevicePanel.browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -598,4 +598,41 @@ describe("DevicePanel", () => {
computer.channels.filter((channel) => channel.input.path === "/vendor/serve-sim/helper/ws"),
).toHaveLength(1);
});

it("selects the booted serial when an Android AVD boots, hides Shake on Android, and reopens setup from the picker", async () => {
const AVD = {
id: "Pixel_9_API_35",
platform: "android",
name: "Pixel 9",
version: "Android 16",
booted: false,
physical: false,
} as const;
const computer = fakeComputer(deviceState({ devices: [AVD] }));
computer.device.open.mockImplementationOnce(async () => session(PIXEL.id, "android", "user"));
await render(<Host visible />);

// Picker gear icon reopens setup and Done returns to the picker.
await page.getByRole("button", { name: "Device settings" }).click();
await expect.element(page.getByRole("heading", { name: "Set up devices" })).toBeVisible();
await page.getByRole("button", { name: "Done" }).click();
await expect.element(page.getByTestId("device-picker")).toBeVisible();

// Booting an AVD whose open returns its booted emulator serial selects that serial.
await page.getByRole("button", { name: "Start Pixel 9" }).click();
computer.push(
deviceState({
devices: [PIXEL],
sessions: [session(PIXEL.id, "android", "user")],
revision: 2,
}),
);
await expect.element(page.getByRole("toolbar", { name: "Device controls" })).toBeVisible();
expect(readThreadDeviceViews(THREAD_KEY).selected).toBe(PIXEL.id);

// Android Tools hides the iOS-only Shake button.
await page.getByRole("button", { name: "Tools" }).click();
await expect.element(page.getByRole("button", { name: "Close tools" })).toBeVisible();
await expect.element(page.getByRole("button", { name: "Shake" })).not.toBeInTheDocument();
});
});
26 changes: 19 additions & 7 deletions apps/web/src/components/device/DevicePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ export function DevicePanel(props: {
const [error, setError] = useState<string | null>(null);

// Devices on and nothing started yet: list them, which starts the hub. Once
// per panel, and only while the tab is on screen.
// per enable cycle, and only while the tab is on screen.
const listed = useRef(false);
const enabled = state?.enabled === true;
const idle = state?.hostStatus === "idle";
useEffect(() => {
if (!visible || !enabled || !idle || listed.current) return;
if (!enabled) {
listed.current = false;
return;
}
if (!visible || !idle || listed.current) return;
listed.current = true;
refreshDevices(environmentId).catch((cause: unknown) => setError(deviceErrorText(cause)));
}, [enabled, environmentId, idle, visible]);
Expand Down Expand Up @@ -130,14 +134,21 @@ export function DevicePanel(props: {
}
setPending(device.id);
void run(async () => {
await openDevice(environmentId, { threadId, deviceId: device.id, platform: device.platform });
selectThreadDevice(threadKey, device.id);
// Android AVDs change id when they boot (AVD name → emulator serial), so use the returned session.
const session = await openDevice(environmentId, {
threadId,
deviceId: device.id,
platform: device.platform,
});
selectThreadDevice(threadKey, session.deviceId);
}).finally(() => setPending(null));
};

const close = (deviceId: string, shutdown: boolean) => {
removeDeviceChip(threadKey, deviceId, sessions);
void run(() => closeDevice(environmentId, { threadId, deviceId, shutdown }));
void run(async () => {
await closeDevice(environmentId, { threadId, deviceId, shutdown });
removeDeviceChip(threadKey, deviceId, sessions);
});
};

const errorLine = error ? (
Expand Down Expand Up @@ -229,7 +240,7 @@ export function DevicePanel(props: {
/>
) : (
<DeviceWorkspace
key={`${environmentId}\u0000${activeDevice.id}`}
key={`${threadKey}\u0000${activeDevice.id}`}
environmentId={environmentId}
device={activeDevice}
visible={visible}
Expand Down Expand Up @@ -274,6 +285,7 @@ export function DevicePanel(props: {
setRefreshing(true);
void run(() => refreshDevices(environmentId)).finally(() => setRefreshing(false));
}}
onOpenSetup={() => setInSetup(true)}
/>
)}
</div>
Expand Down
37 changes: 26 additions & 11 deletions apps/web/src/components/device/DevicePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
groupDevicesByPlatform,
isDeviceHostBusy,
} from "@threadlines/client-runtime/deviceState";
import { PowerIcon, RefreshCwIcon, SmartphoneIcon } from "lucide-react";
import { PowerIcon, RefreshCwIcon, SettingsIcon, SmartphoneIcon } from "lucide-react";

import { cn } from "~/lib/utils";
import { SETTINGS_GROUP_ROW_CLASS, SettingsGroup } from "../settings/settingsLayout";
Expand All @@ -26,6 +26,8 @@ export function DevicePicker(props: {
readonly onOpen: (device: DeviceSummary) => void;
readonly onPowerOff: (device: DeviceSummary) => void;
readonly onRefresh: () => void;
/** Reopens this computer's device setup (closes the one-way door on linked computers / phone). */
readonly onOpenSetup?: () => void;
}) {
const { state } = props;
const groups = groupDevicesByPlatform(state.devices);
Expand Down Expand Up @@ -53,16 +55,29 @@ export function DevicePicker(props: {
? "1 device"
: `${state.devices.length} devices`}
</span>
<Button
size="icon-xs"
variant="ghost"
aria-label="Refresh devices"
tooltip="Refresh devices"
disabled={props.refreshing || busy}
onClick={props.onRefresh}
>
{props.refreshing ? <Spinner /> : <RefreshCwIcon />}
</Button>
<div className="flex shrink-0 items-center gap-0.5">
<Button
size="icon-xs"
variant="ghost"
aria-label="Refresh devices"
tooltip="Refresh devices"
disabled={props.refreshing || busy}
onClick={props.onRefresh}
>
{props.refreshing ? <Spinner /> : <RefreshCwIcon />}
</Button>
{props.onOpenSetup ? (
<Button
size="icon-xs"
variant="ghost"
aria-label="Device settings"
tooltip="Device settings"
onClick={props.onOpenSetup}
>
<SettingsIcon />
</Button>
) : null}
</div>
</div>
<div className="min-h-0 flex-1 space-y-3 overflow-y-auto px-3 pb-3">
{state.hostStatus !== "ready" && state.hostStatus !== "idle" ? (
Expand Down
Loading
Loading