diff --git a/CHANGELOG.md b/CHANGELOG.md index 64c4943..ce17257 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ What changed in each release, one line per change. Versions follow [Semantic Ver - `iphone_tap` takes `count` (1–10): the taps go in one gesture, about 0.1 s apart, so a double tap or several quick taps work; separate calls are about 0.5 s apart. An older daemon ignores it and taps once. - `iphone_batch` takes `one_gesture`: a batch of coordinate taps runs as one gesture, about twice as fast for pressing keys on a keyboard. +- `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 diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 5fc2d6e..e37fd7b 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -10,6 +10,7 @@ - `iphone_tap` 加 `count`(1~10):在一个手势里连点,每下间隔约 0.1 秒,双击、短时间内连点几下的入口都能点到;分开调用每下约隔 0.5 秒。旧版本守护进程不认这个参数,只点一下。 - `iphone_batch` 新增 `one_gesture`:全是坐标点击的一批步骤放进一个手势里点完,在键盘上逐个按键快一倍左右。 +- `iphone_swipe` 新增 `hold`:先在起点按住几秒再移动,用来拖动主屏幕图标等要先长按才拿得起来的东西。旧版本守护进程会忽略它,照常滑动。 ### 改进 diff --git a/apps/iphone-control/src/viewer.rs b/apps/iphone-control/src/viewer.rs index 2b32e31..f57fed0 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, count: 1 })); 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 8d59c72..7eda837 100644 --- a/crates/ictl-daemon/src/core.rs +++ b/crates/ictl-daemon/src/core.rs @@ -1222,7 +1222,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 } => { @@ -1506,7 +1508,20 @@ fn check_request(req: &Request) -> Result<(), String> { _ => {} } let seconds = match req { - Request::LongPress { seconds, .. } | Request::Swipe { seconds, .. } => *seconds, + Request::LongPress { seconds, .. } => *seconds, + 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")); + } + // 按住加移动一共多久: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(()), }; if !seconds.is_finite() || !(0.0..=MAX_GESTURE_SECONDS).contains(&seconds) { @@ -1846,8 +1861,19 @@ 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()); + 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()); 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 6f7a28e..0ba22f4 100644 --- a/crates/ictl-daemon/src/tasks.rs +++ b/crates/ictl-daemon/src/tasks.rs @@ -1515,7 +1515,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 b5b4fd7..218de31 100644 --- a/crates/ictl-daemon/src/tools/input.rs +++ b/crates/ictl-daemon/src/tools/input.rs @@ -3,6 +3,15 @@ use super::*; use crate::protocol::MAX_TAP_COUNT; +/// 一次滑动([`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. @@ -313,16 +322,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 @@ -349,7 +360,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 a3d2053..fce71da 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., 1, 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 b7fc613..a538dc2 100644 --- a/crates/ictl-mcp/src/lib.rs +++ b/crates/ictl-mcp/src/lib.rs @@ -404,7 +404,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"], ), @@ -668,6 +669,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")? }, @@ -1250,6 +1252,20 @@ 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() + ); + } + /// one_gesture 把全是坐标点击的批量并成一个 TapSequence;混了别的步骤就报错,一步都不执行 #[test] fn one_gesture_turns_taps_into_one_sequence() { @@ -1295,7 +1311,7 @@ mod tests { #[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() })); @@ -1367,7 +1383,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 6bfab5b..1ba82fb 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 +} + /// [`Request::Tap`] 一次最多连点几下 pub const MAX_TAP_COUNT: u32 = 10; @@ -113,10 +117,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, @@ -934,9 +941,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 r = Request::TapSequence { points: vec![(60.0, 548.0), (23.0, 548.0)] }; let s = serde_json::to_string(&r).unwrap(); diff --git a/crates/ictl-wda/src/client.rs b/crates/ictl-wda/src/client.rs index 905e740..29ae996 100644 --- a/crates/ictl-wda/src/client.rs +++ b/crates/ictl-wda/src/client.rs @@ -90,6 +90,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, + ] +} + /// 一个 actions 请求里依次点几个点,每个点一根手指:第 k 根手指先空等前面 k 个点按完(每个点占 5 个节拍:移动、按下、 /// 按住 `press_ms`、抬起、停 `gap_ms`),再移过去按下抬起。W3C 按节拍对齐各手指,所以这些点一个接一个、不重叠。 /// 不用一根手指移来移去:iPhone 17(iOS 26.5.2)上一根手指在一个手势里移到别的点再按,每个点都被识别两次 @@ -862,10 +878,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; } @@ -1663,6 +1680,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 f71570c..9a29b33 100644 --- a/crates/ictl-wda/src/lib.rs +++ b/crates/ictl-wda/src/lib.rs @@ -10,7 +10,7 @@ pub mod http; pub mod runner; pub use client::{ - IdleSettings, Launch, MULTI_TAP_GAP_MS, SEQUENCE_GAP_MS, WdaClient, multi_tap_steps, swipe_steps, + IdleSettings, Launch, MULTI_TAP_GAP_MS, SEQUENCE_GAP_MS, WdaClient, drag_steps, multi_tap_steps, swipe_steps, tap_sequence_body, tap_steps, }; pub use runner::WdaRunner; diff --git a/docs/dev/regression-cases.md b/docs/dev/regression-cases.md index 6358c98..33d3394 100644 --- a/docs/dev/regression-cases.md +++ b/docs/dev/regression-cases.md @@ -152,3 +152,4 @@ | 146 | App 内浏览器(WebView 在导航栏下面,y≈100)里元素坐标整体偏下一个 WebView 的 y:WKWebView 内部有一层节点报 (0,0)、和 WebView 一样大,被当成小组件、之后的子节点都加上偏移,按文字点击点到下面那一行(Safari 全屏的 WebView 从 0 开始,看不出来) | WebView 和它里面的节点不按小组件的相对坐标处理,用元素树里的屏幕坐标 | 单测 `web_contents_keep_screen_coordinates` + 真机(App 内浏览器页面:元素坐标和截图对上,按文字点击点中) | | 147 | 分开点击每下都要等界面空闲(每下约 0.5 秒,`iphone_batch` 连点 5 下约 2.8 秒):双击、要在短时间内连点几下的入口都点不出来(键盘上双击 Shift 只是开了又关,大写锁定没开) | `iphone_tap` 的 `count`:同一点在一个 actions 手势里连点,每下间隔 `MULTI_TAP_GAP_MS`(0.1 秒),一根手指只移动一次(一根手指在一个手势里移到别的点再按,每下会被识别两次);HID 在同一个会话里连发 | 单测 `multi_tap_is_one_request_at_one_point`、`tap_count_defaults_to_one_and_rejects_out_of_range`、`a_tap_without_count_is_one_tap_on_the_wire` + 真机(iPhone 12 mini / iOS 26.4.1:搜索框里 count 2/3/5/10 打出的字数一致;Shift 上 count=2 开大写锁定,分开点两下不开) | | 148 | 输入框不接受 `iphone_type_text`(应用内网页里的输入框),只能逐个点键盘上的键:`iphone_batch` 每步都等界面空闲,7 个键 3.6 秒;把同一根手指在一个手势里挪到各个键上点,每个键会被按两次 | `one_gesture: true` 把全是 `iphone_tap` 的批量并成一个 W3C 手势,每个点一根手指,第 k 根先空等前面的点按完再按(间隔 0.04 秒),中间不等界面空闲;混了别的步骤直接报错、一步都不执行;没有 WDA 时退回逐个点 | 单测 `one_gesture_turns_taps_into_one_sequence`、`a_sequence_is_one_finger_per_point_in_turn` + 真机(iPhone 12 mini,iOS 26.4.1,Spotlight 数字键盘 7/16/20 位、字母键盘 10 个字母,各重复 3~5 次读回输入框的值全对)| +| 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 a32ac26..52ca5c6 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`, `count` (default 1, max 10) | For targets without text (icons, games, maps); falls back to HID when WDA is down. `count` taps the same point that many times in one gesture, about 0.1 s apart: 2 is a double tap (also turns on Caps Lock on the keyboard's Shift key); for hidden entries that need several taps in a short time, which separate calls or `iphone_batch` are too slow for | | `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 af9ee0a..c63d6ed 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; `count` taps the same point several times (double tap, entries that need quick repeated taps) | | `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 31b78a4..c649f72 100644 --- a/website/guide/tools.md +++ b/website/guide/tools.md @@ -21,7 +21,7 @@ MCP 服务提供 17 个工具,开启[开发者工具](#开发者工具-显式 | `iphone_tap` | 按坐标点击;`count` 在同一点连点(双击、要短时间内连点几下的入口) | | `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 |