diff --git a/README.md b/README.md index b41a9ab9..f4f29e8f 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ to avoid duplicate Mobile Dev servers. See [Cursor's plugin guide](https://curso ### Mac app The Mac app shows the devices and tools in their own window, without a chat. Pick -a tool and the visible platforms in the sidebar. It runs the same server as the +a tool in the sidebar and devices from **+ Add device** in the tab strip. It runs the same server as the plugins, so the device panels, logs, performance, storage, and TraceSift work the same way. Chat actions such as Send to chat and annotations are hidden because there is no chat to send to. @@ -216,7 +216,7 @@ its device panel, inspection, logs, and performance tools. Ask your agent to open the simulator beside this chat. In Codex, you can also open Mobile Dev from the sidebar; in Cursor, ask **"Open Mobile Dev"** in an agent chat. Pick a device from the toolbar; selecting a stopped simulator or AVD -boots it. Use the iOS and Android toggles to show either platform or both. +boots it. Choose additional iOS or Android devices from **+ Add device** in the tab strip to open them side by side. Drag a device tab to an edge to split the view, or into another group to collect its tabs. Click an iOS simulator or Android screen to focus it, then press **Ctrl+V** on Windows or **Command-V** on macOS to paste text into the device. Paste accepts up to 4,096 printable US-ASCII characters; diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 47369e08..350a32ea 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -10,7 +10,7 @@ Native helpers statically link [Sentry Native 0.17.1](https://github.com/getsent This plugin also includes [agent-device 0.21.37](https://github.com/callstack/agent-device/tree/v0.21.37) by Callstack under the MIT License. Its license sits at `dist/agent-device/node_modules/agent-device/LICENSE`. The package includes the official npm release, its Apple runner source, and its bundled JavaScript dependencies. `runtimes/agent-device/package-lock.json` pins the package and its integrity hash. `dist/agent-device/release.json` records the npm archive, integrity hash, and lockfile SHA-256. The agent-device skill's workflow guide, `skills/agent-device/references/workflow.md`, is that CLI version's `help workflow` output. -The Baguette MCP server and panel bundle the Model Context Protocol SDK, MCP Apps SDK, OpenAI MCP Extensions, Zod, ws, React, Radix UI, Legend List, Sentry's React and Node SDKs, and their required JavaScript code. The panel uses shadcn/ui components under the MIT License and Tailwind CSS styles. It bundles Lucide icons under the ISC License, with Feather icons under the MIT License and Inter under the SIL Open Font License 1.1. `dist/third-party-licenses.txt` contains their licenses. The build preserves bundled license comments too. +The Baguette MCP server and panel bundle the Model Context Protocol SDK, MCP Apps SDK, OpenAI MCP Extensions, Zod, ws, React, Radix UI, Legend List, Sentry's React and Node SDKs, and their required JavaScript code. The panel uses Dockview and shadcn/ui components under the MIT License and Tailwind CSS styles. It bundles Lucide icons under the ISC License, with Feather icons under the MIT License and Inter under the SIL Open Font License 1.1. `dist/third-party-licenses.txt` contains their licenses. The build preserves bundled license comments too. This plugin includes [serve-emu 0.0.6](https://github.com/jiunshinn/serve-emu) by jiunshinn under the Apache License 2.0. Its server source is checked in at `runtimes/serve-emu/src`; the fork, dependencies, and licenses ship in `dist/serve-emu`. `runtimes/serve-emu/upstream.json` records the copied release's npm tarball and integrity hash. `runtimes/serve-emu/package-lock.json` pins the fork’s Node dependencies and integrity hashes. `dist/serve-emu/release.json` records these hashes and the SHA-256 of the bundled [scrcpy 4.0 server](https://github.com/Genymobile/scrcpy/releases/tag/v4.0), also under the Apache License 2.0. The plugin includes a source fork with a Node.js port of serve-emu's CLI and HTTP/WebSocket server, using the bundled MIT-licensed ws library. Its scrcpy protocol, input queues, and session recovery are preserved. diff --git a/apps/codex-plugin/test/workspace-opening.test.ts b/apps/codex-plugin/test/workspace-opening.test.ts index c665ddb9..7393b2f3 100644 --- a/apps/codex-plugin/test/workspace-opening.test.ts +++ b/apps/codex-plugin/test/workspace-opening.test.ts @@ -96,6 +96,7 @@ for (const notification of ["input", "result"] as const) test(`workspace applies } if (notification === "input") { const captured = telemetry.join("\n"); + assert.match(captured, /ui\.devices\.visible/); assert.match(captured, /"device_platform":\{"value":"android"/); assert.match(captured, /"device_kind":\{"value":"emulator"/); assert.match(captured, /"layout":\{"value":"android"/); @@ -117,16 +118,11 @@ for (const notification of ["input", "result"] as const) test(`workspace applies else send({ method: "ui/notifications/tool-result", params: { content: [], structuredContent: { panelTarget: target } } }); await until(() => calls.includes("mobile_list_android_devices")); await until(() => { - const label = window.document.getElementById("platform-select")?.textContent ?? ""; - return label.includes("Android"); + const label = window.document.querySelector('[data-device-pane][data-platform="android"]')?.getAttribute("aria-label"); + return label === "Pixel"; }); - await setTimeout(10); - const ios = window.document.getElementById("ios-panel"); - const android = window.document.getElementById("android-panel"); - assert.equal(ios?.hidden, true); - assert.equal(android?.hidden, false); - const devices = android?.querySelector('[data-element="devices"]')?.textContent ?? ""; - assert.match(devices, /Pixel/); + assert.equal(window.document.querySelectorAll("[data-device-pane]").length, 1); + assert.equal(window.document.querySelector('[data-platform="ios"]'), null); const unexpected = calls.filter(name => name.endsWith("_stream_session") || name.startsWith("mobile_boot")); assert.deepEqual(unexpected, []); if (nativeComposer) { @@ -142,9 +138,9 @@ for (const notification of ["input", "result"] as const) test(`workspace applies window.dispatchEvent(new window.Event("focus")); await until(() => reports.length === 4); assert.deepEqual(reports[3], selected, "Refocusing restores the selection even after the server restarts"); - window.document.getElementById("platform-select")?.click(); - await until(() => window.document.getElementById("platform-android") !== null); - window.document.getElementById("platform-android")?.click(); + const closeTab = window.document.querySelector('[role="tab"] [role="button"], [role="tab"] button'); + assert.ok(closeTab); + closeTab.click(); await until(() => reports.at(-1)?.devices?.length === 0); const cleared = reports.at(-1); assert.deepEqual(cleared?.devices, []); diff --git a/apps/codex-plugin/tooling/smoke-package.mjs b/apps/codex-plugin/tooling/smoke-package.mjs index b5b6552f..0f511ebe 100644 --- a/apps/codex-plugin/tooling/smoke-package.mjs +++ b/apps/codex-plugin/tooling/smoke-package.mjs @@ -235,7 +235,7 @@ try { assert.equal(resource.contents[0].mimeType, "text/html;profile=mcp-app"); assert.ok(resource.contents[0].text.includes('id="root"')); // React creates these controls from the bundled script after the app mounts. - for (const control of ["canvas", "logs-drawer", "log-chat", "tool-select", "tool-performance", "tool-app-intel", "app-intelligence-panel", "tool-tracesift", "performance-drawer", "performance-app", "platform-select", "simulator-panels"]) { + for (const control of ["canvas", "logs-drawer", "log-chat", "tool-select", "tool-performance", "tool-app-intel", "app-intelligence-panel", "tool-tracesift", "performance-drawer", "performance-app", "data-device-add", "simulator-panels"]) { assert.ok(resource.contents[0].text.includes(control), `Missing bundled UI control: ${control}`); } assert.ok(!resource.contents[0].text.includes("")); diff --git a/apps/mac/Sources/MobileDev/DeviceLayout.swift b/apps/mac/Sources/MobileDev/DeviceLayout.swift deleted file mode 100644 index a2199610..00000000 --- a/apps/mac/Sources/MobileDev/DeviceLayout.swift +++ /dev/null @@ -1,19 +0,0 @@ -/// Which device platforms are visible. Raw values match the web page's layout names. -enum DeviceLayout: String { - case ios - case android - case both - case none - - init(showsIOS: Bool, showsAndroid: Bool) { - switch (showsIOS, showsAndroid) { - case (true, true): self = .both - case (true, false): self = .ios - case (false, true): self = .android - case (false, false): self = .none - } - } - - var showsIOS: Bool { self == .ios || self == .both } - var showsAndroid: Bool { self == .android || self == .both } -} diff --git a/apps/mac/Sources/MobileDev/PageBridge.swift b/apps/mac/Sources/MobileDev/PageBridge.swift index 90564d42..e52ea008 100644 --- a/apps/mac/Sources/MobileDev/PageBridge.swift +++ b/apps/mac/Sources/MobileDev/PageBridge.swift @@ -40,12 +40,8 @@ final class PageBridge: NSObject, WKScriptMessageHandler { webView.evaluateJavaScript("window.mobileDevShell?.selectTool(\(argument))", completionHandler: nil) } - func select(layout: DeviceLayout) { - webView.evaluateJavaScript("window.mobileDevShell?.selectLayout('\(layout.rawValue)')", completionHandler: nil) - } - - func setTitlebarInset(_ size: CGSize) { - webView.evaluateJavaScript("window.mobileDevShell?.setTitlebarInset(\(size.width), \(size.height))", completionHandler: nil) + func setTitlebarHeight(_ height: CGFloat) { + webView.evaluateJavaScript("window.mobileDevShell?.setTitlebarHeight(\(height))", completionHandler: nil) } func userContentController(_ controller: WKUserContentController, didReceive message: WKScriptMessage) { diff --git a/apps/mac/Sources/MobileDev/ShellMessage.swift b/apps/mac/Sources/MobileDev/ShellMessage.swift index 41aaffb1..2ee21a1c 100644 --- a/apps/mac/Sources/MobileDev/ShellMessage.swift +++ b/apps/mac/Sources/MobileDev/ShellMessage.swift @@ -2,8 +2,6 @@ enum ShellMessage { /// The page connected to the server and its device panels are available. case ready - /// The page chose a layout itself, for example after the server opened a device. - case layout(DeviceLayout) case error(String) init?(body: Any) { @@ -11,9 +9,6 @@ enum ShellMessage { switch type { case "ready": self = .ready - case "layout": - guard let raw = fields["layout"] as? String, let layout = DeviceLayout(rawValue: raw) else { return nil } - self = .layout(layout) case "error": self = .error(fields["message"] as? String ?? "The page reported an error.") default: diff --git a/apps/mac/Sources/MobileDev/SidebarView.swift b/apps/mac/Sources/MobileDev/SidebarView.swift index bcc05e58..c4146cae 100644 --- a/apps/mac/Sources/MobileDev/SidebarView.swift +++ b/apps/mac/Sources/MobileDev/SidebarView.swift @@ -10,14 +10,6 @@ struct SidebarView: View { Label(tool.title, systemImage: tool.systemImage).tag(tool) } } - Section("Devices") { - Toggle(isOn: Binding(get: { model.layout.showsIOS }, set: { model.setShowsIOS($0) })) { - Label("iOS", systemImage: "iphone") - } - Toggle(isOn: Binding(get: { model.layout.showsAndroid }, set: { model.setShowsAndroid($0) })) { - Label("Android", systemImage: "candybarphone") - } - } } .listStyle(.sidebar) .safeAreaInset(edge: .bottom) { ServerStatusView(model: model) } diff --git a/apps/mac/Sources/MobileDev/WindowControls.swift b/apps/mac/Sources/MobileDev/WindowControls.swift index d9a2fbc7..c975d705 100644 --- a/apps/mac/Sources/MobileDev/WindowControls.swift +++ b/apps/mac/Sources/MobileDev/WindowControls.swift @@ -1,8 +1,6 @@ import CoreGraphics -/// The area the traffic lights and the system sidebar button cover at the top-left -/// of the detail column once the sidebar is collapsed, in points. +/// Height reserved for the native window controls when the sidebar is collapsed. enum WindowControls { - static let width: CGFloat = 144 static let height: CGFloat = 52 } diff --git a/apps/mac/Sources/MobileDev/WorkspaceModel.swift b/apps/mac/Sources/MobileDev/WorkspaceModel.swift index c5606f7c..a7ebba28 100644 --- a/apps/mac/Sources/MobileDev/WorkspaceModel.swift +++ b/apps/mac/Sources/MobileDev/WorkspaceModel.swift @@ -7,8 +7,6 @@ import os @Observable final class WorkspaceModel { private(set) var tool: Tool? = .logs - /// The page chooses the first layout from the devices it finds and reports it. - private(set) var layout: DeviceLayout = .none private(set) var status: ServerStatus = .starting { didSet { log.info("Status: \(self.status.label, privacy: .public)") } } @@ -33,12 +31,9 @@ final class WorkspaceModel { /// Moves the page's top-left controls clear of the window controls while the sidebar is collapsed. func setSidebarVisible(_ visible: Bool) { sidebarVisible = visible - page.setTitlebarInset(visible ? .zero : CGSize(width: WindowControls.width, height: WindowControls.height)) + page.setTitlebarHeight(visible ? 0 : WindowControls.height) } - func setShowsIOS(_ shows: Bool) { select(layout: DeviceLayout(showsIOS: shows, showsAndroid: layout.showsAndroid)) } - func setShowsAndroid(_ shows: Bool) { select(layout: DeviceLayout(showsIOS: layout.showsIOS, showsAndroid: shows)) } - /// Restarts the server and reloads the page, for example after the server exits. func restart() { server?.stop() @@ -48,12 +43,6 @@ final class WorkspaceModel { func stop() { server?.stop() } - private func select(layout: DeviceLayout) { - guard layout != self.layout else { return } - self.layout = layout - page.select(layout: layout) - } - private func start() { status = .starting let process: ServerProcess @@ -98,9 +87,6 @@ final class WorkspaceModel { page.select(tool: tool) setSidebarVisible(sidebarVisible) SmokeSnapshot.capture(page.webView) - case .layout(let layout): - // The page already applied this layout; reflect it without sending it back. - self.layout = layout case .error(let message): status = .failed(message) } diff --git a/apps/mac/web/mac-bridge.ts b/apps/mac/web/mac-bridge.ts index 3259fdaa..dd2d5df4 100644 --- a/apps/mac/web/mac-bridge.ts +++ b/apps/mac/web/mac-bridge.ts @@ -7,7 +7,6 @@ import { PLUGIN_VERSION } from "@mobile-dev/shared/version.ts"; type ShellMessage = | { type: "ready" } - | { type: "layout"; layout: string } | { type: "tool"; tool: string } | { type: "error"; message: string }; diff --git a/apps/mac/web/mac-workspace.tsx b/apps/mac/web/mac-workspace.tsx index 86afbcb6..96bb350e 100644 --- a/apps/mac/web/mac-workspace.tsx +++ b/apps/mac/web/mac-workspace.tsx @@ -1,55 +1,35 @@ -import { useEffect } from "react"; +import { useEffect, useSyncExternalStore } from "react"; import { useGroupRef } from "react-resizable-panels"; import type { ToolName, WorkspaceTools } from "@mobile-dev/ui/workspace-tools.ts"; -import type { DeviceLayout } from "@mobile-dev/ui/device-layout.ts"; +import type { DeviceWorkspace } from "@mobile-dev/ui/device-workspace.ts"; import { LogsView } from "@mobile-dev/ui/components/logs-view.tsx"; import { PerformanceView } from "@mobile-dev/ui/components/performance-view.tsx"; -import { SimulatorView } from "@mobile-dev/ui/components/simulator-view.tsx"; +import { DevicePicker, EmptyDeviceTabBar } from "@mobile-dev/ui/components/device-picker.tsx"; +import { DevicePanes } from "@mobile-dev/ui/components/device-panes.tsx"; import { StorageView } from "@mobile-dev/ui/components/storage-view.tsx"; import { TraceSiftView } from "@mobile-dev/ui/components/tracesift-view.tsx"; import { AppIntelligenceView } from "@mobile-dev/ui/components/app-intelligence-view.tsx"; import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@mobile-dev/ui/components/ui/resizable.tsx"; - -/** - * The Mac app's content area. The native sidebar chooses the tool and the visible - * platforms, so this view has no toolbar of its own: a tool on the left, the - * device panels on the right. Both device panels stay mounted, because their - * controllers attach to the DOM once. - */ -export function MacWorkspace({ panels, tool, layout }: { panels: WorkspaceTools; tool?: ToolName; layout: DeviceLayout }) { +export function MacWorkspace({ panels, tool, devices }: { panels: WorkspaceTools; tool?: ToolName; devices: DeviceWorkspace }) { const workspaceGroup = useGroupRef(); - const deviceGroup = useGroupRef(); + const state = useSyncExternalStore(devices.subscribe, devices.getSnapshot); + const hasDevices = state.panes.length > 0; + const size = tool === undefined ? 100 : Math.min(80, state.visible.length * 40); useEffect(() => { - const devices = layout === "none" ? 0 : tool === undefined ? 100 : 40; - workspaceGroup.current?.setLayout({ "mac-tools": 100 - devices, "mac-devices": devices }); - if (layout !== "none") deviceGroup.current?.setLayout({ "mac-ios": layout === "android" ? 0 : layout === "both" ? 50 : 100, "mac-android": layout === "ios" ? 0 : layout === "both" ? 50 : 100 }); - }, [tool, layout]); - const leading = tool !== undefined ? "tool" : layout === "android" ? "android" : "ios"; - const leadingClass = (panel: string) => panel === leading ? "mac-leading h-full" : "h-full"; + workspaceGroup.current?.setLayout({ "mac-tools": 100 - size, "mac-devices": size }); + }, [size]); const toolView = tool === "logs" ? : tool === "performance" ? : tool === "storage" ? : tool === "app-intel" ? - : tool === "tracesift" ? - : ; - return
+ : tool === "tracesift" ? : null; + return
+ {!hasDevices && } -
{toolView}
-
-
; -} - -function EmptyTool({ layout }: { layout: DeviceLayout }) { - return
- {layout === "none" ? "Choose a device platform or a tool in the sidebar." : "Choose a tool in the sidebar."} -
; +
; } diff --git a/apps/mac/web/mac.css b/apps/mac/web/mac.css index ab3747d3..4f0a2ede 100644 --- a/apps/mac/web/mac.css +++ b/apps/mac/web/mac.css @@ -1,11 +1,2 @@ -/* While the native sidebar is collapsed, the window's traffic lights and sidebar - button sit over the page's top-left corner. Swift sets --mac-titlebar-inset to - their width, and the leading panel's top row makes room for them. */ -.mac-leading .panel-toolbar { - padding-left: calc(var(--mac-titlebar-inset, 0px) + 0.5rem); - transition: padding-left 150ms ease; -} -/* Views without a toolbar row, such as TraceSift, move below the controls instead. */ -.mac-leading:not(:has(.panel-toolbar)) { - padding-top: var(--mac-titlebar-height, 0px); -} +/* Keep the tab strip clear of native window controls when the sidebar collapses. */ +.mac-workspace { padding-top: var(--mac-titlebar-height, 0px); } diff --git a/apps/mac/web/main.tsx b/apps/mac/web/main.tsx index a1645fd9..2e813053 100644 --- a/apps/mac/web/main.tsx +++ b/apps/mac/web/main.tsx @@ -5,40 +5,27 @@ import "./mac.css"; import { applyDocumentTheme } from "@modelcontextprotocol/ext-apps"; import { createRoot } from "react-dom/client"; import { flushSync } from "react-dom"; -import type { DeviceLayout } from "@mobile-dev/ui/device-layout.ts"; import { DeviceWorkspace } from "@mobile-dev/ui/device-workspace.ts"; import { ErrorBoundary, captureUiError, startUiTelemetry, stopUiTelemetry } from "@mobile-dev/ui/telemetry.ts"; import { isToolName, WorkspaceTools, type ToolName } from "@mobile-dev/ui/workspace-tools.ts"; import { MacHostBridge, postToShell } from "./mac-bridge.ts"; import { MacWorkspace } from "./mac-workspace.tsx"; -const layouts = ["ios", "android", "both", "none"] as const; -const isLayout = (value: unknown): value is DeviceLayout => layouts.includes(value as DeviceLayout); - const bridge = new MacHostBridge(); startUiTelemetry(bridge); // The Mac app has no chat, so the panels have no host attachments. const panels = WorkspaceTools.create(bridge); let tool: ToolName | undefined; -let layout: DeviceLayout = "none"; +const devices = new DeviceWorkspace(bridge, panels); const reactRoot = createRoot(document.getElementById("root")!); function render() { reactRoot.render(Mobile Dev could not render. Reload the window to try again.

}> - +
); } flushSync(render); -const devices = new DeviceWorkspace(bridge, panels, { - onAutomaticLayout: next => { - layout = next; - render(); - postToShell({ type: "layout", layout: next }); - }, - connectionFailed, -}); panels.logs.setLayout(true); -devices.changeLayout("none"); function connectionFailed(error: unknown) { captureUiError(error, "host.connect"); @@ -55,24 +42,15 @@ function selectTool(next: ToolName | undefined) { render(); } -function selectLayout(next: DeviceLayout) { - if (next === layout) return; - layout = next; - devices.changeLayout(next, true); - render(); -} - declare global { interface Window { /** The native sidebar drives the content area through these calls. */ - mobileDevShell?: { selectTool(tool: string | null): void; selectLayout(layout: string): void; setTitlebarInset(width: number, height: number): void }; + mobileDevShell?: { selectTool(tool: string | null): void; setTitlebarHeight(height: number): void }; } } window.mobileDevShell = { selectTool: value => selectTool(isToolName(value) ? value : undefined), - selectLayout: value => { if (isLayout(value)) selectLayout(value); }, - setTitlebarInset: (width, height) => { - document.documentElement.style.setProperty("--mac-titlebar-inset", `${Math.max(0, width)}px`); + setTitlebarHeight: height => { document.documentElement.style.setProperty("--mac-titlebar-height", `${Math.max(0, height)}px`); }, }; @@ -97,9 +75,7 @@ void (async () => { panels.setAvailable(true); await devices.setAvailable(true); postToShell({ type: "ready" }); - // Codex opens the panel through a tool call that names a target. The app has - // none, so the panels restore or pick devices and choose the layout themselves - // unless the sidebar changes it first. + // The standalone app opens without a target and can select a running device. await devices.open({}); } catch (error) { connectionFailed(error); diff --git a/docs/devices.md b/docs/devices.md index 95a2e175..5ca40499 100644 --- a/docs/devices.md +++ b/docs/devices.md @@ -16,21 +16,21 @@ Android tools look for the SDK in `ANDROID_HOME`, `ANDROID_SDK_ROOT`, and the de ## Device panel -Open a new chat after installing. Open Mobile Dev in the sidebar or call `mobile_open_workspace` for the fullscreen view. Call `mobile_open_simulator` for the panel beside a chat. Both opening tools accept optional `platform`, `kind`, and discovered `deviceId` arguments. For example, `{ platform: "android", kind: "emulator" }` opens Android and selects an emulator before connecting; `kind: "physical"` selects a connected phone. An unavailable requested target stays unselected, with a message and the device picker available. Opening never boots a device. Without targeting, iOS opens when both platforms have running devices; Android opens when it has the only running device. Later manual platform or device selections replace the opening choice. +Open a new chat after installing. Open Mobile Dev in the sidebar or call `mobile_open_workspace` for the fullscreen view. Call `mobile_open_simulator` for the panel beside a chat. Both opening tools accept optional `platform`, `kind`, and discovered `deviceId` arguments. For example, `{ platform: "android", kind: "emulator" }` opens Android and selects an emulator before connecting; `kind: "physical"` selects a connected phone. An unavailable requested target stays unselected, with a message and the device picker available. Opening never boots a device. Without targeting, iOS opens when both platforms have running devices; Android opens when it has the only running device. Later manual device selections replace the opening choice. -Enable both platforms from the platform menu to show the panels side by side. Each panel has a device dropdown, Home, App Switcher, and Screenshot. Pick a device in each panel. In the sidebar panel, the bar under the simulators holds the tools menu on the left and the platform menu on the right; fullscreen shows them above the tools. Use the platform menu to show either, both, or neither simulator. Selecting a device boots it if needed, then connects its screen. A selected running device connects automatically. The panel uses Apple’s device bezel and screen mask from the installed DeviceKit assets, with a simple frame as a fallback when assets are unavailable. Use the settings button at the bottom right for appearance, text size, location, and the device frame. iOS also offers contrast; Android offers rotation. The menu shows only settings supported by the bundled backend. Click the screen to type or drag. Closing the panel closes its stream. +Choose **+ Add device** in a tab strip and select the screens to display. The menu groups devices into iOS and Android columns. Choosing a device closes the menu. Open **+ Add device** again to choose another. Selecting a stopped simulator or emulator starts it. Each screen has its own Home, App Switcher, Screenshot, and Select controls. Each new device opens in a split to the right of that group. Drag a tab to the left, right, top, or bottom edge of a view to split it. Drop it in the center to join that group or on the tab strip to reorder it. Drag a divider to resize the views. Drag the empty part of a tab strip to move the whole group. Each group streams its selected tab. Deselecting a device closes its screen and leaves the device running. The panel uses Apple’s device bezel and screen mask from the installed DeviceKit assets, with a simple frame as a fallback when assets are unavailable. Use the settings button at the bottom right for appearance, text size, location, and the device frame. iOS also offers contrast; Android offers rotation. The menu shows only settings supported by the bundled backend. Click the screen to type or drag. Closing the panel closes its stream. Click an iOS simulator or Android screen to focus it, then press **Ctrl+V** on Windows or **Command-V** on macOS to paste text into the device. Paste accepts up to 4,096 printable US-ASCII characters. Empty or non-text clipboard content sends nothing; line breaks, other characters, and oversized text show a notice without sending partial text. Paste is disabled during Select, while input is blocked, and until the stream is ready. Physical iOS keyboard input remains unavailable. Use Select in the simulator toolbar to pause the screen. Hover to outline a component, then click to add a note. React Native development apps can supply runtime elements when accessibility omits a view. Drag to mark a region when neither source exposes it. Saved notes leave numbered blue bubbles. Notes attach text and available element details to your next chat message. The captured screen stays local for editing; annotations never attach screenshots. Click a bubble to edit or remove a note, or use Send to chat to send all notes for that device. If chat is unavailable, the panel keeps the notes and retries when you return. A sent or cleared batch starts again at 1. -The iOS dropdown shows **Connected devices** first, with USB or Wi-Fi labels, then **Simulators**. It refreshes every three seconds while the iOS panel is visible, and when opening the dropdown. Selecting a physical device opens interactive screen mirroring through its paired developer connection. The phone sends HEVC video; a bundled native Node-API addon assembles compressed frames and transfers them into Node without copying the frame payload, then the panel decodes them through WebCodecs. MCP serializes the compressed bytes as base64, so the full path is not zero copy. The capture queue is limited to eight frames or 4 MiB and requests a keyframe after overflow. Physical iOS supports pointer taps, long presses, and drags through CoreDevice UniversalHID on the same developer tunnel. Input starts after a fresh video frame, uses normalized touchscreen coordinates, and releases held touches when the stream closes or resets. Screenshot captures the displayed mirrored frame as a PNG, attaches it to chat, and copies the same image to the macOS clipboard. Select annotates screen regions using the mirrored frame's pixel coordinates; native accessibility component names are unavailable. Both controls require a connected device and a ready video frame. Keyboard and hardware-button controls remain disabled. CPU and memory monitoring can attach to an already running development app on a paired iOS 17.4+ device. Mirroring requires Developer Mode and a host with HEVC WebCodecs support. `mobile_list_ios_devices` also returns remembered disconnected devices with their connection state; the picker shows connected devices only. Discovery errors remain visible while available simulators continue to work. +The iOS column shows **Connected devices** first, with USB or Wi-Fi labels, then **Simulators**. It refreshes every three seconds while the iOS panel is visible, and when opening the dropdown. Selecting a physical device opens interactive screen mirroring through its paired developer connection. The phone sends HEVC video; a bundled native Node-API addon assembles compressed frames and transfers them into Node without copying the frame payload, then the panel decodes them through WebCodecs. MCP serializes the compressed bytes as base64, so the full path is not zero copy. The capture queue is limited to eight frames or 4 MiB and requests a keyframe after overflow. Physical iOS supports pointer taps, long presses, and drags through CoreDevice UniversalHID on the same developer tunnel. Input starts after a fresh video frame, uses normalized touchscreen coordinates, and releases held touches when the stream closes or resets. Screenshot captures the displayed mirrored frame as a PNG, attaches it to chat, and copies the same image to the macOS clipboard. Select annotates screen regions using the mirrored frame's pixel coordinates; native accessibility component names are unavailable. Both controls require a connected device and a ready video frame. Keyboard and hardware-button controls remain disabled. CPU and memory monitoring can attach to an already running development app on a paired iOS 17.4+ device. Mirroring requires Developer Mode and a host with HEVC WebCodecs support. `mobile_list_ios_devices` also returns remembered disconnected devices with their connection state; the picker shows connected devices only. Discovery errors remain visible while available simulators continue to work. Panels in multiple chats share one physical iOS capture through a local, per-user service. Each panel has an independent queue limited to eight frames or 4 MiB. Opening another panel requests a fresh keyframe without resetting the hardware stream or other panels’ decoders. A slow panel drops its own backlog and requests recovery when it resumes reading; other panels continue receiving frames. Closing a panel removes only its subscription. The final subscription closes the native capture, and the service exits after 30 idle seconds. Concurrent gestures are serialized, and a held touch belongs to the panel that started it. Device Hub runs its own hardware capture and cannot subscribe to this service; close its mirroring window while using Mobile Dev. Physical iOS mirroring uses the same Apple DeviceKit bezel and framebuffer mask as the matching simulator model. Discovery preserves the hardware product type, which selects the installed Xcode device profile. The bundled Baguette CLI renders its bezel without starting a simulator, and macOS rasterizes its mask. These assets are cached per model outside the video path. A device type stands for its own model identifier plus any regional or cellular variants its profile lists. Older Xcode profiles list none. If Xcode has no matching device type or the render fails, the screen mirrors without a frame, and the plugin looks for that model's frame again after five minutes. -Ask the agent to inspect or control the app on the selected device. The panel shares both visible device IDs and platforms with the chat. Click a device panel to make it the active device for logs. Hiding a simulator keeps the current log source and buffered logs. Use Mobile Dev's screenshot, accessibility and input tools for the selected platform. Baguette streams iOS and serve-emu streams Android in the panel. +Ask the agent to inspect or control the app on the selected device. The panel shares all visible device IDs and their platforms with the chat. Click a device panel to make it the active device for logs. Hiding a simulator keeps the current log source and buffered logs. Use Mobile Dev's screenshot, accessibility and input tools for the selected platform. Baguette streams iOS and serve-emu streams Android in the panel. For mobile app development, the bundled skill tells the agent to open the panel beside the chat before the first device launch, or reuse an open panel. It covers iOS, Android, Expo, React Native, and SwiftUI work. The agent follows your device choice, reuses a suitable running device, or chooses and boots an installed simulator or AVD. It asks only when the choice changes what the task needs. The app project's own tools build, install, and launch the app on that device; the agent reuses an existing app dev server. @@ -65,7 +65,7 @@ For a custom SDK, set `ANDROID_HOME` to the **Android SDK Location** shown in SD The Android panel lists devices without booting one. Selecting an AVD boots it if needed, then starts the bundled Node.js serve-emu CLI on a private loopback port. Home, Back, Recents, Lock, pointer gestures, and typing use scrcpy's control socket. Closing the panel leaves the emulator running. AVDs start without a separate emulator window. A failed emulator process reports its exit right away instead of waiting for the boot timeout. -The Android dropdown shows **Connected devices** first, with USB or Wi-Fi labels, then **Emulators**. It refreshes every three seconds while the Android panel is visible, and when opening the dropdown. Physical devices use ADB discovery: enable USB debugging and authorize the computer, or pair the device for wireless debugging. Offline and unauthorized devices remain visible with their state. Emulators keep their AVD name while unauthorized. An emulator restored from a quick-boot snapshot can stay unauthorized because adb does not repeat the key exchange; the panel reconnects adb at most every 5 seconds while an AVD boots, and for up to 15 seconds after you select an already running emulator. Selecting an authorized phone connects its screen and shares its serial and transport with the chat. Bundled scrcpy mirrors and controls the phone without installing a companion app. Physical Android devices support the existing screen, input, screenshot, native log, and performance tools; emulator boot and stop controls do not apply to them. +The Android column shows **Connected devices** first, with USB or Wi-Fi labels, then **Emulators**. It refreshes every three seconds while the Android panel is visible, and when opening the dropdown. Physical devices use ADB discovery: enable USB debugging and authorize the computer, or pair the device for wireless debugging. Offline and unauthorized devices remain visible with their state. Emulators keep their AVD name while unauthorized. An emulator restored from a quick-boot snapshot can stay unauthorized because adb does not repeat the key exchange; the panel reconnects adb at most every 5 seconds while an AVD boots, and for up to 15 seconds after you select an already running emulator. Selecting an authorized phone connects its screen and shares its serial and transport with the chat. Bundled scrcpy mirrors and controls the phone without installing a companion app. Physical Android devices support the existing screen, input, screenshot, native log, and performance tools; emulator boot and stop controls do not apply to them. Android H.264 packets travel through MCP resource reads. The panel decodes them with WebCodecs, so the host must support H.264 `VideoDecoder`. Each device gets its own backend and each panel gets its own stream session. Decoder errors and video backlog request a fresh keyframe on the same connection. The panel drops delta frames until it can decode that keyframe. Requests have a cooldown, and stale decoder callbacks cannot repaint a closed stream. The plugin reuses a matching serve-emu server at port 3300. Set `SERVE_EMU_URL` to reuse another loopback HTTP server; it must already stream the selected serial. Closing MCP stops only backends the plugin started. diff --git a/docs/telemetry.md b/docs/telemetry.md index a1f26c7e..4eecd5f0 100644 --- a/docs/telemetry.md +++ b/docs/telemetry.md @@ -543,6 +543,8 @@ Since 0.1.69, inspection timing also includes the bounded Metro source-map looku Since 0.1.92, Android inspection timing also includes the full-resolution display-size read and bounds scaling. Existing inspection, fallback and tree-processing coverage stays on the active selection path. Display sizes and element bounds remain local. +The device workspace records the number of visible screens in the numeric gauge `ui.devices.visible`. Since 0.1.193 this counts the selected tab in each split. A background tab suspends its stream and frame measurements until it becomes visible. The layout attribute describes the platforms shown. Workspaces with multiple screens omit device platform and kind attributes because their timing windows can contain work from several devices. Platform-specific frame counters continue to count each painted frame. + Since 0.1.93, `ui.video.paint` and the platform frame counters also cover frames drawn to the local buffer while Select freezes the visible screen. These remain bounded plugin processing measurements, not device FPS. Recovery uses the same surface attribution and timing units; screenshots and element details remain local. `ui.annotations.send` measures the host send round trip, including composer retries. Outcome counters distinguish success, a missing composer, timeout and other failures. Unexpected send failures use a fixed error message. No message content goes to Sentry. A timeout keeps notes for a manual retry; it never triggers an automatic resend, since delivery may have succeeded without acknowledgement. diff --git a/package-lock.json b/package-lock.json index 2395f3b0..09142fa7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mobile-dev", - "version": "0.1.192", + "version": "0.1.193", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "mobile-dev", - "version": "0.1.192", + "version": "0.1.193", "workspaces": [ "packages/shared", "packages/core", @@ -34,6 +34,7 @@ "ajv": "8.20.0", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", + "dockview-react": "^8.9.1", "enhanced-resolve": "^5.26.1", "lucide-react": "^1.49.0", "radix-ui": "^1.6.7", @@ -6752,6 +6753,34 @@ "node": ">=0.3.1" } }, + "node_modules/dockview": { + "version": "8.9.1", + "resolved": "https://registry.npmjs.org/dockview/-/dockview-8.9.1.tgz", + "integrity": "sha512-y35BxYANBtHJ4q7AIkd2c1Oh2pPx3dsaMhm6s4YvMXyIWlklxHRZupXtN6bS8QuJ/hmy/5ih/Ow2oARbEx4Yog==", + "license": "MIT", + "dependencies": { + "dockview-core": "^8.9.1" + } + }, + "node_modules/dockview-core": { + "version": "8.9.1", + "resolved": "https://registry.npmjs.org/dockview-core/-/dockview-core-8.9.1.tgz", + "integrity": "sha512-OzqB63P65qeSquFoyYjQi5yT85ERcmceaJ0+YdQL68IZJmBd5kAfe4UD9bl3xILuXJ1tlXIoExdZ+vLpv30u1g==", + "license": "MIT" + }, + "node_modules/dockview-react": { + "version": "8.9.1", + "resolved": "https://registry.npmjs.org/dockview-react/-/dockview-react-8.9.1.tgz", + "integrity": "sha512-xH63jytJwoLPNhK1XohVAQ3RnoWu+wh8U5ISlHQpxQ/jWxS94HuPMDB2JZbszfJ2ziBRafG1XHzrDlyvhIOdCw==", + "license": "MIT", + "dependencies": { + "dockview": "^8.9.1" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0", + "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, "node_modules/dot-prop": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-6.0.1.tgz", diff --git a/package.json b/package.json index a47d5703..27fd73ce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mobile-dev", - "version": "0.1.192", + "version": "0.1.193", "private": true, "workspaces": [ "packages/shared", @@ -89,6 +89,7 @@ "ajv": "8.20.0", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", + "dockview-react": "^8.9.1", "enhanced-resolve": "^5.26.1", "lucide-react": "^1.49.0", "radix-ui": "^1.6.7", diff --git a/packages/core/test/testing-panel-ui.test.ts b/packages/core/test/testing-panel-ui.test.ts index 53986980..50ba4b44 100644 --- a/packages/core/test/testing-panel-ui.test.ts +++ b/packages/core/test/testing-panel-ui.test.ts @@ -35,7 +35,9 @@ test("the element menu renders the runner's own steps over the mirror and record testRecorder.start("udid", "ios"); const root = createRoot(dom.window.document.getElementById("root")!); - await act(async () => { root.render(createElement(TestRecorderOverlay, { store: annotations, platform: "ios" })); }); + const firstMirror = createElement(TestRecorderOverlay, { store: annotations, platform: "ios", deviceId: "udid" }); + const secondMirror = createElement(TestRecorderOverlay, { store: annotations, platform: "ios", deviceId: "another-iphone" }); + await act(async () => { root.render(createElement("div", null, firstMirror, secondMirror)); }); onTeardown(async () => { await act(async () => { root.unmount(); }); await new Promise(resolve => dom.window.requestAnimationFrame(resolve)); @@ -45,6 +47,7 @@ test("the element menu renders the runner's own steps over the mirror and record await act(async () => { await testRecorder.openMenu({ x: 150, y: 420 }); }); assert.ok(menu(), "the right-click opens the menu over the outline"); + assert.equal(dom.window.document.querySelectorAll("[data-element=recorder-menu]").length, 1, "only the recording device shows the menu"); // The selector is named once and rows stay compact; exact code is still available as a tooltip. assert.match(menu()?.textContent ?? "", /Selected element"Go To Explore List" \(button\)/); assert.deepEqual(rows().map(row => row.textContent), [ @@ -109,7 +112,7 @@ test("a row that needs a value asks for it instead of emitting an empty string", }); testRecorder.start("udid", "ios"); const root = createRoot(dom.window.document.getElementById("root")!); - await act(async () => { root.render(createElement(TestRecorderOverlay, { store: annotations, platform: "ios" })); }); + await act(async () => { root.render(createElement(TestRecorderOverlay, { store: annotations, platform: "ios", deviceId: "udid" })); }); onTeardown(async () => { await act(async () => { root.unmount(); }); await new Promise(resolve => dom.window.requestAnimationFrame(resolve)); @@ -329,7 +332,7 @@ test("the element menu survives a tree invalidation that takes the hover outline testRecorder.attach("udid", "ios", { readComponents: async () => [button], screen: () => SCREEN, release: () => undefined }); testRecorder.start("udid", "ios"); const root = createRoot(dom.window.document.getElementById("root")!); - await act(async () => { root.render(createElement(TestRecorderOverlay, { store: annotations, platform: "ios" })); }); + await act(async () => { root.render(createElement(TestRecorderOverlay, { store: annotations, platform: "ios", deviceId: "udid" })); }); onTeardown(async () => { await act(async () => { root.unmount(); }); await new Promise(resolve => dom.window.requestAnimationFrame(resolve)); @@ -363,7 +366,7 @@ test("a coordinate gets the tap row and is told why that is all", async t => { testRecorder.attach("udid", "ios", { readComponents: async () => [button], screen: () => SCREEN, release: () => undefined }); testRecorder.start("udid", "ios"); const root = createRoot(dom.window.document.getElementById("root")!); - await act(async () => { root.render(createElement(TestRecorderOverlay, { store: annotations, platform: "ios" })); }); + await act(async () => { root.render(createElement(TestRecorderOverlay, { store: annotations, platform: "ios", deviceId: "udid" })); }); onTeardown(async () => { await act(async () => { root.unmount(); }); await new Promise(resolve => dom.window.requestAnimationFrame(resolve)); @@ -413,7 +416,7 @@ test("the command list is a submenu of its own, opened by pointing at its row", testRecorder.attach("udid", "ios", { readComponents: async () => [button], screen: () => SCREEN, release: () => undefined }); testRecorder.start("udid", "ios"); const root = createRoot(dom.window.document.getElementById("root")!); - await act(async () => { root.render(createElement(TestRecorderOverlay, { store: annotations, platform: "ios" })); }); + await act(async () => { root.render(createElement(TestRecorderOverlay, { store: annotations, platform: "ios", deviceId: "udid" })); }); onTeardown(async () => { await act(async () => { root.unmount(); }); await new Promise(resolve => dom.window.requestAnimationFrame(resolve)); @@ -481,7 +484,7 @@ test("the agentic branches cascade to the side, and record a sentence with its p }); testRecorder.start("udid", "ios"); const root = createRoot(dom.window.document.getElementById("root")!); - await act(async () => { root.render(createElement(TestRecorderOverlay, { store: annotations, platform: "ios" })); }); + await act(async () => { root.render(createElement(TestRecorderOverlay, { store: annotations, platform: "ios", deviceId: "udid" })); }); onTeardown(async () => { await act(async () => { root.unmount(); }); await new Promise(resolve => dom.window.requestAnimationFrame(resolve)); @@ -615,7 +618,7 @@ test("the recording blocker explains how to show an already-running device", asy await act(async () => { root.render(createElement(TestingView, { panel: panelStub(), deviceApps })); }); - assert.match(dom.window.document.querySelector("[data-testing-blocker]")?.textContent ?? "", /choose Platforms → iOS or Android to show it/); + assert.match(dom.window.document.querySelector("[data-testing-blocker]")?.textContent ?? "", /choose it from Add device/); await act(async () => { root.unmount(); }); }); @@ -698,7 +701,7 @@ test("Record says the mirror is not ready yet, until selection actually is", asy testRecorder.attach("udid", "ios", { readComponents: () => tree, screen: () => SCREEN, release: () => undefined }); const root = createRoot(dom.window.document.getElementById("root")!); - await act(async () => { root.render(createElement(TestRecorderOverlay, { store: annotations, platform: "ios" })); }); + await act(async () => { root.render(createElement(TestRecorderOverlay, { store: annotations, platform: "ios", deviceId: "udid" })); }); onTeardown(async () => { await act(async () => { root.unmount(); }); await new Promise(resolve => dom.window.requestAnimationFrame(resolve)); diff --git a/packages/mcp-app/src/components/workspace.tsx b/packages/mcp-app/src/components/workspace.tsx index 8b66c21c..9a225c7a 100644 --- a/packages/mcp-app/src/components/workspace.tsx +++ b/packages/mcp-app/src/components/workspace.tsx @@ -3,7 +3,8 @@ import { useEffect, useRef, useState, useSyncExternalStore } from "react"; import type { ReactNode } from "react"; import type { ToolName, WorkspaceTools } from "@mobile-dev/ui/workspace-tools.ts"; import { PerformanceView } from "@mobile-dev/ui/components/performance-view.tsx"; -import { SimulatorView } from "@mobile-dev/ui/components/simulator-view.tsx"; +import { DevicePanes } from "@mobile-dev/ui/components/device-panes.tsx"; +import { DevicePicker, EmptyDeviceTabBar } from "@mobile-dev/ui/components/device-picker.tsx"; import { LogsView } from "@mobile-dev/ui/components/logs-view.tsx"; import { StorageView } from "@mobile-dev/ui/components/storage-view.tsx"; import { TraceSiftView } from "@mobile-dev/ui/components/tracesift-view.tsx"; @@ -11,7 +12,7 @@ import { AppIntelligenceView } from "@mobile-dev/ui/components/app-intelligence- import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@mobile-dev/ui/components/ui/base-select.tsx"; import { Button } from "@mobile-dev/ui/components/ui/button.tsx"; -import { usePanelRef, useGroupRef } from "react-resizable-panels"; +import { usePanelRef, useGroupRef, type Layout } from "react-resizable-panels"; import { ResizableHandle, ResizablePanel, ResizablePanelGroup } from "@mobile-dev/ui/components/ui/resizable.tsx"; import { useMediaQuery } from "@mobile-dev/ui/components/use-media-query.ts"; import { setUiSurface, setUiTelemetryContext } from "@mobile-dev/ui/telemetry.ts"; @@ -20,8 +21,7 @@ import { RecordingCard } from "@mobile-dev/ui/components/recording-card.tsx"; import { AppFlowView } from "@mobile-dev/ui/components/app-flow-view.tsx"; import { TestingView } from "@mobile-dev/ui/components/testing-view.tsx"; -import type { DeviceLayout } from "@mobile-dev/ui/device-layout.ts"; -export type { DeviceLayout } from "@mobile-dev/ui/device-layout.ts"; +import type { DeviceWorkspace } from "@mobile-dev/ui/device-workspace.ts"; // Menu item IDs stay literal so tests and the package smoke check can find them in the bundle. const tools = { @@ -36,7 +36,7 @@ const tools = { type Tool = keyof typeof tools; const isTool = (value: string): value is Tool => value in tools; -export function Workspace({ panels, recordingController, banner, displayModeControl, contextControl, automaticLayout, automaticTool, automaticToolRevision = 0, onLayout }: { panels: WorkspaceTools; recordingController: RecordingController; banner?: ReactNode; displayModeControl?: ReactNode; contextControl?: ReactNode; automaticLayout?: DeviceLayout; automaticTool?: ToolName; automaticToolRevision?: number; onLayout: (layout: DeviceLayout, manual?: boolean) => void }) { +export function Workspace({ panels, recordingController, banner, displayModeControl, contextControl, automaticTool, automaticToolRevision = 0, devices }: { panels: WorkspaceTools; recordingController: RecordingController; banner?: ReactNode; displayModeControl?: ReactNode; contextControl?: ReactNode; automaticTool?: ToolName; automaticToolRevision?: number; devices: DeviceWorkspace }) { const { logs, performance, storage, tracesift } = panels; const appIntel = panels["app-intel"]; const appFlow = panels["app-flow"]; @@ -44,44 +44,23 @@ export function Workspace({ panels, recordingController, banner, displayModeCont const [tool, setTool] = useState("logs"); const [savedVisible, setSavedVisible] = useState(false); const [simulatorsCollapsed, setSimulatorsCollapsed] = useState(false); - const [layout, setLayout] = useState(automaticLayout ?? "none"); - const manualLayout = useRef(false); - const layoutRef = useRef(layout); - layoutRef.current = layout; + const deviceState = useSyncExternalStore(devices.subscribe, devices.getSnapshot); const recordingState = useSyncExternalStore(recordingController.subscribe, recordingController.getSnapshot); - useEffect(() => { - if (automaticLayout === undefined || manualLayout.current || recordingState.recording !== undefined) return; - setLayout(automaticLayout); - onLayout(automaticLayout); - }, [automaticLayout]); useEffect(() => { if (recordingState.recording === undefined) return; - manualLayout.current = true; setTool("performance"); setSavedVisible(true); - setLayout("none"); - onLayout("none"); + devices.clear(); panels.hide(); }, [recordingState.recording?.id]); // An agent recording opens the Testing Studio tab for the user: they asked their agent for a test, and // the steps appearing one at a time are the whole point. Which tool is on screen is this // component's own state, so the panel asks rather than reaches. useEffect(() => testing.onAgentRecordingStarted(() => { - manualLayout.current = true; setTool("testing"); setSavedVisible(false); panels.show("testing"); }), [testing]); - // Picking a lane in the results shows that lane's platform. Only a single-mirror layout moves, - // and only on the pick itself: the manual platform picker and a mirror switched back by hand - // are never overridden. - useEffect(() => testing.onLanePicked(platform => { - const current = layoutRef.current; - if (current === "both" || current === "none" || current === platform) return; - manualLayout.current = true; - setLayout(platform); - onLayout(platform, true); - }), [testing]); const performanceState = useSyncExternalStore(performance.subscribe, performance.getSnapshot); const wide = useMediaQuery("(min-width: 900px)"); const fullscreen = document.documentElement.dataset.view === "workspace"; @@ -126,76 +105,43 @@ export function Workspace({ panels, recordingController, banner, displayModeCont useEffect(() => { if (automaticTool) { setTool(automaticTool); setSavedVisible(false); panels.show(automaticTool); } }, [automaticTool, automaticToolRevision]); const logsRef = usePanelRef(); const simulatorsRef = usePanelRef(); - const simulatorGroupRef = useGroupRef(); + const showDevices = deviceState.panes.length > 0 || !!deviceState.message || !open; + const deviceShare = testingOpen ? 25 : split ? Math.min(80, 36 * Math.max(1, deviceState.visible.length)) : 60; const workspaceGroupRef = useGroupRef(); - useEffect(() => { if (open) logsRef.current?.expand(); else logsRef.current?.collapse(); }, [open, split, layout]); + const resizedLayout = useRef(undefined); + useEffect(() => { if (open) logsRef.current?.expand(); else logsRef.current?.collapse(); }, [open, split]); useEffect(() => { - let simulatorsPending = layout !== "none"; - let workspacePending = true; - // Hidden hosts defer group initialization; retain the request until the groups are measurable. + // Hidden hosts defer group initialization until the page becomes measurable. + const container = document.getElementById("workspace-panels")!; + let pending = true; + resizedLayout.current = undefined; const applyLayout = () => { - const simulators = simulatorGroupRef.current; - if (simulatorsPending && simulators) { - const current = simulators.getLayout(); - const panelIds = Object.keys(current); - if (panelIds.length > 0) { - simulatorsPending = false; - simulators.setLayout({ "ios-resizable": layout === "android" ? 0 : layout === "both" ? 50 : 100, "android-resizable": layout === "ios" ? 0 : layout === "both" ? 50 : 100 }); - } - } + if (!container.clientWidth || !container.clientHeight) { pending = true; return; } + if (!pending) return; const workspace = workspaceGroupRef.current; - if (workspacePending && workspace) { - const current = workspace.getLayout(); - const panelIds = Object.keys(current); - if (panelIds.length > 0) { - workspacePending = false; - // The Testing Studio panel is read as three panes — mirror, preview, steps — and the preview - // and the steps split the tools pane 60/40 of their own accord. A quarter of the - // workspace for the mirror is what makes those 45% and 30%: the mirror is tapped, while - // the two beside it are read, and reading a generated file needs the room. - const toolsShare = testingOpen ? 75 : split ? 64 : 40; - workspace.setLayout({ "tools-resizable": toolsShare, "simulators-resizable": 100 - toolsShare }); - // No visible platform is the panel being collapsed, not a share of 0. A share is the - // group's last *requested* layout, which it re-applies whenever a panel's constraints - // change — and the Testing Studio panel changes them as it opens. A 0 requested while nothing - // was bootable therefore outlived the device: discovery selected a simulator, the - // platform selector read "iOS", and the mirror stayed shut until the user toggled the - // platform off and on again. Collapsing says the same thing in the group's own terms, - // so expanding it is all that finding a device has to do. - if (layout === "none") simulatorsRef.current?.collapse(); - else simulatorsRef.current?.expand(); - if (isOpen() === false) logsRef.current?.collapse(); - } - } - if (simulatorsPending === false && workspacePending === false) observer.disconnect(); + if (!workspace) return; + const current = workspace.getLayout(); + if (Object.keys(current).length === 0) return; + pending = false; + const share = showDevices ? deviceShare : 0; + workspace.setLayout(resizedLayout.current ?? { "tools-resizable": 100 - share, "simulators-resizable": share }); + if (showDevices) simulatorsRef.current?.expand(); + else simulatorsRef.current?.collapse(); + if (isOpen() === false) logsRef.current?.collapse(); }; const observer = new ResizeObserver(applyLayout); - observer.observe(document.getElementById("simulator-panels")!); - observer.observe(document.getElementById("workspace-panels")!); + observer.observe(container); applyLayout(); - // And again on the next frame, because the group re-derives its own layout from the panels' - // defaults when their constraints change — which is what opening the Testing Studio panel does, since - // its mirror and its tools declare sizes of their own. Asking during the commit is asking - // before that, so the answer was thrown away; the frame after it is when it sticks. - const frame = requestAnimationFrame(() => { workspacePending = true; simulatorsPending = layout !== "none"; applyLayout(); }); + // Testing Studio changes the panel constraints during layout. Reapply the split once they settle. + const frame = requestAnimationFrame(() => { pending = true; applyLayout(); }); return () => { cancelAnimationFrame(frame); observer.disconnect(); }; - }, [layout, split, sideBySide, tool, testingOpen]); - const toolPanel = { - if (!previous) return; - if (size.inPixels <= collapsedToolSize + 1 && isOpen()) closeTools(); - else if (size.inPixels > 80 && isOpen() === false) showTool(tool); - }}>{tool === "logs" && }{tool === "storage" && }{tool === "app-intel" && }{tool === "tracesift" && }{tool === "app-flow" && open && }{tool === "testing" && open && }{tool === "performance" && open && (savedVisible ?
: )}
; - // The sidebar keeps these controls under its simulators. Fullscreen, or no visible - // platform, moves them above the tools. - const bottomToolbar = !fullscreen && layout !== "none"; + }, [showDevices, sideBySide, testingOpen, tool, deviceShare]); + const bottomToolbarClosed = !fullscreen && !open; + const toolPanel = {tool === "logs" && }{tool === "storage" && }{tool === "app-intel" && }{tool === "testing" && open && }{tool === "tracesift" && }{tool === "app-flow" && open && }{tool === "performance" && open && (savedVisible ?
: )}
; + const bottomToolbar = !fullscreen; const menuSide = bottomToolbar ? "top" : "bottom"; const ToolIcon = tools[tool].icon; - // The Testing Studio panel records by tapping the mirror and reads the test it emits beside it, so the - // mirror leads and the preview follows it — the reading order of the thing being done. Every - // other tool is a readout the simulator is secondary to, and keeps the simulator on the right. - // Only side by side: stacked, "left" is the top panel, which the simulator already is. - const mirrorFirst = testingOpen && sideBySide; - const toolbar =