Control a real USB-connected iPhone from Linux (no Mac, no paid developer account) and expose it to AI agents as MCP tools
Rust ai-agentautomationclaudeclaude-codedockeriosiphonelinuxmcpmcp-servermodel-context-protocolrustwebdriveragent
fix(viewer): fast touch-down again — no screen measurement per press, keep HID warm (#54)
Qinghe Li153edccd6b27
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 0a76659..a64c66b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -20,6 +20,7 @@ All notable changes to this project are documented here. The format is based on### Fixed- Piping output into a program that exits early, such as `iphone-control status | head -1`, no longer crashes with "Broken pipe"; the command ends quietly like other command-line tools.+- Touches on the control page respond faster again: a press no longer measures the screen size on WDA each time (about 0.1–0.2 s, new in 0.2.2); the size is measured on rotation and at most once a minute. Moving the mouse over the picture also keeps the touch session open, so the first press after a pause doesn't wait about 0.5 s for it to reopen.## [0.2.2] - 2026-11-12diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.mdindex 731b791..45406e0 100644--- a/CHANGELOG.zh-CN.md+++ b/CHANGELOG.zh-CN.md@@ -20,6 +20,7 @@### 修复- `iphone-control status | head -1` 这类把输出接给提前退出的程序的用法,不再报 “Broken pipe” 崩溃,而是像其他命令行工具一样直接结束。+- 控制台的触控恢复灵敏:按下时不再每次都向 WDA 量屏幕尺寸(每次约 0.1~0.2 秒,0.2.2 引入),只在转屏时和最多每分钟量一次。鼠标在画面上移动时也保持触控会话打开,停顿后的第一下不用再等约 0.5 秒重开。## [0.2.2] - 2026-11-12diff --git a/apps/iphone-control/src/viewer.html b/apps/iphone-control/src/viewer.htmlindex 0d41acd..a02e034 100644--- a/apps/iphone-control/src/viewer.html+++ b/apps/iphone-control/src/viewer.html@@ -1752,6 +1752,8 @@ stage.addEventListener('pointermove', ev => {if (down && ev.pointerId !== down.pointerId) return;const p = toPoints(ev.clientX, ev.clientY);moveHoverDot(p, ev);+ // 鼠标停在画面上移动时也保持 HID 会话打开(空闲 30 秒会被关,按下时重开要约 0.5 秒);touchWarm 自己限频到 20 秒一次+ if (!down) touchWarm();if (down && down.live && !down.legacy) {const pos = p || toPoints(ev.clientX, ev.clientY, true);if (pos) fingerMove(pos); else cancelGestures();diff --git a/crates/ictl-wda/src/client.rs b/crates/ictl-wda/src/client.rsindex 04d0b83..c883f35 100644--- a/crates/ictl-wda/src/client.rs+++ b/crates/ictl-wda/src/client.rs@@ -1,6 +1,6 @@//! WDA HTTP 客户端。会话失效(WDA 重启后)自动重建一次。-use std::time::Duration;+use std::time::{Duration, Instant};use base64::Engine;use ictl_device::{Rotation, ScreenSize};@@ -10,6 +10,9 @@ use crate::http::Transport;use crate::{Result, WdaError, elements};const DEFAULT_TIMEOUT: Duration = Duration::from_secs(30);+/// How long a measured screen size is trusted at the start of a gesture. `/wda/screen` takes about 100 ms (measured on+/// iOS 27) and only Display Zoom changes the size, so a touch-down doesn't pay for it every time+const SCREEN_RECHECK: Duration = Duration::from_secs(60);/// 普通点击按下的时长(毫秒)。太短可能不被识别成点击;解锁按键另有自己的时长const TAP_PRESS_MS: u64 = 50;@@ -112,6 +115,8 @@ pub struct WdaClient<T> {session: Option<String>,/// `/wda/screen` 第一次给的尺寸(当时的方向)。当前方向下的宽高见 [`Self::view`]screen: Option<ScreenSize>,+ /// When [`Self::screen`] was measured+ screen_at: Option<Instant>,rotation_unsupported: bool,/// 本客户端(对应一次 WDA 启动)是否确认过一次「确实没锁屏」,确认后 `/wda/locked` 就可信了lock_state_trusted: bool,@@ -130,6 +135,7 @@ impl<T: Transport> WdaClient<T> {transport,session: None,screen: None,+ screen_at: None,rotation_unsupported: false,lock_state_trusted: false,idle_baseline: None,@@ -246,6 +252,7 @@ impl<T: Transport> WdaClient<T> {WdaError::Unavailable(ictl_l10n::tr!("/wda/screen 尺寸无效", "Invalid /wda/screen dimensions").into())})?;self.screen = Some(size);+ self.screen_at = Some(Instant::now());Ok(size)}@@ -310,8 +317,9 @@ impl<T: Transport> WdaClient<T> {fallback.await}- /// Poll rotation to detect a changed view. The screen-size request is slower and is- /// needed on acquisition, on rotation, and after unlock for a new coordinate action.+ /// Poll rotation to detect a changed view. The screen size (a slower request) is measured on acquisition and on+ /// rotation; a gesture start measures it again only once the last measurement is older than [`SCREEN_RECHECK`]+ /// (Display Zoom), so a touch-down usually costs only the rotation request.pub async fn display_sample(&mut self,previous: Option<u16>,@@ -319,7 +327,9 @@ impl<T: Transport> WdaClient<T> {fallback: impl Future<Output = Option<Rotation>>,) -> (Option<ScreenSize>, Option<Rotation>) {let rotation = self.interface_rotation(fallback).await;- let size = if gesture_start || rotation.is_some_and(|r| Some(r.degrees()) != previous) {+ let stale = self.screen_at.is_none_or(|t| t.elapsed() >= SCREEN_RECHECK);+ let rotated = rotation.is_some_and(|r| Some(r.degrees()) != previous);+ let size = if rotated || (gesture_start && stale) {self.measure_screen().await} else {self.base_screen_size().await@@ -794,14 +804,21 @@ mod tests {let size = (200, r#"{"value":{"screenSize":{"width":393,"height":852}}}"#);let portrait = (200, r#"{"value":{"z":0}}"#);let landscape = (200, r#"{"value":{"z":90}}"#);- let m = Mock::with(&[session, portrait, size, portrait, landscape, size, landscape, size]);+ let m = Mock::with(&[session, portrait, size, portrait, landscape, size, landscape, landscape, size]);let mut w = WdaClient::new(&m);- for (previous, start, expected) in [- (None, false, Rotation::Portrait),- (Some(0), false, Rotation::Portrait),- (Some(0), false, Rotation::TopToRight),- (Some(90), true, Rotation::TopToRight),+ // (previous rotation, gesture start, size older than SCREEN_RECHECK, expected rotation)+ for (previous, start, stale, expected) in [+ (None, false, false, Rotation::Portrait),+ (Some(0), false, false, Rotation::Portrait),+ (Some(0), false, false, Rotation::TopToRight),+ // a touch-down with a recent size: rotation only+ (Some(90), true, false, Rotation::TopToRight),+ // a touch-down once the size is old: measured again (Display Zoom)+ (Some(90), true, true, Rotation::TopToRight),] {+ if stale {+ w.screen_at = Some(Instant::now() - SCREEN_RECHECK);+ }let (size, rotation) = w.display_sample(previous, start, async { panic!("unexpected fallback") }).await;assert_eq!(rotation, Some(expected));assert_eq!(size.unwrap().width, 393.);@@ -817,6 +834,7 @@ mod tests {"/session/A/rotation","/wda/screen","/session/A/rotation",+ "/session/A/rotation","/wda/screen"]);diff --git a/docs/dev/regression-cases.md b/docs/dev/regression-cases.mdindex 3257718..201995d 100644--- a/docs/dev/regression-cases.md+++ b/docs/dev/regression-cases.md@@ -103,3 +103,4 @@| 97 | APT 锁定(hold)的包仍提示可直接升级,运行后才报错 | hold 当作“已固定”:升级命令带上 `sudo apt-mark unhold`,直接运行时先提示解除锁定 | 单测 a_held_deb_is_reported_like_a_pinned_installation || 98 | 发布清单只允许从声明过的某一个版本升级,其他版本一律“需要手动迁移” | 去掉回滚兼容标记和 `update rollback`;任何更新的签名稳定版都能升级,新版本起不来时仍自动换回旧版本;清单保留两个旧字段让 0.2.2 还能升级 | 单测 verifies_publisher_signed_bytes_before_staging_an_executable、unhealthy_daemon_restores_last_verified_executable_and_service;`test_installer.py` test_archive_manifest_still_lets_0_2_2_upgrade || 99 | `iphone-control status \| head -1`:读者先退出,后面的 `println!` 遇到 EPIPE 就 panic(退出码 101,打出崩溃信息)。Rust 启动时把 SIGPIPE 设成了忽略 | 只打印结果就结束的命令恢复 SIGPIPE 默认行为,安静退出;守护进程、MCP、viewer、wda-bridge 和跨守护进程重启的 update、service、setup 保持忽略 | 单测 sigpipe_default_only_for_commands_that_print_and_end、集成测试 a_closed_stdout_ends_printing_commands_quietly |+| 100 | 0.2.2 起控制台每次按下都先请求 `/wda/screen`(约 0.1~0.2 秒),HID 会话空闲 30 秒关掉后,鼠标一直停在画面里时第一下还要等约 0.5 秒重开 | 按下只问方向,尺寸在转屏时和距上次测量满 60 秒后才重量;鼠标在画面上移动时每 20 秒最多预热一次 HID 会话 | 单测 display_poll_remeasures_size_only_when_needed;页面测试 hovering keeps the HID session warm at most every 20 seconds;真机:控制台连按,按下往返在几十毫秒内 |diff --git a/tests/viewer/actions.test.mjs b/tests/viewer/actions.test.mjsindex 8079fc0..9b75612 100644--- a/tests/viewer/actions.test.mjs+++ b/tests/viewer/actions.test.mjs@@ -109,3 +109,20 @@ test('a named element can be tapped without a rendered frame and targets its devawait tapElement(0);assert.deepEqual(marks, [['tap', 'user', 15, 20]]);});++test('hovering keeps the HID session warm at most every 20 seconds', () => {+ const sent = [];+ let now = 100000;+ const context = {+ S: { liveTouch: true, mode: 'live' }, T: { warm: 0 }, dims: () => ({ W: 1, H: 1 }), guarded: () => false,+ touchSend: phase => sent.push(phase), Date: { now: () => now },+ };+ const { touchWarm } = handlers(['touchWarm'], context);+ touchWarm(); touchWarm();+ now += 19999; touchWarm();+ assert.deepEqual(sent, ['prepare'], 'one prepare per 20 s while the pointer moves');+ now += 1; touchWarm();+ assert.deepEqual(sent, ['prepare', 'prepare']);+ context.S.liveTouch = false; now += 20000; touchWarm();+ assert.equal(sent.length, 2, 'no warm-up without live touch');+});