From 9138db860eea040dffb15d59f19e23c6d328d5c0 Mon Sep 17 00:00:00 2001 From: cosine <1726697408@qq.com> Date: Tue, 17 Nov 2026 14:10:38 +0800 Subject: [PATCH 1/2] feat(mcp): iphone_swipe holds before moving with hold, to drag icons Home-screen icons, files and reorderable rows have to be long-pressed before they can be dragged. iphone_swipe moves as soon as the finger is down, so it only scrolls or pages. Holding with a W3C pause before the move doesn't pick them up either; holding with a pointerMove in place does. hold (seconds, default 0) adds that in-place move before the stroke; over HID the finger is held, reporting its position every 100 ms like a long press, and then dragged without lifting. On an iPhone 12 mini, moving the Settings icon to an empty slot worked 5/5 each with hold 0.5, 0.6 and 1 s, and 0/5 without it. A swipe without hold is the same request as before, and seconds + hold is bounded by the existing 10 s gesture limit. Regression case #149. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 +++ CHANGELOG.zh-CN.md | 4 +++ apps/iphone-control/src/viewer.rs | 3 ++- crates/ictl-daemon/src/core.rs | 22 +++++++++++++--- crates/ictl-daemon/src/tasks.rs | 2 +- crates/ictl-daemon/src/tools/input.rs | 23 +++++++++++----- crates/ictl-daemon/src/tools/mod.rs | 8 +++++- crates/ictl-device/src/hid.rs | 21 +++++++++++++++ crates/ictl-mcp/src/lib.rs | 22 +++++++++++++--- crates/ictl-protocol/src/lib.rs | 16 +++++++++-- crates/ictl-wda/src/client.rs | 38 +++++++++++++++++++++++++-- crates/ictl-wda/src/lib.rs | 2 +- docs/dev/regression-cases.md | 1 + docs/tools.md | 2 +- website/en/guide/tools.md | 2 +- website/guide/tools.md | 2 +- 16 files changed, 149 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d433e42..22ab978 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ What changed in each release, one line per change. Versions follow [Semantic Ver ## [Unreleased] +### New + +- `iphone_swipe` takes `hold`: hold still at the start before moving, to drag home-screen icons and other things that need a long press first. An older daemon ignores it and swipes as before. + ### Improvements - An action that had to unlock the phone first says so, and how long it took (#135). diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index fa578f6..bf00729 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -6,6 +6,10 @@ ## [Unreleased] +### 新功能 + +- `iphone_swipe` 新增 `hold`:先在起点按住几秒再移动,用来拖动主屏幕图标等要先长按才拿得起来的东西。旧版本守护进程会忽略它,照常滑动。 + ### 改进 - 操作前先自动解锁了的话,结果里会说明,并写明用了多久(#135)。 diff --git a/apps/iphone-control/src/viewer.rs b/apps/iphone-control/src/viewer.rs index 68815be..40df4c6 100644 --- a/apps/iphone-control/src/viewer.rs +++ b/apps/iphone-control/src/viewer.rs @@ -1339,6 +1339,7 @@ fn action(name: &str, b: &Value) -> Option { from: (num("x1")?, num("y1")?), to: (num("x2")?, num("y2")?), seconds: num("seconds")?.clamp(0.05, 3.0), + hold: 0.0, }, "type" => { Request::TypeText { text: text("text")?, submit: b.get("submit").and_then(Value::as_bool).unwrap_or(false) } @@ -2013,7 +2014,7 @@ mod tests { assert_eq!(action("tap", &json!({"x": 10.0, "y": 20.5})), Some(Request::Tap { x: 10.0, y: 20.5 })); assert_eq!( action("swipe", &json!({"x1": 1, "y1": 2, "x2": 3, "y2": 4, "seconds": 9})), - Some(Request::Swipe { from: (1.0, 2.0), to: (3.0, 4.0), seconds: 3.0 }) + Some(Request::Swipe { from: (1.0, 2.0), to: (3.0, 4.0), seconds: 3.0, hold: 0.0 }) ); assert_eq!( action("type", &json!({"text": "hi"})), diff --git a/crates/ictl-daemon/src/core.rs b/crates/ictl-daemon/src/core.rs index 6bc2b5b..3555842 100644 --- a/crates/ictl-daemon/src/core.rs +++ b/crates/ictl-daemon/src/core.rs @@ -1221,7 +1221,9 @@ impl Daemon { }) } Request::LongPress { x, y, seconds } => self.long_press(g, x, y, seconds, view).await, - Request::Swipe { from, to, seconds } => self.swipe(g, from, to, seconds, view, watched).await, + Request::Swipe { from, to, seconds, hold } => { + self.swipe(g, crate::tools::Stroke { from, to, seconds, hold }, view, watched).await + } Request::TypeText { text, submit } => self.type_text(g, &text, submit).await, Request::PressButton { button } => self.press_button(g, &button, watched).await, Request::Touch { phase, x, y } => { @@ -1504,7 +1506,14 @@ fn check_request(req: &Request) -> Result<(), String> { _ => {} } let seconds = match req { - Request::LongPress { seconds, .. } | Request::Swipe { seconds, .. } => *seconds, + Request::LongPress { seconds, .. } => *seconds, + // 按住加移动一共多久:HID 两段都要逐个发采样 + Request::Swipe { seconds, hold, .. } => { + if !hold.is_finite() || *hold < 0.0 { + return Err(ictl_l10n::trf!("hold 要是不小于 0 的秒数", "hold must be a number of seconds, 0 or more")); + } + seconds + hold + } _ => return Ok(()), }; if !seconds.is_finite() || !(0.0..=MAX_GESTURE_SECONDS).contains(&seconds) { @@ -1844,8 +1853,15 @@ pub(crate) mod tests { #[test] fn gesture_seconds_are_bounded() { - let swipe = |s| Request::Swipe { from: (0.0, 0.0), to: (1.0, 1.0), seconds: s }; + let swipe = |s| Request::Swipe { from: (0.0, 0.0), to: (1.0, 1.0), seconds: s, hold: 0.0 }; assert!(check_request(&swipe(0.3)).is_ok()); + // a held drag counts the hold too, and the hold can't be negative + let held = |s, h| Request::Swipe { from: (0.0, 0.0), to: (1.0, 1.0), seconds: s, hold: h }; + assert!(check_request(&held(0.7, 0.6)).is_ok()); + assert!(check_request(&held(5.0, 5.0)).is_ok()); + assert!(check_request(&held(5.0, 5.5)).is_err()); + assert!(check_request(&held(0.7, -0.1)).is_err()); + assert!(check_request(&held(0.7, f64::NAN)).is_err()); assert!(check_request(&swipe(1e6)).is_err()); assert!(check_request(&swipe(-1.0)).is_err()); assert!(check_request(&swipe(f64::NAN)).is_err()); diff --git a/crates/ictl-daemon/src/tasks.rs b/crates/ictl-daemon/src/tasks.rs index 1d4f02a..940c6f9 100644 --- a/crates/ictl-daemon/src/tasks.rs +++ b/crates/ictl-daemon/src/tasks.rs @@ -1514,7 +1514,7 @@ mod tests { let r = ts.handle(&req("iphone_tap", json!({"x": 5, "y": 6})), Some(&t.token), None, &mut None).await; assert_eq!(r, Some(Response::text("2"))); t.thought("点一下"); - let n = ts.auto_step(&t, &Request::Swipe { from: (1.0, 2.0), to: (3.0, 4.0), seconds: 0.3 }); + let n = ts.auto_step(&t, &Request::Swipe { from: (1.0, 2.0), to: (3.0, 4.0), seconds: 0.3, hold: 0.0 }); assert_eq!(n, 3); let (log, _, _) = t.subscribe(); let steps: Vec<&Value> = log.iter().filter(|e| e.event == "step").map(|e| &e.data).collect(); diff --git a/crates/ictl-daemon/src/tools/input.rs b/crates/ictl-daemon/src/tools/input.rs index 64eb36b..136fb18 100644 --- a/crates/ictl-daemon/src/tools/input.rs +++ b/crates/ictl-daemon/src/tools/input.rs @@ -2,6 +2,15 @@ use super::*; +/// 一次滑动([`Daemon::swipe`]):从 `from` 用 `seconds` 秒移到 `to`;`hold` 秒大于 0 时先在起点按住再移动 +#[derive(Debug, Clone, Copy, PartialEq)] +pub(crate) struct Stroke { + pub from: (f64, f64), + pub to: (f64, f64), + pub seconds: f64, + pub hold: f64, +} + impl Daemon { /// A stale pointer must neither unlock nor act on a new display. Unlock can itself /// rotate the foreground app, so take the final measurement after it completes. @@ -240,16 +249,18 @@ impl Daemon { pub(crate) async fn swipe( &self, g: &mut Inner, - from: (f64, f64), - to: (f64, f64), - seconds: f64, + stroke: Stroke, view: Option<&str>, watched: bool, ) -> crate::error::Result { + let Stroke { from, to, seconds, hold } = stroke; self.prepare_coordinates(g, view, true).await?; - let desc = format!("({},{}) → ({},{})", fmt_g(from.0), fmt_g(from.1), fmt_g(to.0), fmt_g(to.1)); + let mut desc = format!("({},{}) → ({},{})", fmt_g(from.0), fmt_g(from.1), fmt_g(to.0), fmt_g(to.1)); + if hold > 0.0 { + desc = ictl_l10n::trf!("{desc},先按住 {} 秒", "{desc}, held {} s first", fmt_g(hold)); + } if let Some(w) = self.wda(g) { - match w.swipe_into_polling(from, to, (seconds * 1000.0) as u64).await { + match w.swipe_into_polling(from, to, (hold * 1000.0) as u64, (seconds * 1000.0) as u64).await { // 滑动请求不等惯性滚动(等的话设置不对能卡十几秒),这里等列表停下再返回: // 列表还在滚时下一次点击只会让它停住,点不到东西 // someone watches the screen ([`crate::protocol::WATCHED`]): they see when it stops @@ -276,7 +287,7 @@ impl Daemon { self.hid_do(g, move |h| { Box::pin(async move { h.rotation = rot; - h.drag(from, to, seconds).await + if hold > 0.0 { h.held_drag(from, to, hold, seconds).await } else { h.drag(from, to, seconds).await } }) }) .await?; diff --git a/crates/ictl-daemon/src/tools/mod.rs b/crates/ictl-daemon/src/tools/mod.rs index a243b6c..1082381 100644 --- a/crates/ictl-daemon/src/tools/mod.rs +++ b/crates/ictl-daemon/src/tools/mod.rs @@ -6,6 +6,8 @@ mod launch; mod native; mod observe; +pub(crate) use input::Stroke; + use std::time::{Duration, Instant}; use base64::Engine; @@ -553,7 +555,11 @@ mod tests { let down = |e: &str| e.contains("没有 HID 后备路线") || e.contains("no HID fallback"); let tap = d.tap(&mut g, 20., 50., None).await.unwrap_err().to_string(); assert!(down(&tap), "{tap}"); - let swipe = d.swipe(&mut g, (20., 50.), (20., 300.), 0.3, None, false).await.unwrap_err().to_string(); + let swipe = d + .swipe(&mut g, Stroke { from: (20., 50.), to: (20., 300.), seconds: 0.3, hold: 0.0 }, None, false) + .await + .unwrap_err() + .to_string(); assert!(down(&swipe), "{swipe}"); // a finger: the same, and the page may still send the whole gesture once WDA is back match d.touch(&mut g, TouchPhase::Down, 20., 50., None).await { diff --git a/crates/ictl-device/src/hid.rs b/crates/ictl-device/src/hid.rs index 4e93751..1593b69 100644 --- a/crates/ictl-device/src/hid.rs +++ b/crates/ictl-device/src/hid.rs @@ -182,6 +182,27 @@ impl HidSession { .await } + /// 按住再拖:按下后在起点按住 `hold` 秒(和 [`Self::long_press`] 一样每 100 毫秒重报一次位置),不抬起,接着 + /// 像 [`Self::drag`] 一样移到终点抬起。拖动主屏幕图标、列表排序这类要先长按才能拖的 + pub async fn held_drag(&mut self, from: (f64, f64), to: (f64, f64), hold: f64, seconds: f64) -> Result<()> { + let (x1, y1) = self.hid_point(from); + let (x2, y2) = self.hid_point(to); + let held = Duration::from_secs_f64(hold.clamp(0.0, 60.0)); + let steps = ((seconds * 1000.0 / 20.0).round() as u32).max(10); + let d = held + Duration::from_secs_f64(seconds.max(0.0) + 10.0); + limit(ictl_l10n::tr!("HID 按住拖动", "HID held drag"), d, async { + let end = tokio::time::Instant::now() + held; + self.touch.send_touchscreen(TOUCHSCREEN_STATE_CONTACT, x1, y1, None).await?; + while tokio::time::Instant::now() < end { + tokio::time::sleep(Duration::from_millis(100).min(end - tokio::time::Instant::now())).await; + self.touch.send_touchscreen(TOUCHSCREEN_STATE_CONTACT, x1, y1, None).await?; + } + // drag() starts with a contact at (x1, y1): the finger stays down from the hold into the move + Ok(self.touch.drag(x1, y1, x2, y2, steps, 20).await?) + }) + .await + } + /// One sample of a finger that follows the user's pointer (the web viewer): `contact` true puts the finger at the /// point (the first one touches down, later ones move it), false lifts it there. iOS works out taps, long presses /// and the speed of a swipe from these samples and their timing, the same way as from a real finger diff --git a/crates/ictl-mcp/src/lib.rs b/crates/ictl-mcp/src/lib.rs index 2d53ed2..598124b 100644 --- a/crates/ictl-mcp/src/lib.rs +++ b/crates/ictl-mcp/src/lib.rs @@ -396,7 +396,8 @@ WDA 不可用时改用 CoreDevice HID(iOS 27 起;结果里注明「经 HID」) "from_y": num(ictl_l10n::tr!("起点 y(点)", "start y (points)")), "to_x": num(ictl_l10n::tr!("终点 x(点)", "end x (points)")), "to_y": num(ictl_l10n::tr!("终点 y(点)", "end y (points)")), - "seconds": {"type": "number", "default": 0.3, "description": ictl_l10n::tr!("滑动用时(秒),默认 0.3;越小越快、惯性越大", "swipe duration (seconds), default 0.3; smaller is faster with more momentum")} + "seconds": {"type": "number", "default": 0.3, "description": ictl_l10n::tr!("滑动用时(秒),默认 0.3;越小越快、惯性越大", "swipe duration (seconds), default 0.3; smaller is faster with more momentum")}, + "hold": {"type": "number", "default": 0, "minimum": 0, "description": ictl_l10n::tr!("先在起点按住几秒再移动,默认 0(普通滑动)。拖动要先长按才拿得起来的东西时用,例如主屏幕图标、可排序的列表项、文件:hold 0.6~1,seconds 0.7 左右。少于 0.5 秒通常拿不起来,只会滑动或翻页", "seconds to hold still at the start before moving, default 0 (a plain swipe). For dragging things that have to be long-pressed before they can be picked up, such as home-screen icons, reorderable list rows or files: hold 0.6-1, seconds about 0.7. Under 0.5 s usually doesn't pick anything up and just swipes or pages")} })), &["from_x", "from_y", "to_x", "to_y"], ), @@ -648,6 +649,7 @@ pub fn to_request(name: &str, args: &Map) -> Result Request::TypeText { text: a.s("text")?, submit: a.b_or("submit", false)? }, "iphone_press_button" => Request::PressButton { button: a.s("button")? }, @@ -1203,9 +1205,23 @@ mod tests { with_lang(Lang::Zh, || assert!(has_cjk(instructions()))); } + /// hold defaults to 0 (a plain swipe, same request as before) and is passed through when given + #[test] + fn swipe_hold_defaults_to_zero() { + let plain = to_request("iphone_swipe", &args(json!({"from_x": 1, "from_y": 2, "to_x": 3, "to_y": 4}))).unwrap(); + assert_eq!(plain, Request::Swipe { from: (1.0, 2.0), to: (3.0, 4.0), seconds: 0.3, hold: 0.0 }); + let held = json!({"from_x": 1, "from_y": 2, "to_x": 3, "to_y": 4, "seconds": 0.7, "hold": 0.6}); + let held = to_request("iphone_swipe", &args(held)).unwrap(); + assert_eq!(held, Request::Swipe { from: (1.0, 2.0), to: (3.0, 4.0), seconds: 0.7, hold: 0.6 }); + assert!( + to_request("iphone_swipe", &args(json!({"from_x": 1, "from_y": 2, "to_x": 3, "to_y": 4, "hold": "x"}))) + .is_err() + ); + } + #[test] fn alert_check_after_actions_but_not_buttons_or_reads() { - assert!(wants_alert_check(&Request::Swipe { from: (0.0, 0.0), to: (1.0, 1.0), seconds: 0.3 })); + assert!(wants_alert_check(&Request::Swipe { from: (0.0, 0.0), to: (1.0, 1.0), seconds: 0.3, hold: 0.0 })); assert!(wants_alert_check(&Request::LaunchApp { app: "微信".into() })); assert!(!wants_alert_check(&Request::PressButton { button: "home".into() })); assert!(!wants_alert_check(&Request::TerminateApp { app: "微信".into() })); @@ -1277,7 +1293,7 @@ mod tests { ); assert_eq!( to_request("iphone_swipe", &args(json!({"from_x": 1, "from_y": 2, "to_x": 3, "to_y": 4}))).unwrap(), - Request::Swipe { from: (1.0, 2.0), to: (3.0, 4.0), seconds: 0.3 } + Request::Swipe { from: (1.0, 2.0), to: (3.0, 4.0), seconds: 0.3, hold: 0.0 } ); assert_eq!( to_request("iphone_long_press", &args(json!({"x": 1, "y": 2}))).unwrap(), diff --git a/crates/ictl-protocol/src/lib.rs b/crates/ictl-protocol/src/lib.rs index b9fe2e6..94cb320 100644 --- a/crates/ictl-protocol/src/lib.rs +++ b/crates/ictl-protocol/src/lib.rs @@ -43,6 +43,10 @@ pub fn default_socket() -> PathBuf { } } +fn is_zero(v: &f64) -> bool { + *v == 0.0 +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum TouchPhase { @@ -93,10 +97,13 @@ pub enum Request { y: f64, seconds: f64, }, + /// `hold`:先在起点按住几秒再移动(拖动图标、列表排序),0 是普通滑动。旧版本守护进程不认识这个字段,当普通滑动做 Swipe { from: (f64, f64), to: (f64, f64), seconds: f64, + #[serde(default, skip_serializing_if = "is_zero")] + hold: f64, }, TypeText { text: String, @@ -903,9 +910,14 @@ mod tests { #[test] fn requests_round_trip_as_tagged_json() { - let r = Request::Swipe { from: (1.0, 2.0), to: (3.0, 4.0), seconds: 0.3 }; + let r = Request::Swipe { from: (1.0, 2.0), to: (3.0, 4.0), seconds: 0.3, hold: 0.0 }; + let s = serde_json::to_string(&r).unwrap(); + // a plain swipe is what it always was on the wire: older daemons and clients see no change + assert_eq!(s, r#"{"op":"swipe","from":[1.0,2.0],"to":[3.0,4.0],"seconds":0.3}"#); + assert_eq!(serde_json::from_str::(&s).unwrap(), r); + let r = Request::Swipe { from: (1.0, 2.0), to: (3.0, 4.0), seconds: 0.7, hold: 0.6 }; let s = serde_json::to_string(&r).unwrap(); - assert!(s.starts_with(r#"{"op":"swipe""#), "{s}"); + assert!(s.ends_with(r#""hold":0.6}"#), "{s}"); assert_eq!(serde_json::from_str::(&s).unwrap(), r); let e: Response = serde_json::from_str(r#"{"kind":"error","message":"x"}"#).unwrap(); assert_eq!(e, Response::error("x")); diff --git a/crates/ictl-wda/src/client.rs b/crates/ictl-wda/src/client.rs index f9d8c44..acbef23 100644 --- a/crates/ictl-wda/src/client.rs +++ b/crates/ictl-wda/src/client.rs @@ -72,6 +72,22 @@ pub fn swipe_steps(from: (f64, f64), to: (f64, f64), ms: u64) -> Vec Vec { + if hold_ms == 0 { + return swipe_steps(from, to, ms); + } + vec![ + PointerStep::Move { x: from.0, y: from.1, ms: 0 }, + PointerStep::Down, + PointerStep::Move { x: from.0, y: from.1, ms: hold_ms }, + PointerStep::Move { x: to.0, y: to.1, ms }, + PointerStep::Up, + ] +} + /// `POST /session/{id}/actions` 的请求体 pub fn actions_body(steps: &[PointerStep]) -> Value { let actions: Vec = steps @@ -803,10 +819,11 @@ impl WdaClient { /// Swipes and stays in polling mode for the caller, who ends it with [`Self::end_polling`]: restoring the settings /// only to change them again right after would cost two round trips - pub async fn swipe_into_polling(&mut self, from: (f64, f64), to: (f64, f64), ms: u64) -> Result<()> { + /// `hold_ms` > 0 holds the finger still at `from` first ([`drag_steps`]) + pub async fn swipe_into_polling(&mut self, from: (f64, f64), to: (f64, f64), hold_ms: u64, ms: u64) -> Result<()> { self.baseline().await?; self.set_idle_settings(IdleSettings::NO_COOL_OFF).await?; - let r = self.actions(&swipe_steps(from, to, ms)).await; + let r = self.actions(&drag_steps(from, to, hold_ms, ms)).await; if r.is_err() { self.end_polling().await; } @@ -1551,6 +1568,23 @@ mod tests { assert_eq!(s[3], PointerStep::Move { x: 3.0, y: 4.0, ms: 300 }); } + /// 按住再拖:按下后原地 move 按住(不是 pause,pause 拖不动图标),再移到终点;不按住就是普通滑动 + #[test] + fn a_held_drag_holds_with_a_move_in_place() { + let s = drag_steps((1.0, 2.0), (3.0, 4.0), 600, 700); + assert_eq!( + s, + [ + PointerStep::Move { x: 1.0, y: 2.0, ms: 0 }, + PointerStep::Down, + PointerStep::Move { x: 1.0, y: 2.0, ms: 600 }, + PointerStep::Move { x: 3.0, y: 4.0, ms: 700 }, + PointerStep::Up, + ] + ); + assert_eq!(drag_steps((1.0, 2.0), (3.0, 4.0), 0, 300), swipe_steps((1.0, 2.0), (3.0, 4.0), 300)); + } + #[tokio::test] async fn locked_checks_tree_until_unlocked_once_then_trusts_wda() { let lock_xml = serde_json::to_string(include_str!("../tests/fixtures/lockscreen-ios27.xml")).unwrap(); diff --git a/crates/ictl-wda/src/lib.rs b/crates/ictl-wda/src/lib.rs index ede821c..e401042 100644 --- a/crates/ictl-wda/src/lib.rs +++ b/crates/ictl-wda/src/lib.rs @@ -9,7 +9,7 @@ pub mod elements; pub mod http; pub mod runner; -pub use client::{IdleSettings, Launch, WdaClient, swipe_steps, tap_steps}; +pub use client::{IdleSettings, Launch, WdaClient, drag_steps, swipe_steps, tap_steps}; pub use runner::WdaRunner; #[derive(Debug, thiserror::Error)] diff --git a/docs/dev/regression-cases.md b/docs/dev/regression-cases.md index 5f0a9f3..fd64644 100644 --- a/docs/dev/regression-cases.md +++ b/docs/dev/regression-cases.md @@ -149,3 +149,4 @@ | 143 | 原生:Spotlight 打开时选中上次的搜索词,再粘贴同样的词会把它替换成自己,输入框的值不变,`iphone_type_text` 报「粘贴了…但输入框里没有这段文字」(带 `submit` 时还不按回车),其实已经输进去了 | 「允许粘贴」点过之后,输入框原来就有这段文字、1.5 秒不变,算输入成功并提示截图确认;没点过「允许粘贴」时仍报错 | 单测 `a_paste_that_replaced_the_same_text_is_told_apart_from_one_that_missed` + 真机(Spotlight 留着「设置」时再输入「设置」,`run.py` 连跑两遍);真机脚本 `scenarios.py typing` | | 144 | 设备闲置时自动锁屏,下一个操作先自动解锁(iPad 经 WDA 约 15 秒,iPhone 原生约 9 秒),结果和事件日志都没说,看着像「切换设备后第一个操作慢」 | 结果第一行(截图在说明里、出错时在报错里)写「手机锁着,先自动解锁了,用时 X 秒」,事件日志记「已自动解锁」 | 单测 `an_unlock_first_is_said_on_the_answers_first_line` + 真机(锁屏后按名字点击、截图,两台设备);真机脚本 `scenarios.py lock` | | 145 | WDA 的短探测已正常应答或返回远端错误,却不清零超时计数,三个独立慢请求仍会触发重启;连接失败反而清零。日志还把长请求和短探测均未应答写成「连续 3 次」、宣称尚未检查的 `/status` 正常,请求超时本身缺端点日志 | 只有正常响应或远端错误清零,连接失败不清零;连续无应答和长请求后的失败探测分别记录原因及实际次数;超时诊断记录方法、短路径和耗时,不记录查询参数或正文 | 单测 `answered_probe_resets_stall_count_after_each_slow_request`、`connection_error_does_not_reset_unanswered_count`、`long_request_and_failed_probe_keep_the_actual_count_and_reason`、`three_short_unanswered_requests_report_a_consecutive_stall`、`answered_session_delete_does_not_mask_a_failed_probe`、`failed_request_log_keeps_endpoint_and_time_without_query`、`successful_request_log_does_not_include_response_body`;真机:同一 iPad、同一 WDA,把只读业务请求的客户端时限缩短到 20ms,短探测保留 5s,对照修复前后各 3 轮 | +| 149 | 拖动要先长按才拿得起来的东西(主屏幕图标、文件、可排序的列表项):`iphone_swipe` 按下就移动,只会滑动或翻页;在 W3C 手势里按下后用 `pause` 按住 0.6~1 秒再移动也拿不起来(0/6),原地 `pointerMove` 0.3 秒也不行 | `iphone_swipe` 的 `hold`:按下后用一段原地的 `pointerMove` 按住 `hold` 秒(不是 `pause`),再用 `seconds` 移到终点;HID 按住时每 100 毫秒重报一次位置,手指不抬起接着拖;`seconds + hold` 不超过 10 秒;不带 `hold` 的请求和以前完全一样 | 单测 `a_held_drag_holds_with_a_move_in_place`、`swipe_hold_defaults_to_zero`、`gesture_seconds_are_bounded`、`requests_round_trip_as_tagged_json` + 真机(iPhone 12 mini,iOS 26.4.1:主屏幕「设置」图标移到同一行空位,`hold` 0.5/0.6/1 各 5/5,不带 0/5;每次再用 `hold` 拖回原位)| diff --git a/docs/tools.md b/docs/tools.md index c7ae63c..1e023ef 100644 --- a/docs/tools.md +++ b/docs/tools.md @@ -21,7 +21,7 @@ Coordinates are in **points**, the same unit as the pixels of a full-screen `iph | `iphone_tap` | `x`, `y` | For targets without text (icons, games, maps); falls back to HID when WDA is down | | `iphone_tap_element` | `text`, `index` (default 0) | Exact label or name first, then substring. If the element's center is covered (floating toolbar, keyboard, overlay), taps an uncovered part of it; if it is fully covered, does not tap and says so | | `iphone_long_press` | `x`, `y`, `seconds` (default 1, max 10) | Holds one finger still, then lifts: context menus, home-screen quick actions, text selection | -| `iphone_swipe` | `from_x`, `from_y`, `to_x`, `to_y`, `seconds` (default 0.3, max 10) | Returns after the list has stopped scrolling (up to 2.5 s). Swipe up (`from_y` > `to_y`) to see content further down | +| `iphone_swipe` | `from_x`, `from_y`, `to_x`, `to_y`, `seconds` (default 0.3, max 10), `hold` (default 0) | Returns after the list has stopped scrolling (up to 2.5 s). Swipe up (`from_y` > `to_y`) to see content further down. `hold` holds the finger still at the start for that many seconds before moving, to drag things that have to be long-pressed first (home-screen icons, reorderable rows); about 0.6 works, under 0.5 usually doesn't pick anything up. `seconds` + `hold` is at most 10 | | `iphone_type_text` | `text`, `submit` (default false) | Types into the focused field (Chinese supported); fails if no keyboard is shown. Reads the field back afterwards: dropped trailing characters are typed again; if the field still doesn't match, it reports an error and does not press Return | | `iphone_press_button` | `button`: `home`, `volume_up`, `volume_down`, `lock` | `home` refuses to act while a system alert is on screen (it would have no effect). `home` is sent as an IOHID AC Home event and waits until the home screen is in front; `lock` presses the power key over IOHID. Each falls back to the XCTest/WebDriverAgent way if it had no effect | | `iphone_launch_app` | `app` (bundle id or display name, e.g. `设置`) | Cold-launches the app, or brings it back to where it was if it is already running. Waits until it is in the foreground; returns early and says so if a system alert is blocking it | diff --git a/website/en/guide/tools.md b/website/en/guide/tools.md index c863000..3eb67e7 100644 --- a/website/en/guide/tools.md +++ b/website/en/guide/tools.md @@ -21,7 +21,7 @@ With [auto-unlock](./auto-unlock) on, `iphone_screenshot`, `iphone_list_elements | `iphone_tap` | Tap coordinates | | `iphone_tap_element` | Tap by text; if the center is covered by a floating bar or the keyboard it taps a visible part, and if it's fully covered it doesn't tap | | `iphone_long_press` | Long press; `seconds` defaults to 1, max 10 | -| `iphone_swipe` | Swipe; returns once the list has stopped scrolling. `seconds` defaults to 0.3, max 10 | +| `iphone_swipe` | Swipe; returns once the list has stopped scrolling. `seconds` defaults to 0.3, max 10. `hold` holds still at the start for that many seconds before moving, to drag things that need a long press first (home-screen icons, reorderable rows); about 0.6 works | | `iphone_type_text` | Type into the focused field (Chinese supported), read it back and fix dropped characters; `submit` presses Return | | `iphone_press_button` | `home`, `volume_up`, `volume_down`, `lock` | | `iphone_launch_app` / `iphone_terminate_app` | Launch / quit an app by name (e.g. `设置`) or bundle id | diff --git a/website/guide/tools.md b/website/guide/tools.md index 08bf887..df8cac2 100644 --- a/website/guide/tools.md +++ b/website/guide/tools.md @@ -21,7 +21,7 @@ MCP 服务提供 17 个工具,开启[开发者工具](#开发者工具-显式 | `iphone_tap` | 按坐标点击 | | `iphone_tap_element` | 按文字点击;中心被悬浮栏、键盘挡住时改点露出来的部分,整个被挡住就不点 | | `iphone_long_press` | 长按;`seconds` 默认 1,最多 10 | -| `iphone_swipe` | 滑动;列表停稳后才返回。`seconds` 默认 0.3,最多 10 | +| `iphone_swipe` | 滑动;列表停稳后才返回。`seconds` 默认 0.3,最多 10。`hold` 先在起点按住几秒再移动,用来拖动要先长按才拿得起来的东西(主屏幕图标、可排序的列表项),0.6 左右即可 | | `iphone_type_text` | 在当前输入框输入文字(支持中文),输完读回核对,丢字会补上;`submit` 时按回车 | | `iphone_press_button` | `home`、`volume_up`、`volume_down`、`lock` | | `iphone_launch_app` / `iphone_terminate_app` | 启动 / 结束 App,可以用名字(如「设置」)或 Bundle ID | From 8dbac4396dc1ec8a167bd95f16f3e300cd639024 Mon Sep 17 00:00:00 2001 From: Derrors <33656531+Derrors@users.noreply.github.com> Date: Tue, 17 Nov 2026 23:22:47 +0800 Subject: [PATCH 2/2] fix(daemon): check a swipe's seconds on its own, then seconds plus hold Only the sum was checked, so a negative seconds passed when the hold made up for it (-0.5 + 1), and a sum over the limit said "seconds must be between 0 and 10" although seconds alone was fine. Now seconds keeps its own range, hold can't be negative, and a sum over the limit names both. Co-Authored-By: Claude Opus 5.5 --- crates/ictl-daemon/src/core.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/ictl-daemon/src/core.rs b/crates/ictl-daemon/src/core.rs index 4576dcc..7eda837 100644 --- a/crates/ictl-daemon/src/core.rs +++ b/crates/ictl-daemon/src/core.rs @@ -1509,12 +1509,18 @@ fn check_request(req: &Request) -> Result<(), String> { } let seconds = match req { Request::LongPress { seconds, .. } => *seconds, - // 按住加移动一共多久:HID 两段都要逐个发采样 Request::Swipe { seconds, hold, .. } => { if !hold.is_finite() || *hold < 0.0 { return Err(ictl_l10n::trf!("hold 要是不小于 0 的秒数", "hold must be a number of seconds, 0 or more")); } - seconds + hold + // 按住加移动一共多久:HID 两段都要逐个发采样。seconds 自己的范围下面照常查,负数不能靠 hold 凑过去 + if seconds.is_finite() && *seconds >= 0.0 && seconds + hold > MAX_GESTURE_SECONDS { + return Err(ictl_l10n::trf!( + "seconds 加 hold 不能超过 {MAX_GESTURE_SECONDS} 秒", + "seconds plus hold must be at most {MAX_GESTURE_SECONDS} s" + )); + } + *seconds } _ => return Ok(()), }; @@ -1861,7 +1867,11 @@ pub(crate) mod tests { let held = |s, h| Request::Swipe { from: (0.0, 0.0), to: (1.0, 1.0), seconds: s, hold: h }; assert!(check_request(&held(0.7, 0.6)).is_ok()); assert!(check_request(&held(5.0, 5.0)).is_ok()); - assert!(check_request(&held(5.0, 5.5)).is_err()); + let too_long = check_request(&held(5.0, 5.5)).unwrap_err(); + assert!(too_long.contains("hold"), "{too_long}"); + // a negative seconds isn't made up for by the hold + assert!(check_request(&held(-0.5, 1.0)).is_err()); + assert!(check_request(&held(0.3, 20.0)).is_err()); assert!(check_request(&held(0.7, -0.1)).is_err()); assert!(check_request(&held(0.7, f64::NAN)).is_err()); assert!(check_request(&swipe(1e6)).is_err());