Skip to content

Control a real USB-connected iPhone from Linux (no Mac, no paid developer account) and expose it to AI agents as MCP tools

feat(viewer): redesign the responsive workspace and guard gestures across display changes (#45)

MSKb3cb02494797
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 4e767dc..f58e76f 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -39,6 +39,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
+ - name: Viewer interaction tests
+ run: node --test tests/viewer/*.test.mjs
# 锁定工具链(与发布一致):新版 clippy 的 lint 不会在代码没变时把 CI 弄挂
- uses: dtolnay/[email protected]
with:
diff --git a/Cargo.lock b/Cargo.lock
index b16ff1d..776fa01 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1966,6 +1966,7 @@ dependencies = [
"sha2 0.10.9",
"tokio",
"tracing",
+ "uuid",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index 9e16372..20c1069 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -43,6 +43,7 @@ idevice = { version = "=0.1.68", default-features = false, features = [
"cryptexd",
"tss",
"installation_proxy",
+ "springboardservices",
"misagent",
"xctest",
# developer tools (IPHONE_CONTROL_DEV_TOOLS): os_trace logs, crash reports
diff --git a/DESIGN.md b/DESIGN.md
new file mode 100644
index 0000000..0cd705d
--- /dev/null
+++ b/DESIGN.md
@@ -0,0 +1,44 @@
+# Web 控制台设计规范
+
+桌面从左到右排列 AI 助手、设备画面、设备面板。窄窗口用抽屉或标签切换。接入新控件时沿用这套结构,优先把可用空间留给设备画面。[页面实现](apps/iphone-control/src/viewer.html)
+
+## 输入与排版
+
+按「写任务 → 选执行器 → 发送」安排输入区的信息层级。标准字号采用下表。字号用 `rem` 表示,表中为浏览器默认根字号 16 px 时的 CSS 像素。
+
+| 用途 | 标准字号 | 排版 |
+| --- | --- | --- |
+| 区块标题 | 18–20 px | 半粗体。AI 助手欢迎标题为 19 px。 |
+| 任务输入、任务正文 | 14 px | 常规字重,正文行高约 1.5 倍。触屏手机输入框至少 16 px。 |
+| 下拉按钮和菜单项 | 13 px | 当前名称与箭头垂直居中。长名称在按钮内可省略,展开后可以换行。 |
+| 键盘提示、次要元数据 | 12 px | 常规字重。发送快捷键放在按钮提示和输入框的读屏说明中。 |
+
+界面使用系统无衬线字体,中文由本机中文字体绘制。ProductType、UDID 和代码使用等宽字体。外观设置中的大字和特大字调整控制台文字,设备图像按屏幕工具栏的倍率显示。Primer 将标题、正文、注释及代码定义为不同的文本样式,表中的数值是本项目对中文控制台的选择。[Primer Typography](https://primer.style/product/primitives/typography/)
+
+## 左栏底部
+
+任务输入占第一行。第二行只放执行器和圆形发送键,整组靠右。执行器按钮随当前名称调整宽度,名称与 12 px 箭头之间留 4 px,按钮与发送键之间留 6 px。输入区使用细边和轻阴影,在侧栏的玻璃背景上保留清晰边界。该排列参考 Codex 公开界面中的双行输入区和右端的选择器、发送键。[OpenAI 官方输入区示意](https://learn.chatgpt.com/images/codex/video-posters/proactive-teammate-v2.webp)
+
+执行器、控制设备、界面语言、明暗和界面字号共用选择器。名称与箭头留 4 px,菜单与按钮右缘对齐,间隔 6 px。执行器优先向上展开,其余优先向下,空间不足时翻转。菜单内边距 4 px,选项水平内边距 8 px,右侧的勾标记当前值。方向键移动高亮,Enter 确认,Esc 返回按钮。设置中的菜单关闭后,外层设置窗口继续显示。
+
+全局设置独立放在输入区下方,以齿轮和文字显示,点击二者之间的区域也能打开设置。任务记录滚动时,用户仍能在同一位置找到语言、主题和字号。这个入口沿用官方桌面侧栏将全局操作放在底部的分组方式,具体内容取自本项目已有设置。[OpenAI 官方桌面侧栏示意](https://learn.chatgpt.com/docs/use-chatgpt)
+
+「关于与更新」与设置同排靠右。发现新版时在 ⓘ 上显示红点。点击后从按钮旁打开非模态浮层,首屏展示版本和当前语言的发行说明摘录。后端提供对应安装渠道的命令时,可直接复制。完整发行说明通过链接打开,运行版本、安装渠道和更新策略收在「版本详情」里。
+
+## 图标与命中区域
+
+发送、刷新、缩放等常规动作使用 16 px 图形。下拉箭头使用 12 px,和文字合用同一个选择器。20 px 留给需要强调的独立图形。Carbon 的常规按钮使用 16 px 图标,强调型按钮使用 20 px 图标。Primer 的 12 px 图标中有用于展开和收起的箭头。[Carbon Button](https://www.carbondesignsystem.com/building-blocks/core/components/button/specifications) · [Primer Octicons](https://primer.style/octicons/usage-guidelines/)
+
+发送按钮的箭头固定为 16 px,居中放在桌面的 32 × 32 px 按钮内。对粗指针设备扩大为 44 × 44 CSS px,执行器选择器也至少 44 px 高。图标按钮提供可访问名称及可见的键盘焦点。44 px 是此控制台的触屏目标。WCAG 2.2 AA 对指针目标的常规下限是 24 × 24 CSS px,并列有间距等例外。[WCAG 2.5.8](https://www.w3.org/WAI/WCAG22/Understanding/target-size-minimum.html) · [Primer IconButton](https://primer.style/product/components/icon-button/)
+
+## 玻璃材质
+
+两侧面板外壳、屏幕的浮动工具条和弹窗共用中性色磨砂材质。每块表面只在外层模糊背景,内部控件用底色、细边和留白区分。文字、图标和设备视频保持清晰。正文较多的面板提高底色不透明度,深色主题单独指定表面颜色。Fluent Acrylic 建议将透明效果用于浮层,指出相邻模糊层容易产生接缝。常驻侧栏采用高不透明度的外壳是本项目的选择。[Fluent Acrylic](https://learn.microsoft.com/en-us/windows/apps/design/style/acrylic)
+
+默认样式使用实色表面,在支持 `backdrop-filter` 的浏览器启用玻璃。系统开启减少透明度、更高对比度或强制色彩时回到实色。对比度按前景与最终合成背景计算。普通文字以 4.5∶1 为下限,用于识别可操作控件的图形以 3∶1 为下限。[WCAG 文字对比度](https://www.w3.org/WAI/WCAG22/Understanding/contrast-minimum.html) · [WCAG 非文本对比度](https://www.w3.org/WAI/WCAG22/Understanding/non-text-contrast.html)
+
+## 评审时怎么检查
+
+1. 用鼠标和键盘切换执行器,输入两行中文后发送。分别确认空草稿、可发送和正在执行三种状态。发送箭头与选择器文字对齐,输入区的高度随内容增长。
+2. 切换中英文,在 320 px 宽度使用特大字号。检查长执行器名称、换行提示与发送按钮的占位,触摸目标互不遮挡。
+3. 对照浅色、深色、减少透明度及强制色彩。用真实画面或录制帧检查视频边缘与叠层标记。改变字号后,设备画面仍完整,点击与可见图像位置对应。
diff --git a/THIRD_PARTY.md b/THIRD_PARTY.md
index da7099f..5f36856 100644
--- a/THIRD_PARTY.md
+++ b/THIRD_PARTY.md
@@ -4,6 +4,7 @@
| 组件 | 版本 / 提交 | 许可证 | 引入方式 | 改动 |
|---|---|---|---|---|
+| [DeviceKit](https://github.com/devicekit/DeviceKit/blob/fab82bd988405367c915143e293479f481e93ba0/Source/Device.generated.swift) | `fab82bd988405367c915143e293479f481e93ba0` | MIT | `crates/ictl-device/src/models.rs` | 提取 iPhone 和 iPad 的硬件标识与型号名称 |
| [idevice](https://github.com/jkcoxson/idevice) | 上游 master `89702099`(0.1.68 之后、未发版) | MIT | git 依赖,`[patch.crates-io]` | 无(0.1.68 的 cryptexd install 会挂住;发版后换回 crates.io) |
| [jktcp](https://crates.io/crates/jktcp) | 0.1.8(间接) | MIT | crates.io | 无 |
| [rmcp](https://github.com/modelcontextprotocol/rust-sdk) | 3.8.0 | Apache-2.0(部分历史代码 MIT) | crates.io | 无 |
@@ -22,3 +23,25 @@
因为不启用 omnisette 的默认 feature,AGPL-3.0 的过程宏 `remove-async-await` 和没有许可证声明的 `android-loader`/`sysv64` 都不会被编译。
完整的传递依赖许可证清单 `THIRD_PARTY_LICENSES.html` 由 cargo-about 0.9.3 按 `Cargo.lock` 生成(配置 `packaging/licenses/about.toml`),放在每个发布的压缩包里,.deb 里在 `/usr/share/doc/iphone-control/THIRD_PARTY_LICENSES.html`。vendor 组件的许可证文件在仓库的 `vendor/<组件>/` 里。
+
+## DeviceKit
+
+Copyright (c) 2015 Dennis Weissmann
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/apps/iphone-control/src/main.rs b/apps/iphone-control/src/main.rs
index 0f33ce0..161ee1c 100644
--- a/apps/iphone-control/src/main.rs
+++ b/apps/iphone-control/src/main.rs
@@ -408,7 +408,7 @@ async fn print_text(socket: &Path, req: Request) -> anyhow::Result<()> {
println!("{text}");
Ok(())
}
- Response::Error { message } => bail!("{message}"),
+ Response::Error { message, .. } => bail!("{message}"),
Response::Image { caption, .. } => {
println!("{caption}");
Ok(())
@@ -419,7 +419,7 @@ async fn print_text(socket: &Path, req: Request) -> anyhow::Result<()> {
async fn snapshot(socket: &Path) -> anyhow::Result<ictl_daemon::Snapshot> {
match ask(socket, Request::Daemon).await? {
Response::Text { text, .. } => Ok(serde_json::from_str(&text)?),
- Response::Error { message } => bail!("{message}"),
+ Response::Error { message, .. } => bail!("{message}"),
Response::Image { .. } => {
bail!("{}", ictl_l10n::tr!("守护进程返回了意外的响应", "The daemon sent an unexpected response"))
}
diff --git a/apps/iphone-control/src/update.rs b/apps/iphone-control/src/update.rs
index c6a4214..fb2d9c8 100644
--- a/apps/iphone-control/src/update.rs
+++ b/apps/iphone-control/src/update.rs
@@ -99,6 +99,7 @@ pub struct Report {
pub error_code: Option<String>,
pub published_at: Option<String>,
pub release_url: Option<String>,
+ pub release_notes: Option<String>,
pub guidance: String,
pub upgrade_command: Option<String>,
pub last_update: Option<transaction::Outcome>,
@@ -464,6 +465,7 @@ impl Local {
error_code: cache.error_code,
published_at: release.and_then(|r| r.published_at.clone()),
release_url: repo.zip(release).map(|(repo, r)| format!("https://github.com/{repo}/releases/tag/{}", r.tag)),
+ release_notes: release.and_then(|r| r.notes.as_ref()?.for_lang(ictl_l10n::lang())),
guidance,
upgrade_command: command,
last_update,
@@ -646,16 +648,34 @@ mod tests {
policy: Policy::Manual,
};
let mut cache = Cache::default();
- cache.release = Some(Release { tag: "v9.4.2".into(), published_at: None, assets: vec![] });
+ cache.release = Some(Release { tag: "v9.4.2".into(), published_at: None, assets: vec![], notes: None });
let report = local.report(cache).unwrap();
assert_eq!(report.availability, Availability::Current);
assert!(report.upgrade_command.is_none());
}
+ #[test]
+ fn cached_report_uses_viewer_request_language() {
+ let cache: Cache = serde_json::from_value(serde_json::json!({
+ "release": {"tag": "v1.2.3", "assets": [], "notes": {"en": "New video", "zh": "新画面"}}
+ }))
+ .unwrap();
+ for (lang, expected) in [(ictl_l10n::Lang::En, "New video"), (ictl_l10n::Lang::Zh, "新画面")] {
+ let local = Local {
+ source_command: None,
+ exe: None,
+ install: Installation { method: InstallMethod::Unknown, version: None, pinned: None },
+ policy: Policy::Manual,
+ };
+ let report = ictl_l10n::with_lang(lang, || local.report(cache.clone())).unwrap();
+ assert_eq!(report.release_notes.as_deref(), Some(expected));
+ }
+ }
+
#[test]
fn upgrade_commands_follow_the_verified_channel_and_release_state() {
let exe = Path::new("/Users/it's me/bin/iphone-control");
- let release = Release { tag: "v0.2.1".into(), published_at: None, assets: vec![] };
+ let release = Release { tag: "v0.2.1".into(), published_at: None, assets: vec![], notes: None };
let brew = Path::new("/opt/homebrew/bin/brew");
let keg = Path::new("/opt/homebrew/Cellar/iphone-control/0.2.0/bin/iphone-control");
let command = |method, pinned, status, platform, tap| {
@@ -700,6 +720,7 @@ mod tests {
tag: "v0.2.1".into(),
published_at: None,
assets: vec!["iphone-control-v0.2.1-linux-x86_64.tar.gz".into(), "iphone-control_0.2.1_amd64.deb".into()],
+ notes: None,
};
let for_install = |running, method, platform| availability(running, method, platform, Some(&release));
assert_eq!(for_install("0.2.1", InstallMethod::Unknown, None), Availability::Current);
@@ -718,7 +739,8 @@ mod tests {
#[test]
fn managed_upgrade_waits_for_the_signed_manifest() {
let base = "iphone-control-v0.2.1-linux-x86_64";
- let mut release = Release { tag: "v0.2.1".into(), published_at: None, assets: vec![format!("{base}.tar.gz")] };
+ let mut release =
+ Release { tag: "v0.2.1".into(), published_at: None, assets: vec![format!("{base}.tar.gz")], notes: None };
let managed = |r: &Release, running, keys| {
availability_with(running, InstallMethod::Managed, Some("linux-x86_64"), Some(r), keys)
};
diff --git a/apps/iphone-control/src/update/release.rs b/apps/iphone-control/src/update/release.rs
index 95e3573..79ea56e 100644
--- a/apps/iphone-control/src/update/release.rs
+++ b/apps/iphone-control/src/update/release.rs
@@ -8,6 +8,7 @@ use std::path::Path;
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use anyhow::{Context, Result};
+use ictl_l10n::Lang;
use reqwest::{Client, StatusCode, header};
use serde::{Deserialize, Serialize};
@@ -27,6 +28,64 @@ pub(super) struct Release {
pub tag: String,
pub published_at: Option<String>,
pub assets: Vec<String>,
+ // Absent in caches written before release notes were collected.
+ pub notes: Option<ReleaseNotes>,
+}
+
+#[derive(Clone, Deserialize, Serialize)]
+pub(super) struct ReleaseNotes {
+ en: Option<String>,
+ zh: Option<String>,
+}
+
+impl ReleaseNotes {
+ fn from_body(body: &str) -> Self {
+ // Both release workflows end the changelog with a shared download/installation footer.
+ let body = body
+ .split_once("\n**Binaries / 二进制:**")
+ .and_then(|(before, _)| before.trim_end().strip_suffix("\n---"))
+ .unwrap_or(body);
+ let mut en = String::new();
+ let mut zh = String::new();
+ let mut lang = None;
+ for line in body.split_inclusive('\n') {
+ match line.trim_end() {
+ "## English" => lang = Some(Lang::En),
+ "## 中文" => lang = Some(Lang::Zh),
+ _ => match lang {
+ Some(Lang::En) => en.push_str(line),
+ Some(Lang::Zh) => zh.push_str(line),
+ None => {}
+ },
+ }
+ }
+ Self { en: excerpt(if lang.is_some() { &en } else { body }), zh: excerpt(&zh) }
+ }
+
+ pub(super) fn for_lang(&self, lang: Lang) -> Option<String> {
+ match lang {
+ Lang::En => self.en.as_ref().or(self.zh.as_ref()),
+ Lang::Zh => self.zh.as_ref().or(self.en.as_ref()),
+ }
+ .cloned()
+ }
+}
+
+const MAX_NOTES_BYTES: usize = 4096;
+
+fn excerpt(text: &str) -> Option<String> {
+ let text = text.trim();
+ if text.is_empty() {
+ return None;
+ }
+ if text.len() <= MAX_NOTES_BYTES {
+ return Some(text.to_owned());
+ }
+ let mut end = MAX_NOTES_BYTES - '…'.len_utf8();
+ while !text.is_char_boundary(end) {
+ end -= 1;
+ }
+ Some(format!("{}…", text[..end].trim_end()))
}
#[derive(Deserialize)]
@@ -35,6 +94,7 @@ struct Metadata {
draft: bool,
prerelease: bool,
published_at: Option<String>,
+ body: Option<String>,
assets: Vec<Asset>,
}
@@ -56,7 +116,8 @@ fn parse_release(body: &[u8]) -> Option<Release> {
return None;
}
let assets = meta.assets.into_iter().filter(|a| a.state == "uploaded" && a.size > 0).map(|a| a.name).collect();
- Some(Release { tag: meta.tag_name, published_at: meta.published_at, assets })
+ let notes = Some(ReleaseNotes::from_body(meta.body.as_deref().unwrap_or_default()));
+ Some(Release { tag: meta.tag_name, published_at: meta.published_at, assets, notes })
}
pub(super) fn read(dir: &Path) -> Result<Cache> {
@@ -119,18 +180,16 @@ async fn fetch(client: &Client, url: &str, cache: &Cache, now: u64) -> reqwest::
.get(url)
.header(header::USER_AGENT, "iphone-control-update")
.header(header::ACCEPT, "application/vnd.github+json");
- if let Some(etag) = &cache.etag {
+ // Fetch a complete representation once for legacy caches, even if the release itself hasn't changed.
+ let etag = cache.etag.as_ref().filter(|_| cache.release.as_ref().is_some_and(|r| r.notes.is_some()));
+ if let Some(etag) = etag {
req = req.header(header::IF_NONE_MATCH, etag);
}
let mut res = req.send().await?;
let status = res.status();
let headers = res.headers();
if status == StatusCode::NOT_MODIFIED {
- return Ok(if cache.release.is_some() && cache.etag.is_some() {
- Fetch::Unchanged
- } else {
- Fetch::Failed("invalid_release", None)
- });
+ return Ok(if etag.is_some() { Fetch::Unchanged } else { Fetch::Failed("invalid_release", None) });
}
if status == StatusCode::TOO_MANY_REQUESTS
|| (status == StatusCode::FORBIDDEN
@@ -248,6 +307,65 @@ mod tests {
write_json(&dir.join("release.json"), &cache).unwrap();
}
+ #[test]
+ fn release_notes_select_changelog_without_shared_install_footer() {
+ let body = "## English\r\n\r\n### Added\r\n- Faster video\r\n\r\n## 中文\r\n\r\n### 新增\r\n- 画面更流畅\r\n\r\n---\r\n\r\n**Binaries / 二进制:** packages\r\n**Installer:** command";
+ let notes = ReleaseNotes::from_body(body);
+ assert_eq!(notes.for_lang(Lang::En).as_deref(), Some("### Added\r\n- Faster video"));
+ assert_eq!(notes.for_lang(Lang::Zh).as_deref(), Some("### 新增\r\n- 画面更流畅"));
+ let notes = ReleaseNotes::from_body("## English\n## What's new\n- New video\n## 中文\n## 更新内容\n- 新画面");
+ assert_eq!(notes.for_lang(Lang::En).as_deref(), Some("## What's new\n- New video"));
+ assert_eq!(notes.for_lang(Lang::Zh).as_deref(), Some("## 更新内容\n- 新画面"));
+ }
+
+ #[test]
+ fn release_notes_fall_back_to_available_text_and_bound_each_language_separately() {
+ for (body, expected) in [
+ ("## 中文\n修复", Some("修复")),
+ ("## 中文\n\n## English\nFixed", Some("Fixed")),
+ (" A single paragraph.\n", Some("A single paragraph.")),
+ ("## English\n\n## 中文\n", None),
+ (" \r\n", None),
+ ] {
+ for lang in [Lang::En, Lang::Zh] {
+ assert_eq!(ReleaseNotes::from_body(body).for_lang(lang).as_deref(), expected);
+ }
+ }
+ let body = format!("## English\n{}\n## 中文\n修复", "🎉".repeat(MAX_NOTES_BYTES));
+ let notes = ReleaseNotes::from_body(&body);
+ let en = notes.for_lang(Lang::En).unwrap();
+ assert!(en.ends_with('…') && en.len() <= MAX_NOTES_BYTES);
+ assert_eq!(notes.for_lang(Lang::Zh).as_deref(), Some("修复"));
+ }
+
+ #[tokio::test]
+ async fn legacy_cache_is_backfilled_on_next_due_check_then_keeps_its_etag() {
+ let dir = tempfile::tempdir().unwrap();
+ let old = serde_json::json!({"release": {"tag": "v1.2.3", "assets": ["prior"]}, "etag": "\"tag-1\""});
+ write_json(&dir.path().join("release.json"), &old).unwrap();
+ let legacy = read(dir.path()).unwrap().release.unwrap();
+ assert_eq!(legacy.assets, ["prior"]);
+ assert!(legacy.notes.is_none());
+
+ let mut release: serde_json::Value = serde_json::from_str(RELEASE).unwrap();
+ release["body"] = "## English\nNew video\n## 中文\n新画面".into();
+ let (url, requests) = server(vec![
+ response("200 OK", "ETag: \"tag-1\"\r\n", &release.to_string()),
+ response("304 Not Modified", "", ""),
+ ])
+ .await;
+ let http = local_client();
+ check(dir.path(), &http, &url, false).await.unwrap();
+ make_due(dir.path());
+ let fresh = check(dir.path(), &http, &url, false).await.unwrap();
+ let notes = fresh.release.unwrap().notes.unwrap();
+ assert_eq!(notes.for_lang(Lang::Zh).as_deref(), Some("新画面"));
+ assert_eq!(notes.for_lang(Lang::En).as_deref(), Some("New video"));
+ let requests = requests.await.unwrap();
+ assert!(!requests[0].contains("if-none-match:"));
+ assert!(requests[1].contains("if-none-match: \"tag-1\""));
+ }
+
#[test]
fn release_requires_stable_semver_and_uploaded_assets() {
for tag in ["v01.2.3", "v1.2", "v1.2.3-rc.1", "v1.2.3+local", "v1.2.3/another", "v1.2.3 ", "1.2.3"] {
diff --git a/apps/iphone-control/src/video/device.rs b/apps/iphone-control/src/video/device.rs
index e9f065c..6568877 100644
--- a/apps/iphone-control/src/video/device.rs
+++ b/apps/iphone-control/src/video/device.rs
@@ -21,7 +21,7 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpStream;
use tokio::sync::mpsc;
-use super::{AbortOnDrop, Acks, Flow, QUEUE, message};
+use super::{AbortOnDrop, Acks, Flow, QUEUE, STREAM_IDLE, message, send_video};
/// Asking for keyframes at most this often while dropping frames
const ASK_EVERY: Duration = Duration::from_millis(500);
@@ -47,7 +47,6 @@ pub async fn serve(
acks: Arc<Acks>,
client: TcpStream,
) {
- let (mut client_rd, mut client_wr) = client.into_split();
let (ack_guard, mut acked) = acks.register();
let mut flow = Flow::default();
@@ -71,30 +70,15 @@ pub async fn serve(
});
let _reader = AbortOnDrop(reader);
- let (gone_tx, mut gone) = tokio::sync::oneshot::channel::<()>();
- let watcher = tokio::spawn(async move {
- let mut b = [0u8; 256];
- while matches!(client_rd.read(&mut b).await, Ok(n) if n > 0) {}
- let _ = gone_tx.send(());
- });
- let _watcher = AbortOnDrop(watcher);
-
- let (out_tx, mut out_rx) = mpsc::channel::<Vec<u8>>(QUEUE);
- let writer = tokio::spawn(async move {
- while let Some(m) = out_rx.recv().await {
- if client_wr.write_all(&m).await.is_err() {
- return;
- }
- }
- });
- let _writer = AbortOnDrop(writer);
+ let (out_tx, out_rx) = mpsc::channel(QUEUE);
+ let _writer = AbortOnDrop(tokio::spawn(send_video(client, out_rx, STREAM_IDLE)));
// dropping frames until a keyframe (the page fell behind, or its queue was full)
let mut need_key = false;
let mut asked: Option<Instant> = None;
loop {
tokio::select! {
- _ = &mut gone => return,
+ _ = out_tx.closed() => return,
m = msgs.recv() => {
let Some((kind, body)) = m else { return };
let now = Instant::now();
diff --git a/apps/iphone-control/src/video/mod.rs b/apps/iphone-control/src/video/mod.rs
index 299e7e0..7e84579 100644
--- a/apps/iphone-control/src/video/mod.rs
+++ b/apps/iphone-control/src/video/mod.rs
@@ -37,7 +37,7 @@ use std::sync::Arc;
use std::time::{Duration, Instant};
use serde_json::json;
-use tokio::io::{AsyncRead, AsyncReadExt, AsyncWriteExt};
+use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
use tokio::net::TcpStream;
use tokio::sync::{mpsc, watch};
@@ -50,6 +50,8 @@ pub fn device_allowed() -> bool {
.is_none_or(|v| v.eq_ignore_ascii_case("auto") || v.eq_ignore_ascii_case("device"))
}
+/// Maximum time to read a WDA frame or wait for progress writing to the page. WDA repeats even still frames.
+pub(super) const STREAM_IDLE: Duration = Duration::from_secs(8);
/// Messages waiting for the page; more means it is falling behind
const QUEUE: usize = 8;
/// Restarting for a keyframe at most this often (a link too slow for the picture would otherwise restart all the
@@ -205,7 +207,6 @@ pub async fn serve(
src: impl AsyncRead + Unpin + Send + 'static,
client: TcpStream,
) {
- let (mut client_rd, mut client_wr) = client.into_split();
let (ack_guard, mut acked) = acks.register();
let mut flow = Flow::default();
@@ -215,8 +216,8 @@ pub async fn serve(
let mut f = mjpeg::Frames::new(src);
let mut last: Option<Arc<Vec<u8>>> = None;
loop {
- match f.next().await {
- Ok(Some(j)) => {
+ match tokio::time::timeout(STREAM_IDLE, f.next()).await {
+ Ok(Ok(Some(j))) => {
if last.as_ref().is_some_and(|l| **l == j) {
continue;
}
@@ -226,8 +227,8 @@ pub async fn serve(
return;
}
}
- Ok(None) => return,
- Err(e) => {
+ Err(_) | Ok(Ok(None)) => return,
+ Ok(Err(e)) => {
tracing::debug!("MJPEG stream: {e}");
return;
}
@@ -236,25 +237,8 @@ pub async fn serve(
});
let _reader = AbortOnDrop(reader);
- // the page reads nothing after the request: a read that ends means it went away (a still screen sends nothing,
- // so a failed write wouldn't notice)
- let (gone_tx, mut gone) = tokio::sync::oneshot::channel::<()>();
- let watcher = tokio::spawn(async move {
- let mut b = [0u8; 256];
- while matches!(client_rd.read(&mut b).await, Ok(n) if n > 0) {}
- let _ = gone_tx.send(());
- });
- let _watcher = AbortOnDrop(watcher);
-
- let (out_tx, mut out_rx) = mpsc::channel::<Vec<u8>>(QUEUE);
- let writer = tokio::spawn(async move {
- while let Some(m) = out_rx.recv().await {
- if client_wr.write_all(&m).await.is_err() {
- return;
- }
- }
- });
- let _writer = AbortOnDrop(writer);
+ let (out_tx, out_rx) = mpsc::channel(QUEUE);
+ let _writer = AbortOnDrop(tokio::spawn(send_video(client, out_rx, STREAM_IDLE)));
let mut session: Option<ffmpeg::Session> = None;
let mut last: Option<Arc<Vec<u8>>> = None;
@@ -270,7 +254,7 @@ pub async fn serve(
loop {
let ev = tokio::select! {
- _ = &mut gone => return,
+ _ = out_tx.closed() => return,
r = frames.changed() => match r {
Ok(()) => Ev::Frame(frames.borrow_and_update().clone()),
// the phone's stream ended (unplugged, WDA restarted): the page reconnects
@@ -391,12 +375,16 @@ fn start(enc: &Encoders, size: (u32, u32)) -> Option<ffmpeg::Session> {
/// those (seen on Chrome 14x), and on a still screen no next frame would come. So the parts carry no
/// `Content-Length` (the next one isn't known yet); browsers cut at the boundary anyway. The HTTP response head is
/// written here
-pub async fn serve_mjpeg(src: impl AsyncRead + Unpin + Send + 'static, mut client: TcpStream) {
- let (tx, mut rx) = watch::channel::<Option<Arc<Vec<u8>>>>(None);
+pub async fn serve_mjpeg(
+ src: impl AsyncRead + Unpin + Send + 'static,
+ client: impl AsyncRead + AsyncWrite + Unpin,
+ idle: Duration,
+) {
+ let (tx, rx) = watch::channel::<Option<Arc<Vec<u8>>>>(None);
let reader = tokio::spawn(async move {
let mut f = mjpeg::Frames::new(src);
let mut last: Option<Vec<u8>> = None;
- while let Ok(Some(j)) = f.next().await {
+ while let Ok(Ok(Some(j))) = tokio::time::timeout(idle, f.next()).await {
if last.as_ref() == Some(&j) {
continue;
}
@@ -407,12 +395,25 @@ pub async fn serve_mjpeg(src: impl AsyncRead + Unpin + Send + 'static, mut clien
}
});
let _reader = AbortOnDrop(reader);
+ let (rd, wr) = tokio::io::split(client);
+ tokio::select! {
+ _ = client_disconnected(rd) => {}
+ _ = write_mjpeg(wr, rx, idle) => {}
+ }
+}
+
+async fn write_mjpeg(
+ mut client: impl AsyncWrite + Unpin,
+ mut rx: watch::Receiver<Option<Arc<Vec<u8>>>>,
+ idle: Duration,
+) {
const NEXT: &[u8] = b"\r\n--ictl\r\nContent-Type: image/jpeg\r\n\r\n";
let head =
b"HTTP/1.1 200 OK\r\nContent-Type: multipart/x-mixed-replace; boundary=ictl\r\nCache-Control: no-store\r\n\
X-Content-Type-Options: nosniff\r\nConnection: close\r\n\r\n";
// the first part's boundary and headers, without the line break that ends a part
- if client.write_all(head).await.is_err() || client.write_all(&NEXT[2..]).await.is_err() {
+ let header = [head.as_slice(), &NEXT[2..]].concat();
+ if !write_with_progress(&mut client, &header, idle).await {
return;
}
while rx.changed().await.is_ok() {
@@ -420,12 +421,47 @@ pub async fn serve_mjpeg(src: impl AsyncRead + Unpin + Send + 'static, mut clien
let mut part = Vec::with_capacity(j.len() + NEXT.len());
part.extend_from_slice(&j);
part.extend_from_slice(NEXT);
- if client.write_all(&part).await.is_err() {
+ if !write_with_progress(&mut client, &part, idle).await {
return;
}
}
}
+// A still picture may never need another write. Watch the request socket for EOF as well.
+async fn client_disconnected(mut reader: impl AsyncRead + Unpin) {
+ let mut buf = [0; 256];
+ while matches!(reader.read(&mut buf).await, Ok(n) if n > 0) {}
+}
+
+// A large keyframe can take time over a tunnel. Apply the idle limit between successful writes.
+async fn write_with_progress(writer: &mut (impl AsyncWrite + Unpin), mut data: &[u8], idle: Duration) -> bool {
+ while !data.is_empty() {
+ match tokio::time::timeout(idle, writer.write(data)).await {
+ Ok(Ok(n)) if n > 0 => data = &data[n..],
+ _ => return false,
+ }
+ }
+ true
+}
+
+async fn send_video(
+ client: impl AsyncRead + AsyncWrite + Unpin,
+ mut messages: mpsc::Receiver<Vec<u8>>,
+ idle: Duration,
+) {
+ let (rd, mut wr) = tokio::io::split(client);
+ tokio::select! {
+ _ = client_disconnected(rd) => {}
+ _ = async {
+ while let Some(msg) = messages.recv().await {
+ if !write_with_progress(&mut wr, &msg, idle).await {
+ return;
+ }
+ }
+ } => {}
+ }
+}
+
struct AbortOnDrop(tokio::task::JoinHandle<()>);
impl Drop for AbortOnDrop {
@@ -445,6 +481,45 @@ async fn next_packet(s: &mut Option<ffmpeg::Session>) -> Option<Result<Packet, S
mod tests {
use super::*;
+ #[tokio::test]
+ async fn leaving_a_still_mjpeg_picture_releases_the_source() {
+ let (mut phone, src) = tokio::io::duplex(512);
+ let (client, mut browser) = tokio::io::duplex(512);
+ let relay = tokio::spawn(serve_mjpeg(src, client, Duration::from_secs(30)));
+ phone
+ .write_all(b"HTTP/1.1 200 OK\r\n\r\n--wda\r\nContent-Length: 4\r\n\r\n\xff\xd8\xff\xd9\r\n")
+ .await
+ .unwrap();
+
+ tokio::time::timeout(Duration::from_secs(2), async {
+ let mut frame = Vec::new();
+ tokio::io::AsyncBufReadExt::read_until(&mut tokio::io::BufReader::new(&mut browser), 0xd9, &mut frame)
+ .await
+ .unwrap();
+ assert!(frame.ends_with(b"\xff\xd8\xff\xd9"));
+ drop(browser);
+ relay.await.unwrap();
+ assert_eq!(phone.read(&mut [0]).await.unwrap(), 0);
+ })
+ .await
+ .expect("closing the page releases the source without waiting for another picture");
+ }
+
+ #[tokio::test]
+ async fn video_writer_closes_the_encoder_queue_if_output_stops_making_progress() {
+ let (client, mut browser) = tokio::io::duplex(2);
+ let (tx, rx) = mpsc::channel(1);
+ let writer = tokio::spawn(send_video(client, rx, Duration::from_millis(40)));
+ tx.send(vec![1, 2, 3, 4, 5]).await.unwrap();
+ tokio::time::timeout(Duration::from_secs(2), async {
+ assert_eq!(browser.read_u8().await.unwrap(), 1);
+ tx.closed().await;
+ writer.await.unwrap();
+ })
+ .await
+ .expect("the encoder is notified when its writer gives up");
+ }
+
/// A page that confirms in time is never behind; one whose confirmations stop coming is, once the oldest
/// unconfirmed message is older than the usual round trip plus the slack
#[test]
diff --git a/apps/iphone-control/src/viewer.html b/apps/iphone-control/src/viewer.html
index c0cf983..3aca8cf 100644
--- a/apps/iphone-control/src/viewer.html
+++ b/apps/iphone-control/src/viewer.html
@@ -69,24 +69,35 @@
/* ================= 设计变量 ================= */
:root {
- color-scheme: light dark;
- --font-ui: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
- --font-mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Mono", Menlo, Consolas, monospace;
+ color-scheme: light;
+ --font-ui: -apple-system, BlinkMacSystemFont, system-ui, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
+ --font-mono: "SF Mono", SFMono-Regular, ui-monospace, Menlo, Consolas, monospace;
- --fs-2xs: 12px; --fs-xs: 13px; --fs-sm: 14px; --fs-md: 16px; --fs-lg: 18px; --fs-xl: 26px;
+ --fs-2xs: .75rem; --fs-xs: .8125rem; --fs-sm: .875rem; --fs-lg: 1rem; --fs-xl: 1.1875rem;
--sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
--r-xs: 6px; --r-sm: 8px; --r-md: 10px; --r-lg: 14px; --r-xl: 18px; --r-2xl: 20px;
--gutter: 12px;
- --head-h: 64px;
+ --head-h: max(54px, 3.25rem);
--w-agent: 460px; --w-dev: 344px;
--dur-fast: 150ms; --dur: 220ms; --dur-slow: 300ms; --dur-exit: 150ms;
--ease-out: cubic-bezier(.2, .7, .2, 1); --ease-in: cubic-bezier(.4, 0, 1, 1);
- /* 浅色:冷调浅灰底,白色面板浮在上面;深青绿只用来点睛 */
- --canvas: #eaedf0; --panel: #ffffff; --sunken: #f4f6f8; --hover: #eff2f4; --press: #e5e9ec;
+ /* Frosted workspace surfaces; --glass-surface stays opaque without blur support. */
+ --canvas-light: #f7f9fb;
+ --canvas-shade: #cddae2;
+ --glass-tint: rgb(252 253 255 / 67%);
+ --glass-surface: var(--panel);
+ --glass-border: rgb(54 75 93 / 19%);
+ --glass-highlight: rgb(255 255 255 / 87%);
+ --glass-shadow: inset 0 1px 0 var(--glass-highlight), 0 3px 12px -6px rgb(16 36 52 / 16%);
+ --glass-blur: none;
+ --workspace-light: linear-gradient(127deg, var(--canvas-light) 0%, transparent 42%, var(--canvas-shade) 73%, transparent 100%);
+
+ /* 浅色外观 */
+ --canvas: #e2e9ed; --panel: #ffffff; --sunken: #f4f6f8; --hover: #eff2f4; --press: #e5e9ec;
--line: #e3e7ea; --line-strong: #cbd2d8; --panel-edge: rgba(16, 24, 32, .07);
--text: #11161a; --text-2: #3b444c; --muted: #5f6a73;
- --accent: #0d6e5f; --accent-hover: #0a5a4e; --on-accent: #ffffff; --accent-soft: #e5f3ef; --accent-line: #c3e3d9; --accent-text: #0a5a4e;
+ --accent: #365b7c; --accent-hover: #294965; --on-accent: #ffffff; --accent-soft: #e2eaf1; --accent-line: #bfcedc; --accent-text: #2e4e69;
--user: #2457d6; --user-soft: #e9effc; --user-text: #1f48b3;
--ai: #10937c;
--danger: #c0352b; --danger-hover: #9f2a22; --on-danger: #ffffff; --danger-soft: #fdeeec; --danger-line: #f4cdc8; --danger-text: #a52c23;
@@ -99,12 +110,18 @@
--shadow-float: 0 2px 6px rgba(16, 24, 32, .06), 0 12px 32px rgba(16, 24, 32, .10);
--shadow-phone: 0 4px 10px rgba(16, 24, 32, .08), 0 36px 64px -16px rgba(16, 24, 32, .32);
}
-@media (prefers-color-scheme: dark) {
- :root {
- --canvas: #07090a; --panel: #111518; --sunken: #0b0e10; --hover: #191e22; --press: #20262b;
+:root[data-scheme="dark"] {
+ color-scheme: dark;
+ --canvas-light: #28323b;
+ --canvas-shade: #34434d;
+ --glass-tint: rgb(27 33 39 / 79%);
+ --glass-border: rgb(191 212 230 / 20%);
+ --glass-highlight: rgb(238 248 255 / 8%);
+ --glass-shadow: inset 0 1px 0 var(--glass-highlight), 0 4px 14px -5px rgb(0 0 0 / 28%);
+ --canvas: #222428; --panel: #111518; --sunken: #0b0e10; --hover: #191e22; --press: #20262b;
--line: #20262b; --line-strong: #333b42; --panel-edge: rgba(255, 255, 255, .07);
--text: #e8ecef; --text-2: #c2c9cf; --muted: #96a0aa;
- --accent: #3ccaa9; --accent-hover: #67dbc0; --on-accent: #03201a; --accent-soft: rgba(60, 202, 169, .12); --accent-line: rgba(60, 202, 169, .30); --accent-text: #7ae0c8;
+ --accent: #a1c8ef; --accent-hover: #bdd9f6; --on-accent: #162536; --accent-soft: #273746; --accent-line: #42596d; --accent-text: #b8d5ee;
--user: #8ab4f8; --user-soft: rgba(138, 180, 248, .14); --user-text: #aac8fa;
--ai: #3ccaa9;
--danger: #f2827a; --danger-hover: #f6a39d; --on-danger: #2a0806; --danger-soft: rgba(242, 130, 122, .12); --danger-line: rgba(242, 130, 122, .30); --danger-text: #f8b0aa;
@@ -116,13 +133,14 @@
--shadow-panel: none;
--shadow-float: 0 2px 6px rgba(0, 0, 0, .4), 0 12px 32px rgba(0, 0, 0, .45);
--shadow-phone: 0 36px 64px -16px rgba(0, 0, 0, .7);
- }
}
+:root[data-text-size="large"] { font-size:112.5%; }
+:root[data-text-size="xlarge"] { font-size:125%; }
/* ================= 基础 ================= */
* { box-sizing: border-box; }
html, body { height: 100%; }
-body { margin: 0; background: var(--canvas); color: var(--text); font: var(--fs-md)/1.55 var(--font-ui); -webkit-font-smoothing: antialiased; }
+body { margin: 0; background: var(--workspace-light), var(--canvas); color: var(--text); font: var(--fs-sm)/1.55 var(--font-ui); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button, input, textarea, select { font: inherit; color: inherit; }
@@ -140,7 +158,7 @@ code, .mono { font-family: var(--font-mono); }
display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
min-height: 40px; padding: 0 var(--sp-4); border-radius: var(--r-md);
border: 1px solid var(--line); background: var(--panel); color: var(--text); box-shadow: var(--shadow-xs);
- font-size: var(--fs-sm); font-weight: 600; cursor: pointer; white-space: nowrap; --od-icon-size: 18px;
+ font-size: var(--fs-sm); font-weight: 500; cursor: pointer; white-space: nowrap; --od-icon-size: 16px;
transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
@media (hover: hover) { .btn:hover:not(:disabled) { background: var(--hover); border-color: var(--line-strong); color: var(--text); } }
@@ -169,7 +187,7 @@ code, .mono { font-family: var(--font-mono); }
.tone-muted { background: var(--sunken); color: var(--muted); box-shadow: inset 0 0 0 1px var(--line); }
.t-accent { color: var(--accent-text); } .t-ok { color: var(--ok-text); } .t-danger { color: var(--danger-text); } .t-warn { color: var(--warn-text); } .t-muted { color: var(--muted); } .t-user { color: var(--user-text); }
-.input, .select {
+.input {
width: 100%; min-height: 40px; padding: 0 var(--sp-3); border-radius: var(--r-md);
border: 1px solid transparent; background: var(--sunken); color: var(--text); font-size: var(--fs-sm);
transition: background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out);
@@ -177,15 +195,15 @@ code, .mono { font-family: var(--font-mono); }
@media (hover: hover) { .input:hover:not(:disabled):not(:focus) { border-color: var(--line); } }
.input:focus { background: var(--panel); border-color: var(--line-strong); }
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: 1; }
-.input:disabled, .select:disabled { color: var(--muted); cursor: not-allowed; }
-.input:focus-visible, .select:focus-visible { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
+.input:disabled { color: var(--muted); cursor: not-allowed; }
+.input:focus-visible { outline: 2px solid var(--focus); outline-offset: -1px; border-color: transparent; }
.label { display: block; font-size: var(--fs-xs); font-weight: 600; color: var(--muted); margin-bottom: 6px; }
/* ================= 外壳:浮在浅底上的三栏 ================= */
.shell { display: grid; grid-template-columns: var(--w-agent) minmax(0, 1fr) var(--w-dev); grid-template-rows: minmax(0, 1fr); gap: var(--gutter); padding: var(--gutter); height: 100dvh; }
.mbar { display: none; }
.pane { display: grid; grid-template-rows: var(--head-h) minmax(0, 1fr) auto; min-height: 0; min-width: 0; }
-.pane-agent, .pane-dev { position: relative; background: var(--panel); border-radius: var(--r-2xl); box-shadow: 0 0 0 1px var(--panel-edge), var(--shadow-panel); }
+.pane-agent, .pane-dev { position: relative; border-radius: var(--r-2xl); }
/* 拖拽手柄放在面板之间的缝隙里:悬停、聚焦、拖动时显示主色细线 */
.resizer { position: absolute; top: var(--sp-4); bottom: var(--sp-4); right: calc(var(--gutter) * -1); width: var(--gutter); z-index: 5; cursor: col-resize; touch-action: none; display: flex; justify-content: center; }
.resizer.resizer-left { right: auto; left: calc(var(--gutter) * -1); }
@@ -199,22 +217,21 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.pane-body { overflow-y: auto; overscroll-behavior: contain; min-height: 0; scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
-.brand-mark { flex: none; width: 32px; height: 32px; padding: 3px; border-radius: 9px; background: var(--accent-soft); color: var(--accent-text); }
+.brand-mark { flex: none; width: 26px; height: 26px; padding: 3px; border-radius: 7px; background: var(--accent-soft); color: var(--accent-text); }
.brand-text { display: grid; line-height: 1.25; }
-.brand-name { display: block; font-family: var(--font-mono); font-size: var(--fs-sm); font-weight: 600; letter-spacing: -.01em; }
+.brand-name { display: block; font-family: var(--font-ui); font-size: var(--fs-sm); font-weight: 600; letter-spacing: -.01em; }
.brand-sub { display: block; font-size: var(--fs-2xs); color: var(--muted); }
.pane-head .badge { margin-left: auto; }
.clear-btn { flex: none; }
-.lang-btn { flex: none; margin-left: auto; min-width: 44px; font-weight: 600; }
/* ================= 左栏:AI 助手 ================= */
-.convo { padding: var(--sp-8) var(--sp-6) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-6); }
-.intro { display: flex; flex-direction: column; gap: var(--sp-5); }
-.intro-title { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.02em; line-height: 1.25; outline-offset: 4px; }
-.intro-text { color: var(--text-2); }
+.convo { padding: var(--sp-6) var(--sp-6) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-6); font-size: var(--fs-sm); }
+.intro { display: flex; flex-direction: column; gap: var(--sp-4); }
+.intro-title { font-size: var(--fs-xl); font-weight: 600; line-height: 1.35; letter-spacing: -.01em; outline-offset: 4px; }
+.intro-text { color: var(--text-2); text-wrap: pretty; }
.caps { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3) var(--sp-4); }
.cap { display: flex; align-items: center; gap: 10px; font-size: var(--fs-sm); color: var(--text-2); min-width: 0; }
-.cap .ic { flex: none; width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; background: var(--sunken); box-shadow: inset 0 0 0 1px var(--line); color: var(--accent-text); --od-icon-size: 16px; }
+.cap .ic { flex: none; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 7px; background: var(--sunken); color: var(--accent-text); --od-icon-size: 16px; }
.demo-note { font-size: var(--fs-xs); color: var(--warn-text); background: var(--warn-soft); padding: 10px var(--sp-3); border-radius: var(--r-md); }
.turns { display: flex; flex-direction: column; gap: var(--sp-8); }
@@ -230,7 +247,7 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.bubble:disabled { cursor: default; }
.msg-meta { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; justify-content: flex-end; min-height: 28px; }
.msg-time { display: block; font-size: var(--fs-2xs); color: var(--muted); font-variant-numeric: tabular-nums; margin-right: var(--sp-1); }
-.mini { display: inline-flex; align-items: center; gap: 4px; min-height: 28px; padding: 0 var(--sp-2); border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); font-size: var(--fs-2xs); font-weight: 600; cursor: pointer; white-space: nowrap; --od-icon-size: 14px; transition: opacity var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out); }
+.mini { display: inline-flex; align-items: center; gap: 4px; min-height: 28px; padding: 0 var(--sp-2); border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); font-size: var(--fs-2xs); font-weight: 600; cursor: pointer; white-space: nowrap; --od-icon-size: 16px; transition: opacity var(--dur-fast) var(--ease-out), background-color var(--dur-fast) var(--ease-out); }
@media (hover: hover) {
.mini:hover:not(:disabled) { background: var(--hover); color: var(--text); }
.mini.danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger-text); }
@@ -248,7 +265,7 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.agent-name { font-weight: 600; font-size: var(--fs-sm); }
.agent-meta { font-size: var(--fs-2xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.agent-line .badge { margin-left: auto; }
-.toggle-steps { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 var(--sp-2); margin-left: -8px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); font-size: var(--fs-xs); font-weight: 600; cursor: pointer; --od-icon-size: 14px; }
+.toggle-steps { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 var(--sp-2); margin-left: -8px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--muted); font-size: var(--fs-xs); font-weight: 600; cursor: pointer; --od-icon-size: 16px; }
@media (hover: hover) { .toggle-steps:hover { background: var(--hover); color: var(--text); } }
.toggle-steps .od-icon { transition: transform var(--dur) var(--ease-out); }
.toggle-steps[aria-expanded="true"] .od-icon { transform: rotate(180deg); }
@@ -260,14 +277,14 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.step-line { flex: 1; width: 1.5px; border-radius: 1px; background: var(--line); margin-top: 4px; min-height: 8px; }
.step:last-child .step-line { visibility: hidden; }
.step-body { display: flex; flex-direction: column; gap: 6px; padding-bottom: var(--sp-5); min-width: 0; }
-.step-thought { font-size: var(--fs-md); line-height: 1.5; color: var(--text); overflow-wrap: anywhere; }
+.step-thought { font-size: var(--fs-sm); line-height: 1.5; color: var(--text); overflow-wrap: anywhere; }
.step-result { font-size: var(--fs-sm); color: var(--muted); overflow-wrap: anywhere; }
.step-result.err { color: var(--danger-text); }
.confirm { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-4); border-radius: var(--r-lg); background: var(--warn-soft); box-shadow: inset 0 0 0 1px var(--warn-line); margin-top: var(--sp-1); }
.confirm-title { display: flex; align-items: center; gap: var(--sp-2); font-weight: 600; color: var(--warn-text); --od-icon-size: 18px; }
.confirm-detail { overflow-wrap: anywhere; color: var(--text); }
.confirm .od-cluster { margin-top: var(--sp-1); }
-.answer { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--sp-3); padding: 14px var(--sp-4); border-radius: var(--r-lg); --od-icon-size: 20px; }
+.answer { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--sp-3); padding: 14px var(--sp-4); border-radius: var(--r-lg); --od-icon-size: 18px; }
.answer.tone-ok { box-shadow: inset 0 0 0 1px var(--accent-line); }
.answer.tone-danger { box-shadow: inset 0 0 0 1px var(--danger-line); }
.answer > .od-icon { margin-top: 2px; }
@@ -275,48 +292,67 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.answer-title { display: block; font-weight: 600; font-size: var(--fs-sm); }
.answer-body { display: block; color: var(--text); overflow-wrap: anywhere; }
-.agent-foot { padding: var(--sp-3) var(--sp-4) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); }
-.composer { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--r-xl); background: var(--panel); box-shadow: var(--shadow-float); overflow: hidden; transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out); }
-.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-float); }
+.agent-foot { min-width: 0; padding: 8px var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-2); }
+.composer { display: flex; flex-direction: column; min-width: 0; border: 1px solid var(--glass-border); border-radius: 16px; background: var(--panel); box-shadow: var(--shadow-xs); overflow: hidden; transition: border-color var(--dur-fast) var(--ease-out); }
+.composer:has(.textarea:focus-visible) { border-color: var(--accent); }
.composer.invalid { border-color: var(--danger); }
/* 执行中的暂停 / 接管 / 停止并到输入框顶部 */
.runbar { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; padding: var(--sp-2) var(--sp-2) var(--sp-2) 14px; background: var(--sunken); border-bottom: 1px solid var(--line); }
.runbar-state { flex: 1 1 120px; display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); font-weight: 600; min-width: 0; --od-icon-size: 16px; }
.runbar-time { font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
-.textarea { display: block; width: 100%; min-height: 60px; max-height: 176px; resize: none; padding: 14px var(--sp-4) 0; border: 0; background: transparent; color: var(--text); font-size: var(--fs-md); line-height: 1.55; overflow-y: auto; }
+.textarea { display: block; width: 100%; min-height: 44px; max-height: 176px; resize: none; padding: 11px 12px 6px; border: 0; background: transparent; color: var(--text); font-size: var(--fs-sm); line-height: 1.5; overflow-y: auto; }
.textarea:focus-visible { outline: none; }
.textarea:disabled { color: var(--muted); cursor: not-allowed; }
-.composer-row { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-4); }
-.composer-hint { flex: 1; font-size: var(--fs-2xs); color: var(--muted); }
-.agent-pick { flex: none; }
-.agent-pick .select { min-height: 30px; max-width: 160px; padding: 0 26px 0 10px; border-radius: var(--r-sm); background: var(--sunken); color: var(--text-2); font-size: var(--fs-2xs); font-weight: 500; transition: background var(--dur-fast) var(--ease-out); }
-.agent-pick .select:hover:not(:disabled) { background: var(--hover); }
-.agent-pick .select:disabled { opacity: .6; cursor: default; }
-.agent-pick .select-chev { margin-right: 6px; --od-icon-size: 14px; }
-.send { width: 44px; height: 44px; padding: 0; border-radius: 12px; --od-icon-size: 20px; }
+.composer-row { display: flex; align-items: center; justify-content: flex-end; min-width: 0; gap: 6px; padding: 0 8px 8px; }
+.agent-pick { flex: 0 1 auto; min-width: 0; max-width: min(11rem, calc(100% - 52px)); }
+.picker-trigger { display: flex; align-items: center; gap: 4px; max-width: 100%; min-height: 32px; padding: 0 6px; border: 0; border-radius: 7px; background: transparent; color: var(--text-2); font-size: var(--fs-xs); font-weight: 500; cursor: pointer; }
+.picker-trigger .ic { flex: none; color: var(--muted); --od-icon-size: 12px; }
+.picker-trigger[aria-expanded="true"], .picker-trigger:hover:enabled { background: var(--hover); }
+.picker-trigger[aria-expanded="true"] .ic { transform: rotate(180deg); }
+.picker-trigger:focus-visible { outline-color: var(--accent); outline-offset: 0; }
+.picker-trigger:disabled { color: var(--muted); cursor: default; }
+.picker-menu { position: fixed; inset: auto; margin: 0; width: max-content; min-width: min(9.5rem, calc(100vw - 16px)); max-width: calc(100vw - 16px); overflow: auto; padding: 4px; border-radius: 12px; color: var(--text); font-size: var(--fs-xs); }
+.picker-menu.glass { background-color: color-mix(in srgb, var(--panel) 75%, var(--glass-surface)); box-shadow: var(--shadow-float); }
+.picker-menu:focus { outline: none; }
+.picker-option { display: flex; align-items: center; justify-content: space-between; gap: 14px; min-height: 32px; padding: 4px 8px; border-radius: 8px; cursor: pointer; }
+.picker-option > span { min-width: 0; overflow-wrap: anywhere; }
+.picker-option .od-icon { --od-icon-size: 14px; color: var(--text-2); }
+.picker-option[aria-selected="false"] .od-icon { visibility: hidden; }
+.picker-option[aria-disabled="true"] { color: var(--muted); cursor: default; }
+.picker-option[data-active] { background: var(--hover); }
+.picker-menu:focus-visible .picker-option[data-active] { outline: 1px solid var(--accent); outline-offset: -1px; }
+.send { flex: none; width: 32px; min-height: 32px; height: 32px; padding: 0; border-radius: 50%; --od-icon-size: 16px; }
+.composer .send { background: var(--text); color: var(--panel); border: 0; box-shadow: none; }
+.composer .send:hover:not(:disabled) { background: var(--text-2); }
+.composer .send:disabled { background: var(--press); color: var(--muted); opacity: .75; }
+.sidebar-settings {
+ display: inline-flex; align-items: center; gap: 8px; padding: 0 8px; min-height: 32px;
+ border: 0; border-radius: 7px; background: transparent; font-size: var(--fs-xs); cursor: pointer;
+ align-self: stretch; color: var(--text-2); --od-icon-size: 16px;
+}
+@media (hover: hover) {
+ .sidebar-settings:hover { background: var(--hover); color: var(--text); }
+}
+@media (pointer: coarse) {
+ .send { width: 44px; min-height: 44px; height: 44px; }
+ .picker-trigger, .picker-option, .sidebar-settings { min-height: 44px; }
+}
.field-error { font-size: var(--fs-xs); color: var(--danger-text); font-weight: 500; padding: 0 var(--sp-2); }
/* ================= 中间:设备舞台 ================= */
-.pane-stage { grid-template-rows: var(--head-h) minmax(0, 1fr) auto; }
+.pane-stage { container: preview / inline-size; grid-template-rows: var(--head-h) minmax(0, 1fr) auto; }
.stage-head { border-bottom: 0; padding: 0 var(--sp-1); gap: var(--sp-3); }
/* 设备选择和状态合成一条分段状态栏 */
-.statusbar { display: flex; align-items: center; min-width: 0; height: 44px; padding: 4px; border-radius: var(--r-lg); background: var(--panel); box-shadow: 0 0 0 1px var(--panel-edge), var(--shadow-xs); }
+.statusbar { display: flex; align-items: center; min-width: 0; height: 44px; padding: 4px; border-radius: var(--r-lg); }
.dev-select { display: flex; align-items: center; gap: 6px; min-width: 0; padding-left: 10px; }
.dev-select .label { margin: 0; white-space: nowrap; font-size: var(--fs-2xs); }
-/* 地方不够时设备名先省略(右侧设备面板里有全名,至少留约 6 个字),状态标签尽量完整,再不够才横向滚动 */
-.dev-select { flex: 0 100 auto; }
-.dev-select .select-wrap { min-width: 6.5em; }
-.dev-select .select-wrap { grid-template-columns: minmax(0, auto); flex: 0 1 auto; }
-.dev-select .select { width: 100%; min-width: 0; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
-/* 设备名缩到最窄之后,状态标签才开始让(收缩按 flex-shrink × 宽度分摊,所以这里取很小的值) */
-.statusbar .chips { flex-shrink: 0.01; }
+/* 优先保留设备选择器;状态标签在剩余的宽度内滚动。 */
+.dev-select { flex: 0 1 auto; max-width: 100%; }
+.device-picker { min-width: 0; max-width: 180px; }
+.device-picker .picker-trigger { min-width: 0; }
+.statusbar .chips { flex: 1 1 auto; }
/* 中间栏的各行跟着栏宽收缩,不按内容最小宽度把栏撑出窗口 */
.pane-stage > * { min-width: 0; }
-.select-wrap { display: grid; min-width: 0; }
-.select-wrap > * { grid-area: 1 / 1; }
-.select { appearance: none; -webkit-appearance: none; min-height: 36px; padding: 0 30px 0 var(--sp-2); border: 0; border-radius: var(--r-md); background: transparent; font-weight: 600; cursor: pointer; max-width: 240px; }
-@media (hover: hover) { .select:hover:not(:disabled) { background: var(--hover); } }
-.select-chev { justify-self: end; align-self: center; margin-right: 8px; pointer-events: none; color: var(--muted); --od-icon-size: 16px; }
.chips { display: flex; align-items: center; gap: 2px; flex-wrap: nowrap; min-width: 0; overflow-x: auto; scrollbar-width: none; margin-left: 6px; padding-left: 8px; border-left: 1px solid var(--line); }
.chips:empty { display: none; }
.chips::-webkit-scrollbar { display: none; }
@@ -325,7 +361,7 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.chip-dot.ok { background: var(--ai); } .chip-dot.warn { background: var(--warn); } .chip-dot.off { background: var(--danger); }
.chip .k { color: var(--muted); }
.head-tools { margin-left: auto; display: flex; gap: var(--sp-2); }
-.head-tools .btn { min-height: 44px; border: 0; background: var(--panel); box-shadow: 0 0 0 1px var(--panel-edge), var(--shadow-xs); border-radius: var(--r-lg); }
+.head-tools .btn { min-height: 44px; border-radius: var(--r-lg); }
.head-tools .btn-icon { width: 44px; }
@media (hover: hover) { .head-tools .btn:hover:not(:disabled) { background: var(--hover); } }
.dev-toggle { display: none; }
@@ -336,15 +372,15 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.stage-wrap > .frame { margin: auto; }
.frame[data-zoom="fixed"] { width: var(--fixed-w); }
/* 缩放控件 */
-.zoom { display: flex; align-items: center; gap: 2px; height: 44px; padding: 4px; border-radius: var(--r-lg); background: var(--panel); box-shadow: 0 0 0 1px var(--panel-edge), var(--shadow-xs); }
-.zoom button { height: 36px; min-width: 36px; padding: 0 var(--sp-2); border: 0; border-radius: var(--r-md); background: transparent; color: var(--text-2); display: inline-flex; align-items: center; justify-content: center; font-size: var(--fs-xs); font-weight: 600; cursor: pointer; white-space: nowrap; --od-icon-size: 18px; transition: background-color var(--dur-fast) var(--ease-out); }
+.zoom { display: flex; align-items: center; gap: 2px; height: 44px; padding: 4px; border-radius: var(--r-lg); }
+.zoom button { height: 36px; min-width: 36px; padding: 0 var(--sp-2); border: 0; border-radius: var(--r-md); background: transparent; color: var(--text-2); display: inline-flex; align-items: center; justify-content: center; font-size: var(--fs-xs); font-weight: 600; cursor: pointer; white-space: nowrap; --od-icon-size: 16px; transition: background-color var(--dur-fast) var(--ease-out); }
@media (hover: hover) { .zoom button:hover:not(:disabled) { background: var(--hover); color: var(--text); } }
.zoom button:disabled { color: var(--muted); opacity: .45; cursor: not-allowed; }
.zoom .zoom-val { min-width: 52px; font-variant-numeric: tabular-nums; }
.zoom .zoom-fit[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text); }
.frame {
--ratio: .4613; --pad: 11px;
- width: min(100cqw - 48px, calc((100cqh - 40px - var(--pad) * 2) * var(--ratio) + var(--pad) * 2));
+ width: min(100cqw, calc((100cqh - var(--pad) * 2) * var(--ratio) + var(--pad) * 2));
padding: var(--pad); border-radius: 54px; background: var(--bezel);
box-shadow: inset 0 0 0 1.5px var(--bezel-edge), inset 0 0 0 4px rgba(255, 255, 255, .03), var(--shadow-phone);
transition: box-shadow var(--dur) var(--ease-out);
@@ -356,8 +392,14 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
/* iPad:边框更厚、屏幕圆角更小,跟实际机身比例一致 */
.frame[data-kind="ipad"] { --pad: 14px; border-radius: 34px; }
.frame[data-kind="ipad"] .stage { border-radius: 20px; }
+.frame[data-kind="unknown"], .frame[data-kind="unknown"] .stage { border-radius: 10px; }
.stage > * { grid-area: 1 / 1; }
.stage img, .stage canvas { width: 100%; height: 100%; object-fit: contain; display: block; -webkit-user-drag: none; }
+/* An unplugged device keeps its place in the workspace without a black screen. */
+.frame[data-absent] { border-radius: 38px; background: var(--panel); box-shadow: 0 0 0 1px var(--line-strong), var(--shadow-panel); }
+.frame[data-absent] .stage { border-radius: 28px; background: var(--sunken); cursor: default; }
+.frame[data-absent] .stage-msg { color: var(--muted); }
+.stage-msg .idle-heading { display: block; margin-bottom: 6px; color: var(--text); font-size: var(--fs-lg); font-weight: 600; }
.stage-msg { place-self: center; padding: var(--sp-6); color: #d4d7dc; text-align: center; font-size: var(--fs-sm); max-width: 34ch; }
.stage-msg code { font-family: var(--font-mono, ui-monospace, monospace); font-size: 0.92em; color: #fff; overflow-wrap: anywhere; }
.stage-msg .btn { margin-top: var(--sp-3); }
@@ -393,12 +435,12 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.stage-foot { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); padding: 0 var(--sp-6) var(--sp-3); }
/* 提示条叠在按键工具条的位置上:工具条只是隐藏、仍占位,任何宽度下设备画面都不会因此变小 */
-.dock-slot { display: grid; width: 100%; justify-items: center; align-items: stretch; }
+.dock-slot { display: grid; grid-template-columns: minmax(0, 1fr); width: 100%; justify-items: center; align-items: stretch; }
.dock-slot > * { grid-area: 1 / 1; }
.dock.is-covered { visibility: hidden; }
-.dock { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; justify-content: center; padding: 6px; border-radius: var(--r-xl); background: var(--panel); box-shadow: 0 0 0 1px var(--panel-edge), var(--shadow-float); max-width: 100%; }
+.dock { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; justify-content: center; padding: 6px; border-radius: var(--r-xl); max-width: 100%; }
.keys { flex: none; display: flex; gap: 2px; padding: 2px; border-radius: 12px; background: var(--sunken); }
-.key { width: 40px; height: 40px; border: 0; border-radius: var(--r-md); background: transparent; color: var(--text-2); display: grid; place-items: center; cursor: pointer; --od-icon-size: 20px; transition: background-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out); }
+.key { width: 40px; height: 40px; border: 0; border-radius: var(--r-md); background: transparent; color: var(--text-2); display: grid; place-items: center; cursor: pointer; --od-icon-size: 16px; transition: background-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out); }
@media (hover: hover) { .key:hover:not(:disabled) { background: var(--panel); color: var(--text); box-shadow: var(--shadow-xs), 0 0 0 1px var(--panel-edge); } }
.key:active:not(:disabled) { background: var(--press); box-shadow: none; }
.key:disabled { color: var(--muted); opacity: .45; cursor: not-allowed; }
@@ -406,21 +448,21 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.type-field .input { width: 220px; min-width: 96px; flex: 1 1 220px; min-height: 44px; border-radius: 12px; }
.type-field .btn { min-height: 44px; border-radius: 12px; }
.type-field .btn-icon { width: 44px; }
-.guard { width: min(100%, 560px); min-height: 56px; align-self: stretch; display: flex; align-items: center; gap: var(--sp-3); flex-wrap: nowrap; padding: 0 var(--sp-2) 0 var(--sp-4); border-radius: var(--r-xl); background: var(--panel); box-shadow: 0 0 0 1px var(--panel-edge), var(--shadow-float); --od-icon-size: 18px; }
+.guard { width: min(100%, 560px); min-height: 56px; align-self: stretch; display: flex; align-items: center; gap: var(--sp-3); flex-wrap: nowrap; padding: 0 var(--sp-2) 0 var(--sp-4); border-radius: var(--r-xl); --od-icon-size: 16px; }
.guard-text { flex: 1 1 0; min-width: 0; display: grid; line-height: 1.35; }
.guard-title { display: block; font-weight: 600; font-size: var(--fs-sm); }
.guard-sub { display: block; font-size: var(--fs-xs); color: var(--muted); }
.guard.tone-accent .guard-title { color: var(--accent-text); } .guard.tone-warn .guard-title { color: var(--warn-text); } .guard.tone-user .guard-title { color: var(--user-text); }
.guard.nudge { animation: nudge 360ms var(--ease-out); }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
-.meta-row { display: flex; justify-content: center; font-size: var(--fs-2xs); color: var(--muted); max-width: 100%; }
+.meta-row { display: flex; justify-content: center; font-size: var(--fs-xs); color: var(--muted); max-width: 100%; }
.feed { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.feed-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ai); flex: none; }
.feed-dot.off { background: var(--danger); } .feed-dot.wait { background: var(--muted); }
/* ================= 右栏:设备面板 ================= */
.seg { display: flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--sunken); flex: 1; }
-.seg button { flex: 1; min-height: 36px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: var(--fs-sm); font-weight: 600; cursor: pointer; white-space: nowrap; transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
+.seg button { flex: 1; min-height: 36px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: var(--fs-xs); font-weight: 500; cursor: pointer; white-space: nowrap; transition: background-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out); }
.seg button[aria-selected="true"] { background: var(--panel); color: var(--text); box-shadow: var(--shadow-xs), 0 0 0 1px var(--panel-edge); }
@media (hover: hover) { .seg button:hover { color: var(--text); } }
.dev-close { display: inline-flex; }
@@ -436,28 +478,41 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.empty-note { font-size: var(--fs-sm); color: var(--muted); padding: var(--sp-4); border-radius: var(--r-lg); background: var(--sunken); }
.empty-note.err { color: var(--danger-text); background: var(--danger-soft); }
-.device-card { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 14px; align-items: center; padding: var(--sp-4); border-radius: var(--r-lg); background: var(--sunken); }
-.device-ic { width: 48px; height: 48px; border-radius: 12px; background: var(--panel); box-shadow: var(--shadow-xs), 0 0 0 1px var(--panel-edge); display: grid; place-items: center; color: var(--accent-text); --od-icon-size: 24px; }
-.device-name { display: block; font-weight: 700; font-size: var(--fs-lg); line-height: 1.3; }
-.device-sub { display: block; font-size: var(--fs-xs); color: var(--muted); }
-.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); }
-.fact { padding: 10px var(--sp-3); border-radius: var(--r-md); box-shadow: inset 0 0 0 1px var(--line); display: grid; gap: 2px; min-width: 0; }
-.fact-k { display: block; font-size: var(--fs-2xs); color: var(--muted); }
-.fact-v { display: block; font-size: var(--fs-sm); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
-.fact-v.mono { font-size: var(--fs-2xs); font-weight: 500; }
-.checks { display: flex; flex-direction: column; padding: 14px 14px 2px; border-radius: var(--r-lg); background: var(--sunken); }
-.check { display: grid; grid-template-columns: 24px minmax(0, 1fr); column-gap: var(--sp-3); }
-.check-rail { display: flex; flex-direction: column; align-items: center; }
-.check-dot { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; --od-icon-size: 14px; }
-.check-dot.pending { box-shadow: inset 0 0 0 1.5px var(--line-strong); color: var(--muted); }
-.check-line { flex: 1; width: 1.5px; background: var(--line-strong); opacity: .6; min-height: 10px; margin: 2px 0; }
-.check:last-child .check-line { visibility: hidden; }
-.check-body { padding: 2px 0 var(--sp-3); display: grid; gap: 2px; min-width: 0; }
-.check-name { display: block; font-size: var(--fs-sm); font-weight: 600; }
-.check.pending .check-name { color: var(--muted); font-weight: 500; }
-.check-hint { display: block; font-size: var(--fs-xs); color: var(--text-2); }
-.check-hint code { font-size: var(--fs-2xs); padding: 1px 6px; border-radius: 4px; background: var(--panel); box-shadow: inset 0 0 0 1px var(--line); }
-.check-err { display: block; font-size: var(--fs-2xs); color: var(--danger-text); font-family: var(--font-mono); overflow-wrap: anywhere; }
+.nav-caption { margin: 0 6px 8px; font-size: var(--fs-xs); font-weight: 600; color: var(--muted); }
+.nav-device-list { display: grid; gap: 3px; }
+.nav-device { width: 100%; display: flex; align-items: center; gap: 9px; min-height: 40px; padding: 7px 8px; border: 0; border-radius: 7px; background: transparent; color: var(--text-2); text-align: left; }
+button.nav-device { cursor: pointer; }
+button.nav-device:hover { background: var(--hover); }
+button.nav-device[aria-current="true"] { background: var(--accent-soft); color: var(--accent-text); }
+button.nav-device:disabled { cursor: default; }
+.nav-device > svg { flex: none; --od-icon-size: 16px; }
+.nav-device-copy { min-width: 0; display: grid; gap: 2px; }
+.device-name { font-size: var(--fs-sm); font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
+.device-sub { font-size: var(--fs-xs); color: var(--muted); overflow-wrap: anywhere; }
+.nav-device-empty { color: var(--muted); font-size: var(--fs-sm); padding-block: 5px; }
+.nav-readout { display: grid; gap: 7px; margin: 0 6px; }
+.fact { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.3fr); gap: 10px; align-items: baseline; }
+.fact-k { color: var(--muted); font-size: var(--fs-xs); }
+.fact-v { margin: 0; text-align: right; color: var(--text-2); font-size: var(--fs-sm); overflow-wrap: anywhere; }
+.fact-v.mono { font-size: var(--fs-xs); }
+.nav-disclosure { border-top: 1px solid var(--line); margin: 0 6px; padding-top: 6px; }
+.nav-disclosure > summary { display: flex; align-items: center; gap: 7px; min-height: 36px; width: fit-content; font-size: var(--fs-xs); font-weight: 600; color: var(--text-2); cursor: pointer; list-style: none; }
+.nav-disclosure > summary::-webkit-details-marker { display: none; }
+.nav-disclosure > summary::before { content: ""; width: 6px; height: 6px; transform: rotate(45deg); border-top: 1.5px solid currentColor; border-right: 1.5px solid currentColor; margin: 0 3px 0 1px; }
+.nav-disclosure[open] > summary::before { transform: rotate(135deg); }
+.nav-disclosure .nav-readout { margin: 3px 0 8px; }
+
+.nav-check-list { display: grid; gap: 10px; padding: 4px 0; }
+.nav-check-list li { display: grid; grid-template-columns: 16px minmax(0,1fr); column-gap: 6px; align-items: start; }
+.nav-check-list svg { margin-top: 2px; --od-icon-size: 12px; color: var(--muted); }
+.nav-check-list .check-ok { color: var(--ok-text); }
+.check-name, .check-hint, .check-err { display: block; font-size: var(--fs-xs); overflow-wrap: anywhere; }
+.check-name { font-weight: 500; }
+.check-hint { margin-top: 3px; color: var(--muted); }
+.check-err { color: var(--danger-text); }
+.nav-offline-panel { display: none; color: var(--muted); font-size: var(--fs-sm); }
+#pane-dev[data-no-device="true"] :is(#tp-apps, #tp-elements) > .sec { display: none; }
+#pane-dev[data-no-device="true"] .nav-offline-panel { display: block; }
.url-row { display: flex; gap: var(--sp-2); }
.search { display: grid; }
@@ -467,8 +522,8 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.switch-row { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-xs); color: var(--text-2); cursor: pointer; }
.switch-row input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.list { display: flex; flex-direction: column; gap: 2px; margin: 0 calc(var(--sp-2) * -1); }
-.app-row { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: var(--sp-3); align-items: center; padding: var(--sp-2); border-radius: 12px; transition: background-color var(--dur-fast) var(--ease-out); }
-.app-tile { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; font-size: 17px; font-weight: 700; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06), var(--shadow-xs); }
+.app-row { display: grid; grid-template-columns: 32px minmax(0, 1fr) auto; gap: var(--sp-3); align-items: center; padding: var(--sp-2); border-radius: 12px; transition: background-color var(--dur-fast) var(--ease-out); }
+.app-tile { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; font-size: 14px; font-weight: 700; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06), var(--shadow-xs); }
.app-text { display: grid; min-width: 0; }
.app-name { font-size: var(--fs-sm); font-weight: 600; }
.app-id { font-family: var(--font-mono); font-size: var(--fs-2xs); color: var(--muted); }
@@ -489,10 +544,10 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.count { font-size: var(--fs-2xs); color: var(--muted); font-variant-numeric: tabular-nums; }
.wait-result { font-size: var(--fs-sm); }
/* 读取中的骨架占位 */
-.skel-row { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: var(--sp-3); align-items: center; padding: var(--sp-2); }
+.skel-row { display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: var(--sp-3); align-items: center; padding: var(--sp-2); }
.skel-row.no-tile { grid-template-columns: minmax(0, 1fr); padding: 10px; }
.skel { display: block; background: var(--press); border-radius: var(--r-xs); animation: pulse 1.2s ease-in-out infinite; }
-.skel.tile { width: 40px; height: 40px; border-radius: 11px; }
+.skel.tile { width: 32px; height: 32px; border-radius: 8px; }
.skel-lines { display: grid; gap: 6px; }
.skel.l1 { height: 12px; width: 55%; }
.skel.l2 { height: 10px; width: 80%; }
@@ -500,28 +555,49 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.skel-row:nth-child(3n) .skel.l2 { width: 65%; }
/* 确认弹窗 */
-.dialog { width: min(420px, calc(100vw - 32px)); padding: var(--sp-6); border: 0; border-radius: var(--r-2xl); background: var(--panel); color: var(--text); box-shadow: 0 0 0 1px var(--panel-edge), var(--shadow-float); }
+.dialog { width: min(420px, calc(100vw - 32px)); padding: var(--sp-6); border: 0; border-radius: var(--r-lg); color: var(--text); }
.dialog::backdrop { background: rgba(10, 14, 18, .4); }
.dialog[open] { animation: rise var(--dur) var(--ease-out); }
-.dialog h2 { font-size: var(--fs-lg); margin-bottom: var(--sp-2); }
+.dialog h2 { font-size: 1.125rem; font-weight: 600; margin-bottom: var(--sp-2); }
.dialog p { color: var(--text-2); }
-#updates-dialog { background: color-mix(in srgb, var(--panel) 90%, transparent); backdrop-filter: blur(22px); }
-#updates-dialog .update-head { display: flex; justify-content: space-between; align-items: center; }
-#updates-dialog h2 { margin: 0; }
-#about-updates { position: relative; }
-#update-dot { position: absolute; top: 2px; right: 2px; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--panel); }
-#update-command-block { margin-top: var(--sp-3); padding: var(--sp-3); border-radius: var(--r-sm); background: var(--press); }
-.update-command-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
-#update-command { display: block; margin-top: var(--sp-2); font-family: var(--font-mono); font-size: var(--fs-sm); overflow-wrap: anywhere; white-space: pre-wrap; user-select: all; }
-#update-copy-status:empty { display: none; }
-#updates-dialog .dialog-actions { flex-wrap: wrap; }
-.update-version { margin: var(--sp-4) 0; font: 600 var(--fs-xl)/1.3 var(--font-mono); }
-.update-facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--sp-1) var(--sp-3); margin: var(--sp-3) 0; }
-.update-facts dt { color: var(--text-2); }
-.update-facts dd, .update-detail { margin: 0; overflow-wrap: anywhere; white-space: pre-line; }
-.update-detail { margin-top: var(--sp-2); }
+
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--sp-2); margin-top: var(--sp-6); }
+.sidebar-footer { display: flex; align-items: center; gap: 6px; }
+.sidebar-footer .sidebar-settings { flex: 1; }
+#about-updates { position: relative; flex: none; color: var(--text-2); }
+#about-updates[aria-expanded="true"] { background: var(--hover); }
+#update-dot { position: absolute; top: 5px; right: 5px; width: 6px; height: 6px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--panel); }
+#updates-dialog {
+ position: fixed; inset: auto; margin: 0; width: min(19rem, calc(100vw - 16px)); padding: 12px;
+ border-radius: 12px; color: var(--text); font-size: var(--fs-xs); line-height: 1.5;
+ overflow: auto; overflow-wrap: anywhere; overscroll-behavior: contain;
+ background-color: color-mix(in srgb, var(--panel) 75%, var(--glass-surface)); box-shadow: var(--shadow-float);
+}
+.update-head, .update-actions { display: flex; align-items: center; gap: 6px; }
+#update-version { flex: 1; font-size: var(--fs-sm); font-weight: 600; line-height: 1.4; }
+.update-head .btn-icon { width: 28px; min-height: 28px; padding: 0; color: var(--muted); --od-icon-size: 14px; }
+#update-result, #update-notes { color: var(--text-2); }
+#update-notes:not(:empty), #update-result:not(:empty) { margin-top: 4px; }
+#update-result[data-error="true"] { color: var(--danger-text); }
+.update-actions { flex-wrap: wrap; margin-top: 8px; }
+.update-actions .btn { min-height: 30px; padding-inline: 8px; }
+#update-release { text-decoration: none; }
+#update-more { margin-inline-start: auto; gap: 4px; --od-icon-size: 12px; }
+#update-more[aria-expanded="true"] .ic { transform: rotate(180deg); }
+#update-more[data-attention="true"] { color: var(--warn-text); }
+#update-details { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
+.update-facts { display: grid; grid-template-columns: auto minmax(0,1fr); gap: 4px 12px; margin: 8px 0 0; }
+.update-facts dt { color: var(--muted); }
+.update-facts dd { margin: 0; }
+.update-detail { color: var(--text-2); white-space: pre-line; }
+.update-detail:not(:empty) + .update-detail:not(:empty), #update-copy-status:not(:empty), #update-command-block { margin-top: 6px; }
+#update-command { display: block; padding: 8px; background: var(--sunken); border-radius: 7px; font-size: var(--fs-2xs); white-space: pre-wrap; overflow-wrap: anywhere; user-select: all; }
+@media (pointer: coarse) {
+ #about-updates, .update-head .btn-icon { width: 44px; min-height: 44px; }
+ .update-actions .btn { min-height: 44px; }
+}
+
/* ================= 演示画面(代码绘制的模拟界面;iPhone 393×852 点,iPad mini 横屏 1133×744 点) ================= */
.ph { width: var(--dw, 393px); height: var(--dh, 852px); transform: scale(var(--k, 1)); transform-origin: 0 0; justify-self: start; align-self: start; display: grid; grid-template-rows: 54px minmax(0, 1fr) 34px; overflow: hidden; background: #1f2b35; color: #fff; font: 17px/1.3 -apple-system, "SF Pro Text", "PingFang SC", system-ui, sans-serif; }
.ph--light { background: #fff; color: #000; } .ph--gray { background: #f2f2f7; color: #000; } .ph--black { background: #000; color: #fff; }
@@ -604,11 +680,54 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
.ph-lock-time { font-size: 96px; font-weight: 600; line-height: 1.05; font-variant-numeric: tabular-nums; }
.ph-lock-hint { margin-top: auto; margin-bottom: 12px; font-size: 15px; opacity: .8; }
+.appearance-options { display: grid; }
+.appearance-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 4px; font-size: var(--fs-xs); }
+.appearance-row + .appearance-row { border-top: 1px solid var(--line); }
+.appearance-picker { min-width: 0; max-width: 65%; }
+.pane-agent .pane-head { gap: 6px; padding-inline: 12px; }
+.agent-brand { flex: 1; }
+.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
+.stage-msg { max-height: 100%; overflow: auto; }
+@container preview (max-width: 620px) {
+ .dev-select .label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
+ .dev-select { padding-left: 2px; }
+}
+@container preview (max-width: 490px) {
+ .chips { display: none; }
+ .stage-foot { padding-inline: 8px; }
+ .dock { flex-wrap: wrap; }
+}
+/* Put the filter on the surface. Its text and the live image render at full sharpness. */
+@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
+ :root { --glass-surface: var(--glass-tint); --glass-blur: blur(18px); }
+}
+.glass {
+ background-color: var(--glass-surface);
+ border: 1px solid var(--glass-border);
+ box-shadow: var(--glass-shadow);
+ -webkit-backdrop-filter: var(--glass-blur);
+ backdrop-filter: var(--glass-blur);
+}
+@media (prefers-reduced-transparency: reduce), (prefers-contrast: more), (forced-colors: active) {
+ :root, :root[data-scheme="dark"] {
+ --glass-surface: var(--panel);
+ --glass-blur: none;
+ --glass-shadow: none;
+ --glass-border: var(--line-strong);
+ --workspace-light: none;
+ }
+}
+@media (forced-colors: active) {
+ .glass { border-color: CanvasText; }
+ .composer:has(.textarea:focus-visible) { outline: 2px solid Highlight; }
+ .picker-option[data-active] { outline: 1px solid Highlight; outline-offset: -1px; }
+ .seg button[aria-selected="true"], .zoom-fit[aria-pressed="true"] { outline: 1px solid Highlight; outline-offset: -2px; }
+}
/* ================= 响应式 ================= */
@media (max-width: 1279.98px) {
.shell { grid-template-columns: var(--w-agent) minmax(0, 1fr); }
.dev-toggle { display: inline-flex; }
- .pane-dev { position: fixed; top: var(--gutter); right: var(--gutter); bottom: var(--gutter); z-index: 30; width: min(var(--w-dev), calc(92vw - var(--gutter) * 2)); box-shadow: 0 0 0 1px var(--panel-edge), var(--shadow-float); transform: translateX(calc(100% + var(--gutter) * 2)); transition: transform var(--dur-exit) var(--ease-in); }
+ .pane-dev { position: fixed; top: var(--gutter); right: var(--gutter); bottom: var(--gutter); z-index: 30; width: min(var(--w-dev), calc(92vw - var(--gutter) * 2)); transform: translateX(calc(100% + var(--gutter) * 2)); transition: transform var(--dur-exit) var(--ease-in); }
.shell[data-dev-open="true"] .pane-dev { transform: none; transition: transform var(--dur-slow) var(--ease-out); }
.dev-close { display: inline-flex; }
}
@@ -626,10 +745,10 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
}
@media (max-width: 1023.98px) {
.shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 0; padding: 0; }
- .mbar { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
+ .mbar { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); border-width: 0 0 1px; flex-wrap: wrap; }
.mbar .seg { flex: 0 1 300px; margin-left: auto; }
.pane-agent, .pane-stage, .pane-dev { grid-row: 2; grid-column: 1; }
- .pane-agent, .pane-dev { border-radius: 0; box-shadow: none; }
+ .pane-agent, .pane-dev { border: 0; border-radius: 0; box-shadow: none; }
.pane-dev { position: static; width: auto; transform: none; transition: none; }
.shell[data-view="agent"] .pane-stage, .shell[data-view="agent"] .pane-dev,
.shell[data-view="screen"] .pane-agent, .shell[data-view="screen"] .pane-dev,
@@ -640,20 +759,46 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
}
@media (max-width: 767.98px) {
.mbar .brand-sub { display: none; }
- .mbar .seg { flex-basis: 100%; }
- .stage-head { flex-wrap: wrap; height: auto; padding: var(--sp-3) var(--sp-3) 0; }
+ .mbar .seg { flex: 1; }
+ .mbar { gap: 6px; padding: 6px 8px; }
+ .mbar .brand-text { display: none; }
+ .stage-head { gap: 4px; flex-wrap: wrap; height: auto; padding: var(--sp-3) var(--sp-3) 0; }
.statusbar { flex: 1 1 0; }
+ .dev-select { padding-left: 2px; }
+ .dev-select .label { position: absolute; clip-path: inset(50%); width: 1px; overflow: hidden; }
+ .head-tools { gap: 4px; }
+ .zoom button { min-width: 30px; padding-inline: 5px; }
+ .zoom .zoom-val { min-width: 40px; }
.pane-stage { grid-template-rows: auto minmax(0, 1fr) auto; }
.chips { display: none; }
.stage-wrap { padding: var(--sp-4) var(--sp-3) var(--sp-4); }
.stage-foot { padding: 0 var(--sp-3) var(--sp-3); }
.dock { flex-wrap: wrap; }
.type-field { flex: 1 1 100%; }
- .type-field .input { width: auto; flex: 1; }
+ .type-field .input { width: 0; flex: 1; }
.convo { padding: var(--sp-6) var(--sp-4) var(--sp-4); }
.tabpanel { padding: var(--sp-4); }
.caps { grid-template-columns: minmax(0, 1fr); }
}
+/* A short landscape viewport has room beside the picture for the two toolbars. */
+@media (orientation:landscape) and (min-width:540px) and (max-width:1023.98px) and (max-height:520px) {
+ .pane-stage { grid-template-columns:minmax(0,1fr) minmax(220px,33%); grid-template-rows:auto minmax(0,1fr); }
+ .stage-area { grid-area:1 / 1 / 3 / 2; }
+ .stage-wrap { padding:8px; }
+ .stage-head,.stage-foot { border-left:1px solid var(--line-strong); }
+ .stage-head { grid-area:1 / 2; display:flex; flex-direction:column; align-items:stretch; gap:0; height:auto; padding:4px 8px; }
+ .stage-head .chips { display:none; }
+ .head-tools { margin:0; flex-wrap:wrap; justify-content:center; }
+ .stage-head .statusbar { justify-content:center; }
+ .stage-foot { grid-area:2 / 2; padding:8px; border-top:0; overflow-y:auto; }
+ .dock { flex-wrap:wrap; }
+ .type-field { flex:1 1 100%; }
+ .type-field .input { min-width:0; }
+ .keys,.type-field { justify-content:center; }
+}
+@media (pointer: coarse) and (max-width: 767.98px) {
+ .input, .textarea { font-size: max(1rem, 16px); }
+}
@media (prefers-reduced-motion: reduce) {
*, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
.spin { animation: none !important; }
@@ -664,7 +809,7 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
<div class="shell" id="shell" data-view="agent" data-dev-open="false">
<!-- 窄屏顶栏 -->
- <header class="mbar">
+ <header class="mbar glass">
<div class="brand">
<svg class="brand-mark" viewBox="0 0 32 32" width="28" height="28" aria-hidden="true"><rect x="9" y="3" width="14" height="26" rx="3.5" fill="none" stroke="currentColor" stroke-width="2"/><path d="M13.5 25h5" stroke="currentColor" stroke-width="2" stroke-linecap="round"/><circle cx="16" cy="14" r="3" fill="var(--accent)"/></svg>
<div class="brand-text"><span class="brand-name">iphone-control</span><span class="brand-sub">控制台</span></div>
@@ -677,7 +822,7 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
</header>
<!-- 左:AI 助手 -->
- <aside class="pane pane-agent" id="pane-agent" aria-label="AI 助手">
+ <aside class="pane pane-agent glass" id="pane-agent" aria-label="AI 助手">
<div class="resizer" id="resizer" role="separator" aria-orientation="vertical" aria-controls="pane-agent" aria-label="调整 AI 助手栏宽度" title="拖动调整宽度,双击恢复默认" tabindex="0"></div>
<div class="pane-head">
<div class="brand agent-brand">
@@ -686,8 +831,6 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
</div>
<span id="agent-badge"></span>
<button type="button" class="btn btn-ghost btn-sm clear-btn" id="clear-btn" data-action="clear" data-focus="clear" hidden><span class="ic" data-icon="trash"></span><span>清空记录</span></button>
- <button type="button" class="btn btn-ghost btn-icon btn-sm" id="about-updates" aria-label="关于与更新" title="关于与更新" aria-haspopup="dialog"><svg width="17" height="17" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><circle cx="10" cy="10" r="8"/><path d="M10 9v5m0-8v1"/></svg><span id="update-dot" aria-hidden="true" hidden></span></button>
- <button type="button" class="btn btn-ghost btn-sm lang-btn" id="lang-btn" aria-label="切换语言" title="切换语言">EN</button>
</div>
<div class="pane-body" id="agent-scroll">
<div class="convo">
@@ -711,43 +854,68 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
<div class="composer" id="composer">
<div class="runbar" id="runbar" role="group" aria-label="任务控制" hidden></div>
<label class="sr-only" for="prompt">交给 AI 的任务</label>
- <textarea class="textarea" id="prompt" rows="2" maxlength="4000" aria-describedby="composer-hint prompt-error" placeholder="想让设备做什么?"></textarea>
+ <textarea class="textarea" id="prompt" rows="1" maxlength="4000" aria-describedby="composer-hint prompt-error" placeholder="想让设备做什么?"></textarea>
<div class="composer-row">
- <div class="select-wrap agent-pick" id="agent-pick" hidden>
- <label class="sr-only" for="agent">执行任务的 AI</label>
- <select class="select" id="agent" title="执行任务的本地 AI"></select>
- <span class="select-chev" data-icon="chevron"></span>
+ <div class="agent-pick" id="agent-pick" hidden>
+ <span class="sr-only" id="agent-label">执行任务的 AI</span>
+ <select id="agent-value" data-picker="agent" data-open-above hidden></select>
</div>
- <span class="composer-hint" id="composer-hint">Enter 发送 · Shift+Enter 换行</span>
- <button type="button" class="btn btn-primary send" id="send" data-action="send" data-focus="send" aria-label="开始任务"><span class="ic" data-icon="send"></span></button>
+ <span class="sr-only" id="composer-hint">Enter 发送 · Shift+Enter 换行</span>
+ <button type="button" class="btn btn-primary send" id="send" data-action="send" data-focus="send" aria-label="开始任务" title="Enter 发送 · Shift+Enter 换行"><span class="ic" data-icon="send"></span></button>
</div>
</div>
<p class="field-error" id="prompt-error" hidden></p>
+ <div class="sidebar-footer">
+ <button type="button" class="sidebar-settings" id="appearance-btn" aria-haspopup="dialog" aria-controls="appearance"><span class="ic" data-icon="settings"></span><span>设置</span></button>
+ <button type="button" class="btn btn-ghost btn-icon btn-sm" id="about-updates" popovertarget="updates-dialog" aria-controls="updates-dialog" aria-haspopup="dialog" aria-expanded="false" aria-label="关于与更新" title="关于与更新"><span class="ic" data-icon="info"></span><span id="update-dot" aria-hidden="true" hidden></span></button>
+ </div>
+ <section class="glass" id="updates-dialog" role="dialog" aria-label="关于与更新" popover="auto" tabindex="-1" autofocus>
+ <div class="update-head">
+ <h2 id="update-version">Viewer</h2>
+ <button class="btn btn-ghost btn-icon btn-sm" id="update-check" type="button" aria-label="检查更新" title="检查更新" disabled><span class="ic" data-icon="refresh"></span></button>
+ <button class="btn btn-ghost btn-icon btn-sm" id="update-close" type="button" popovertarget="updates-dialog" popovertargetaction="hide" aria-label="关闭版本信息" title="关闭版本信息"><span class="ic" data-icon="x"></span></button>
+ </div>
+ <p id="update-result" role="status"></p>
+ <p id="update-notes" class="od-clamp-3"></p>
+ <div class="update-actions">
+ <button class="btn btn-primary btn-sm" id="update-copy" type="button" hidden>复制升级命令</button>
+ <a class="btn btn-ghost btn-sm" id="update-release" target="_blank" rel="noopener noreferrer" hidden>发行说明</a>
+ <button class="btn btn-ghost btn-sm" id="update-more" type="button" aria-expanded="false" aria-controls="update-details"><span>版本详情</span><span class="ic" data-icon="chevron"></span></button>
+ </div>
+ <p class="update-detail" id="update-copy-status" role="status"></p>
+ <div id="update-details" hidden>
+ <p class="update-detail" id="update-guide"></p>
+ <div id="update-command-block" hidden><code id="update-command"></code></div>
+ <dl class="update-facts" id="update-facts"></dl>
+ <p class="update-detail" id="update-policy"></p>
+ <p class="update-detail" id="update-outcome"></p>
+ <p class="update-detail" id="update-mismatch"></p>
+ </div>
+ </section>
</div>
</aside>
<!-- 中:设备舞台 -->
<main class="pane pane-stage" id="pane-stage" aria-label="设备屏幕">
<div class="pane-head stage-head">
- <div class="statusbar">
+ <div class="statusbar glass">
<div class="dev-select">
- <label class="label" for="device">控制设备</label>
- <div class="select-wrap">
- <select class="select" id="device" disabled><option>正在查找…</option></select>
- <span class="select-chev" data-icon="chevron"></span>
+ <label class="label" id="device-label" for="device">控制设备</label>
+ <div class="device-picker">
+ <select id="device-value" data-picker="device" disabled hidden><option>正在查找…</option></select>
</div>
</div>
<div class="chips" id="chips"></div>
</div>
<div class="head-tools">
- <div class="zoom" role="group" aria-label="画面缩放">
+ <div class="zoom glass" role="group" aria-label="画面缩放">
<button type="button" data-action="zoom-out" id="zoom-out" aria-label="缩小画面" title="缩小(也可以按住 Ctrl/⌘ 滚动滚轮)"><span class="ic" data-icon="zoomout"></span></button>
<button type="button" class="zoom-val" data-action="zoom-actual" id="zoom-val" title="切换到实际尺寸(100%)" aria-label="当前缩放比例,点击切换到实际尺寸">100%</button>
<button type="button" data-action="zoom-in" id="zoom-in" aria-label="放大画面" title="放大(也可以按住 Ctrl/⌘ 滚动滚轮)"><span class="ic" data-icon="zoomin"></span></button>
<button type="button" class="zoom-fit" data-action="zoom-fit" id="zoom-fit" aria-pressed="true" title="按窗口大小自动适应">适应</button>
</div>
- <button type="button" class="btn btn-ghost btn-icon" data-action="reconnect" aria-label="刷新画面" title="刷新画面"><span class="ic" data-icon="refresh"></span></button>
- <button type="button" class="btn dev-toggle" data-action="dev-open" id="dev-toggle" aria-controls="pane-dev" aria-expanded="false"><span class="ic" data-icon="panel"></span><span>设备面板</span></button>
+ <button type="button" class="btn btn-ghost btn-icon glass" data-action="reconnect" aria-label="刷新画面" title="刷新画面"><span class="ic" data-icon="refresh"></span></button>
+ <button type="button" class="btn dev-toggle glass" data-action="dev-open" id="dev-toggle" aria-controls="pane-dev" aria-expanded="false"><span class="ic" data-icon="panel"></span><span>设备面板</span></button>
</div>
</div>
<div class="stage-area">
@@ -766,8 +934,8 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
</div>
<div class="stage-foot">
<div class="dock-slot">
- <div class="guard" id="guard" role="status" hidden></div>
- <div class="dock" id="dock" role="group" aria-label="设备按键和输入">
+ <div class="guard glass" id="guard" role="status" hidden></div>
+ <div class="dock glass" id="dock" role="group" aria-label="设备按键和输入">
<div class="keys" role="group" aria-label="实体按键">
<button type="button" class="key" data-key="home" aria-label="主屏幕" title="主屏幕"><span class="ic" data-icon="home"></span></button>
<button type="button" class="key" data-key="lock" aria-label="锁屏" title="锁屏"><span class="ic" data-icon="lock"></span></button>
@@ -790,7 +958,7 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
</main>
<!-- 右:设备面板 -->
- <aside class="pane pane-dev" id="pane-dev" aria-label="设备面板">
+ <aside class="pane pane-dev glass" id="pane-dev" aria-label="设备面板">
<div class="resizer resizer-left" id="resizer-dev" role="separator" aria-orientation="vertical" aria-controls="pane-dev" aria-label="调整设备面板宽度" title="拖动调整宽度,双击恢复默认" tabindex="0"></div>
<div class="pane-head">
<div class="seg" role="tablist" aria-label="设备面板">
@@ -801,8 +969,18 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
<button type="button" class="btn btn-ghost btn-icon dev-close" id="dev-close" data-action="dev-close" aria-label="隐藏设备面板" title="隐藏设备面板"><span class="ic" data-icon="panel"></span></button>
</div>
<div class="pane-body">
- <section class="tabpanel" id="tp-status" role="tabpanel" aria-labelledby="tab-status"></section>
+ <section class="tabpanel" id="tp-status" role="tabpanel" aria-labelledby="tab-status">
+ <div><h2 class="nav-caption">设备列表</h2><ul class="nav-device-list" id="nav-devices"></ul></div>
+ <dl class="nav-readout" id="nav-facts" hidden></dl>
+ <details class="nav-disclosure" id="device-identifiers" hidden>
+ <summary>设备标识</summary><dl class="nav-readout" id="nav-ids"></dl>
+ </details>
+ <details class="nav-disclosure" id="connection-checks">
+ <summary>连接检查</summary><div id="nav-checks"></div>
+ </details>
+ </section>
<section class="tabpanel" id="tp-apps" role="tabpanel" aria-labelledby="tab-apps" hidden>
+ <p class="nav-offline-panel">连接设备后可查看应用。</p>
<div class="sec">
<label class="label" for="url">打开链接</label>
<div class="url-row">
@@ -818,6 +996,7 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
</div>
</section>
<section class="tabpanel" id="tp-elements" role="tabpanel" aria-labelledby="tab-elements" hidden>
+ <p class="nav-offline-panel">连接设备后可查看界面元素。</p>
<div class="sec">
<div class="sec-head"><span class="sec-title">当前界面的元素</span><span class="count" id="el-count"></span></div>
<div class="panel-tools">
@@ -839,24 +1018,16 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
</aside>
</div>
-<dialog class="dialog" id="updates-dialog" aria-labelledby="updates-title">
- <div class="update-head"><h2 id="updates-title">关于与更新</h2><form method="dialog"><button class="btn btn-ghost btn-sm">完成</button></form></div>
- <div class="update-version" id="update-version"></div>
- <dl class="update-facts" id="update-facts"></dl>
- <strong id="update-result" role="status"></strong>
- <p class="update-detail" id="update-guide"></p>
- <div id="update-command-block" hidden>
- <div class="update-command-head"><strong>升级命令</strong><button class="btn btn-sm" id="update-copy" type="button">复制命令</button></div>
- <code id="update-command"></code>
- <p class="update-detail" id="update-copy-status" role="status"></p>
+<dialog class="dialog glass" id="appearance" aria-labelledby="appearance-title">
+ <h2 id="appearance-title">设置</h2>
+ <div class="appearance-options">
+ <div class="appearance-row"><label for="language" id="language-label">界面语言</label><div class="appearance-picker"><select id="language-value" data-picker="language" hidden><option value="zh" lang="zh-CN">简体中文</option><option value="en" lang="en">English</option></select></div></div>
+ <div class="appearance-row"><label for="theme" id="theme-label">明暗</label><div class="appearance-picker"><select id="theme-value" data-picker="theme" hidden><option value="system">跟随系统</option><option value="light">浅色</option><option value="dark">深色</option></select></div></div>
+ <div class="appearance-row"><label for="text-size" id="text-size-label">界面字号</label><div class="appearance-picker"><select id="text-size-value" data-picker="text-size" hidden><option value="standard">标准</option><option value="large">大</option><option value="xlarge">特大</option></select></div></div>
</div>
- <p class="update-detail" id="update-policy"></p>
- <p class="update-detail" id="update-outcome"></p>
- <p class="update-detail" id="update-mismatch"></p>
- <div class="dialog-actions"><a class="btn btn-ghost" id="update-release" target="_blank" rel="noreferrer" hidden>发行说明</a>
- <button class="btn btn-primary" id="update-check" type="button" disabled>检查更新</button></div>
+ <form method="dialog" class="dialog-actions"><button class="btn btn-primary" type="submit">完成</button></form>
</dialog>
-<dialog class="dialog" id="clear-dialog" aria-labelledby="clear-title" aria-describedby="clear-desc">
+<dialog class="dialog glass" id="clear-dialog" aria-labelledby="clear-title" aria-describedby="clear-desc">
<h2 id="clear-title">清空全部操作记录?</h2>
<p id="clear-desc">只清除左侧的任务和步骤记录,不会影响设备上已经做过的操作。清空后无法恢复。</p>
<div class="dialog-actions">
@@ -865,7 +1036,7 @@ body.resizing .stage, body.resizing iframe { pointer-events: none; }
</div>
</dialog>
-<dialog class="dialog" id="stop-dialog" aria-labelledby="stop-title" aria-describedby="stop-desc">
+<dialog class="dialog glass" id="stop-dialog" aria-labelledby="stop-title" aria-describedby="stop-desc">
<h2 id="stop-title">停止这个任务?</h2>
<p id="stop-desc">AI 会立刻停下。已经在设备上做完的操作不会撤销。</p>
<div class="dialog-actions">
@@ -887,9 +1058,31 @@ const LANG = (() => {
return v === 'en' || v === 'zh' ? v : document.documentElement.dataset.lang === 'en' ? 'en' : 'zh';
})();
document.documentElement.lang = LANG === 'en' ? 'en' : 'zh-CN';
-const EN = {" · 演示数据":" · demo data"," 等":" and more","<div class=\"ph-kb\" data-type=\"Keyboard\">键盘</div>":"<div class=\"ph-kb\" data-type=\"Keyboard\">Keyboard</div>","<li class=\"empty-note\">打开这一页时会读取已安装的 App。</li>":"<li class=\"empty-note\">The installed apps are read when this tab opens.</li>","<li class=\"sr-only\">正在读取 App 列表…</li>":"<li class=\"sr-only\">Reading the app list…</li>","<li class=\"sr-only\">正在读取元素…</li>":"<li class=\"sr-only\">Reading elements…</li>","<option>没有可用的 AI</option>":"<option>No AI available</option>","<p class=\"empty-note\">正在连接 iphone-control 服务…</p>":"<p class=\"empty-note\">Connecting to the iphone-control service…</p>","<span class=\"chip\"><span class=\"chip-dot warn\"></span><span>演示模式</span></span>":"<span class=\"chip\"><span class=\"chip-dot warn\"></span><span>Demo</span></span>","AI 任务已停止":"AI task stopped","AI 任务已完成":"AI task done","AI 任务没有完成":"AI task not done","AI 任务的事件流断开了,正在重连…":"Lost the AI task's event stream, reconnecting…","AI 会立刻停下。已经在设备上做完的操作不会撤销。":"The AI stops right away. What it already did on the device isn't undone.","AI 助手":"AI assistant","AI 在等你确认一步操作":"The AI is waiting for you to confirm a step","AI 在等你确认一步操作,确认前画面保持锁定。":"The AI is waiting for you to confirm a step; the screen stays locked until you do.","AI 已暂停":"AI paused","AI 已暂停。交还后它会先重新看一遍屏幕。":"The AI is paused. When you hand back, it looks at the screen again first.","AI 正在操作这台设备":"The AI is operating this device","AI 正在操作这台设备。要自己操作,先点「接管」。":"The AI is operating this device. To act yourself, click “Take over” first.","AI 继续执行":"AI resumed","AI 能用的操作":"Actions the AI can use","Enter 发送 · Shift+Enter 换行":"Enter to send · Shift+Enter for a new line","HID 后备":"HID fallback","USB 连接":"USB connection","WDA 已签名安装":"WDA signed and installed","WDA 运行中":"WDA running","https://… 或 App 的 URL scheme":"https://… or an app's URL scheme","iMessage 信息":"iMessage","iOS 版本":"iOS Version","iPad mini(第 6 代)":"iPad mini (6th generation)","iphone-control 控制台":"iphone-control console","、":", ","。":".","。可以换个说法再试,或者接管后手动完成。":". Try rephrasing, or take over and finish by hand.","「":"“","」":"”","」。":"”.","」。界面可能已经变了,需要重新截图判断。":"” on the screen. It may have changed; take a new screenshot.","」出现,最多 5 秒":"” to appear, up to 5 s","」发给「":"” to “","」已在前台":"” is in front","」已经出现(":"” appeared (","」的 App。":"”.","」的元素。":"”.","」的对话":"”","」的对话。":"”.","」,能看到:":"”, showing: ","」:":"”: ","一共":"","上滑:":": ","与「":"Chat with “","世界时钟":"World Clock","个":"items","个带文字的元素":"elements with text","个步骤":"steps","个闹钟":"alarms","个闹钟:":"alarms: ","主屏幕":"Home Screen","乐":"M","交给 AI 的任务":"Task for the AI","交还 AI":"Hand back","今天":"Today","今天,−13 小时":"Today, −13 hours","今天,−8 小时":"Today, −8 hours","从":"Swipe up from","任务已交给 AI,画面的手动操作已锁定":"Task handed to the AI; manual control of the screen is locked","任务控制":"Task controls","任务没能交给 AI。手动操作和设备面板不受影响。":"The task couldn't be handed to the AI. Manual control and the device panel still work.","任务记录":"Task history","伦敦":"London","你刚才接管过设备,先重新看一下界面再继续。":"You took over the device just now, so first a fresh look at the screen.","你在接管":"You're in control","你已接管:现在可以直接在画面上操作。":"You're in control: act on the screen directly now.","你拒绝了发送。消息还留在输入框里,没有发出。":"You declined to send. The message is still in the text field, not sent.","你拒绝了这一步,没有执行。":"You rejected this step; it wasn't done.","例如:秒表":"e.g. Stopwatch","信":"M","信任这台电脑":"Trust this computer","信息":"Messages","停止":"Stop","停止任务":"Stop task","停止这个任务?":"Stop this task?","健康":"Health","像素":"px","元素":"Elements","先写下要 AI 做的事,例如「打开设置,查看系统版本」。":"First write what the AI should do, for example “Open Settings and check the iOS version”.","先填要打开的链接":"Enter the link to open first","先填要等的文字。":"Enter the text to wait for first.","先看一下设备现在的界面。":"First a look at the device's screen.","先输入要打到设备上的文字":"Enter the text to type on the device first","全部就绪":"All ready","关":"off","关于本机":"About","内容填好了。发消息需要你先确认。":"The message is ready. Sending it needs your confirmation.","再点「关于本机」。":"Then tap “About”.","切到「":"Switched to “","切换到实际尺寸(100%)":"Actual size (100%)","切换视图":"Switch view","切换语言":"Switch language","列表里没有闹钟":"No alarms in the list","删除":"Delete","删除这条记录":"Delete this record","刷新":"Refresh","刷新 App 列表":"Refresh the app list","刷新画面":"Refresh the picture","前台":"Front","前台 App":"Foreground app","助手":"assistant","包含系统 App":"Include system apps","北京":"Beijing","去确认":"Review","发给「":"To “","发送":"Send","发送消息":"Send message","取消":"Cancel","只清除左侧的任务和步骤记录,不会影响设备上已经做过的操作。清空后无法恢复。":"Only clears the tasks and steps on the left; nothing already done on the device changes. This can't be undone.","名称":"Name","向上轻扫以打开":"Swipe up to open","向设备输入文字":"Type on the device","启动":"Start","启动、关闭 App":"Open and quit apps","周末":"Weekends","回到「信息」列表":"Back to the Messages list","回到主屏幕":"Back to the Home Screen","图":"M","在第":"Stopped at step","在设备「设置 › 隐私与安全性 › 开发者模式」里打开,重启后确认。":"Turn it on in Settings › Privacy & Security › Developer Mode on the device, then confirm after the restart.","地图":"Maps","型号名称":"Model Name","型号未知":"Unknown model","备忘录":"Notes","复位":"Reset","天气":"Weather","失败":"Failed","妈妈":"Mom","它不是可点的控件,界面没有变化":"it isn't a control, nothing changed","完成":"Done","实体按键":"Hardware buttons","实时画面":"Live","容量":"Capacity","就绪":"Ready","就绪检查":"Readiness","屏幕":"Screen","屏幕尺寸":"Screen size","工作日":"Weekdays","已中止":"Stopped","已交还 AI,它会先重新看一遍屏幕":"Handed back to the AI; it looks at the screen again first","已停止":"Stopped","已切换到":"Switched to","已删除这条记录":"Record deleted","已刷新演示画面":"Demo screen refreshed","已发送给「":"Sent to “","已回到主屏幕。":"Back on the Home Screen.","已安装的 App":"Installed apps","已完成":"Done","已批准,AI 继续执行":"Approved, the AI continues","已把「":"Sent “","已拒绝":"Rejected","已拒绝这一步":"Step rejected","已改为自动选择:继续控制":"Switched to automatic: still controlling","已显示设备面板":"Device panel shown","已暂停":"Paused","已清空操作记录":"History cleared","已用 IPHONE_UDID 固定设备,不能切换":"IPHONE_UDID pins the device, so it can't be switched","已用 Safari 打开":"Opened in Safari:","已经在控制这台设备":"Already controlling this device","已结束「":"Quit “","已自动解锁,回到主屏幕":"Unlocked automatically, back to the Home Screen","已设置密码":"Passcode set","已输入「":"Typed “","已连接":"Connected","已连接的设备":"Connected device","已锁定":"Locked","已锁屏":"Locked","已隐藏设备面板,点右上角「设备面板」可以再打开":"Device panel hidden; open it again with “Device panel” at the top right","应用":"Apps","底部有「闹钟」标签,点它。":"There's an “Alarms” tab at the bottom; tap it.","康":"H","开":"on","开发者模式":"Developer Mode","开始任务":"Start task","当前任务结束后可以发新任务":"A new task can start when this one ends","当前任务结束后可以重新执行":"Can run again when the current task ends","当前在「":"Now on “","当前界面没有带文字的元素。":"No elements with text on the current screen.","当前界面的元素":"Elements on screen","当前缩放比例,点击切换到实际尺寸":"Current zoom; click for actual size","当前设备":"Current device","待确认":"Confirm","快递通知":"Delivery","您的包裹已到驿站,凭取件码取件":"Your parcel is at the pickup point; bring your pickup code","想让设备做什么?":"What should the device do?","我晚点到":"I'll be late","手动操作已锁定,避免和 AI 同时点击。":"Manual control is locked so you and the AI don't tap at once.","打开":"On","打开「":"Open “","打开了「":"Opened “","打开了与「":"Opened the chat with “","打开链接":"Open links","执行中":"Running","执行任务的 AI":"AI that runs the task","执行任务的本地 AI":"Local AI that runs the task","执行步骤":"Steps","批准并执行":"Approve","找到":"Found","拒绝":"Reject","拖动调整宽度,双击恢复默认":"Drag to resize, double-click to reset","按一下主屏幕键。":"Press the Home button.","按名字点「":"Tap by name “","按名称或 bundle id 搜索":"Search by name or bundle id","按文字或类型筛选":"Filter by text or type","按窗口大小自动适应":"Fit to the window","接管":"Take over","接管中":"You're in control","控制台":"console","控制设备":"Device","搜索":"Search","搜索 App":"Search apps","摄":"C","操作失败":"Action failed","操作往返":"round trip","操作没有生效:":"That didn't take effect: ","操作通道":"Route","收起步骤":"Hide steps","放大画面":"Zoom in","放大(也可以按住 Ctrl/⌘ 滚动滚轮)":"Zoom in (or Ctrl/⌘ + scroll)","无线局域网":"Wi-Fi","日历":"Calendar","日期与时间":"Date & Time","时":"C","时钟":"Clock","明天的评审改到上午十点了":"Tomorrow's review moved to 10 a.m.","昨天":"Yesterday","显示与亮度":"Display & Brightness","晚上回来吃饭吗?":"Coming home for dinner tonight?","晴":"W","暂停":"Pause","未就绪":"Not ready","未设置":"Not set","未锁定":"Unlocked","查看":"Show","次计次":"","正在打开":"Opening","正在挂开发者镜像、启动 WebDriverAgent,最长约 2 分钟。期间截图和点击会改走 HID 后备。":"Mounting the developer disk image and starting WebDriverAgent, up to about 2 minutes. Meanwhile screenshots and taps use the HID fallback.","正在查找…":"Looking…","正在连接 iphone-control 服务…":"Connecting to the iphone-control service…","正在连接…":"Connecting…","正在连接画面…":"Connecting to the screen…","正在重新连接画面…":"Reconnecting the picture…","步":"steps","步停下了。已经做完的操作不会撤销。":". What was already done isn't undone.","步时的屏幕截图":"screen","步没走通:":"failed: ","没找到「iOS 版本」":"“iOS Version” not found","没有你自己安装的 App。勾上「包含系统 App」可以看到系统自带的。":"No apps you installed yourself. Check “Include system apps” to see the built-in ones.","没有名称或 bundle id 含「":"No app whose name or bundle id contains “","没有含「":"No element contains “","没有完成":"Not done","没有弹出键盘:先在画面里点一下输入框。":"No keyboard on screen: tap a text field on the screen first.","没有画面:画面来自设备上的 WebDriverAgent,它现在没有运行。3 秒后自动重试…":"No picture: it comes from WebDriverAgent on the device, which isn't running right now. Retrying in 3 s…","没有设备":"No device","没有读到 App。":"No apps were read.","没有这个接口(":"has no such endpoint (","清空":"Clear","清空全部操作记录?":"Clear all history?","清空记录":"Clear history","滑动":"Swipe","演示模式":"Demo","演示模式只内置了几个示例:查系统版本、看闹钟、秒表、发信息、回主屏幕、看屏幕。这条在模拟画面上做不了。":"The demo only knows a few examples: check the iOS version, look at alarms, the stopwatch, send a message, go Home, look at the screen. This one can't be done on the simulated screen.","演示模式只模拟 http(s) 链接,URL scheme 要连上真机才能试":"The demo only simulates http(s) links; try URL schemes with a real device","演示模式只能跑内置示例。连上服务后,这条指令会交给真正的 agent。":"The demo only runs its built-in examples. Connected to the service, this task goes to a real agent.","演示模式没有模拟计时器":"The demo doesn't simulate timers","演示模式没有模拟这一页":"The demo doesn't simulate this page","演示模式没有模拟这个 App。按主屏幕键或从底部上滑返回。":"The demo doesn't simulate this app. Press Home or swipe up from the bottom to go back.","演示模式没有模拟这个任务":"The demo doesn't simulate this task","演示模式:没有连上 iphone-control 服务。设备画面、App 列表、元素和 AI 的每一步都是本地模拟的。":"Demo mode: not connected to the iphone-control service. The screen, app list, elements and every AI step are simulated locally.","演示模式:没有连上 iphone-control 服务,画面是本地模拟的。":"Demo mode: not connected to the iphone-control service; the screen is simulated locally.","演示画面 · 本地模拟":"Demo screen · simulated locally","点「启动」。":"Tap “Start”.","点「读取」列出当前界面上带文字的元素。鼠标移上去会在画面上框出位置。":"Click “Read” to list the elements with text on the current screen. Hover one to outline it on the picture.","点一下底部的输入框。":"Tap the text field at the bottom.","点了":"Tapped","点击重新执行这条指令":"Click to run this task again","点它":"Tap","点底部的「秒表」。":"Tap “Stopwatch” at the bottom.","点开和「":"Open the chat with “","点按、滑动、长按":"Tap, swipe, long press","照":"P","照片":"Photos","状态":"Status","王磊":"Wang Lei","现在在「":"Now on “","用 USB 连上设备,确认数据线能传数据。":"Connect the device over USB with a cable that carries data.","用一句话描述目标。AI 会看真实屏幕,用下面这些现成的操作一步步完成;遇到付款、删除、发消息这类操作会先停下来等你确认。":"Describe the goal in a sentence. The AI looks at the real screen and gets there step by step with the actions below; before paying, deleting, sending a message and the like it stops and waits for you to confirm.","电池":"Battery","电话":"Phone","画面仍为 AI 保留,要自己操作先接管。":"The screen stays reserved for the AI; take over to act yourself.","画面断开":"Picture lost","画面断开 · 自动重试中":"Picture lost · retrying","画面缩放":"Zoom","界面上没找到「":"Couldn't find “","界面变了,":"The screen changed. ","相机":"Camera","看屏幕、读元素":"See the screen, read elements","确认删除":"Delete","确认前画面保持锁定。":"The screen stays locked until you confirm.","确认已经在主屏幕。":"Check that the Home Screen is in front.","确认秒表在走。":"Check that the stopwatch runs.","秒内没有出现「":"s passed without “","秒表":"Stopwatch","秒表已停止":"Stopwatch stopped","秒表已复位":"Stopwatch reset","秒表已经在计时":"The stopwatch is already running","秒表已经开始计时。":"The stopwatch has started.","秒表开始计时":"Stopwatch started","秒表时间":"Stopwatch time","秒表正在计时:":"Stopwatch running: ","秒表没有在计时":"The stopwatch isn't running","秒)":" s)","秒:演示模式没有模拟长按菜单":"s: the demo doesn't simulate long-press menus","空闲":"Idle","第":"Step","等「":"Waiting for “","等一段文字出现":"Wait for text","等你确认":"Needs you","等待 5 秒":"Wait 5 s","等待中…":"Waiting…","等待前一步":"waiting for the step before","筛选元素":"Filter elements","系统":"System","系统版本在「通用 › 关于本机」里,先点「通用」。":"The version is under General › About; tap “General” first.","纽约":"New York","结束":"Quit","结束「":"Quit “","继续":"Resume","继续执行":"Keep running","缩小画面":"Zoom out","缩小(也可以按住 Ctrl/⌘ 滚动滚轮)":"Zoom out (or Ctrl/⌘ + scroll)","自动解锁":"Auto-unlock","自动选择":"Automatic","蓝牙":"Bluetooth","计时器":"Timers","计次":"Lap","让 AI 操作你的 Apple 设备":"Let AI operate your Apple device","记":"N","记了第":"Recorded lap","设":"S","设备":"Device","设备实时画面:单击轻点,拖动或滚动滚轮滑动,按住长按":"Live device screen: click to tap, drag or scroll to swipe, hold to long-press","设备屏幕":"Device screen","设备按键和输入":"Device buttons and typing","设备的实时画面":"Live picture of the device","设备重启后还没解锁过,需要在设备上手动解锁一次。":"The device hasn't been unlocked since it restarted; unlock it by hand once.","设备重启后首次启用 UI 自动化,请在设备上输入锁屏密码。":"UI automation is starting for the first time since the restart; enter the passcode on the device.","设备面板":"Device panel","设置":"Settings","话":"P","请求失败(":"Request failed (","读一下列表里的闹钟。":"Read the alarms in the list.","读一下界面上带文字的元素。":"Read the elements with text on the screen.","读出「iOS 版本」这一行。":"Read the “iOS Version” row.","读取":"Read","调整 AI 助手栏宽度":"Resize the AI assistant column","调整设备面板宽度":"Resize the device panel","软件更新":"Software Update","轻点":"Tap","输入":"Type","输入并回车":"Type and press Return","输入文字":"Type text","输入框":"Text field","输入框是空的,没有发出任何内容":"The text field is empty, nothing was sent","输入框获得焦点,弹出了键盘":"The text field has focus and the keyboard is up","输入要发的内容。":"Type the message.","运行 <code>iphone-control sign</code>,用免费 Apple ID 签名并安装。":"Run <code>iphone-control sign</code> to sign and install it with a free Apple ID.","还不知道屏幕尺寸,稍后再试":"The screen size isn't known yet; try again shortly","还停在「":"Still on “","还在读取可用的 AI,稍等一下再试。":"Still reading the available AIs; try again in a moment.","还在连接服务,稍等一下再开始":"Still connecting to the service; start in a moment","还没有拿到守护进程状态。":"No daemon status yet.","这个位置在画面外面":"That point is outside the screen","这台机器上没有可用的 AI。安装并登录 Claude Code 或 Codex,再重新运行 iphone-control viewer。":"No AI is available on this machine. Install and log in to Claude Code or Codex, then run iphone-control viewer again.","这台机器的 PATH 里没有 claude 或 codex":"Neither claude nor codex is on this machine's PATH","这台设备的系统版本是 iOS 18.1。":"This device runs iOS 18.1.","这里没有可点的东西":"nothing to tap here","进入「":"Opened “","进行中":"in progress","连接中":"Connecting","适应":"Fit","通用":"General","通道":"Route","邮":"M","邮件":"Mail","重新执行":"Run again","重新执行:":"Run again: ","钱":"W","钱包":"Wallet","锁定屏幕":"Lock Screen","锁屏":"Lock","键盘":"Keyboard","长按":"Long press","闹钟":"Alarms","闹钟 ":"Alarm ","闹钟,":"Alarm, ","隐私与安全性":"Privacy & Security","隐藏设备面板":"Hide the device panel","需要你确认:":"Needs your confirmation: ","需要处理":"needs attention","音乐":"Music","音量减":"Volume down","音量减(演示画面没有变化)":"Volume down (no change on the demo screen)","音量加":"Volume up","音量加(演示画面没有变化)":"Volume up (no change on the demo screen)","页面刷新时这个任务还在执行,刷新后页面不再跟踪它的进度。":"This task was still running when the page reloaded, so the page no longer follows it.","(":" (","(未安装)":" (not installed)","(演示画面不加载网页)":" (the demo doesn't load web pages)","(演示)":" (demo)",")":")",",":", ",":":": ",":演示画面不支持滚动":": the demo screen doesn't scroll","看一下屏幕":"Look at the screen","读取屏幕上的内容":"Read what's on the screen","查看手机状态":"Check the phone's status","点击屏幕":"Tap the screen","点击":"Tap","长按屏幕":"Long-press the screen","滑动屏幕":"Swipe the screen","按主屏幕键":"Press Home","按键":"Press a button","打开 App":"Open","关闭":"Quit","等待":"Wait for","出现":"to appear","查看已安装的 App":"List installed apps","查看已连接的设备":"List connected devices","连续执行几步操作":"Run a few steps in a row","请你确认":"Ask you to confirm","操作手机":"Operate the phone","这一步没成功":"This step didn't work","另一台设备":"another device","设备已在别处切换到":"The device was switched elsewhere to",",画面已跟过去":"; the picture follows it","没有连上设备:用数据线连上 iPhone,确认数据线能传数据。":"No device connected: connect the iPhone with a cable that carries data.","还没设置好(配对、开发者模式)。在终端运行":"isn’t set up yet (pairing, Developer Mode). In a terminal, run",",选「手机」。":" and pick Phone.","上还没装 WebDriverAgent。":"doesn’t have WebDriverAgent yet.","正在签名安装…":"Signing and installing…","签名并安装 WDA":"Sign and install WDA","上还没装 WebDriverAgent,需要先登录 Apple ID:在终端运行":"doesn’t have WebDriverAgent yet, and an Apple ID is needed to sign it: in a terminal, run",",选「Apple ID」。":" and pick Apple ID.","正在":"Starting WebDriverAgent on","上启动 WebDriverAgent,通常 10–60 秒…":"— usually 10–60 seconds…","设备重启后还没解锁过,在设备上手动解锁一次,画面就会出来。":"The device hasn’t been unlocked since it restarted. Unlock it once by hand and the picture appears.","正在签名并安装 WebDriverAgent,大约 1–2 分钟,保持手机解锁…":"Signing and installing WebDriverAgent, about 1–2 minutes; keep the phone unlocked…","运行 <code>iphone-control setup --reconfigure</code> 选「手机」,在设备上点「信任」。":"Run <code>iphone-control setup --reconfigure</code>, pick Phone, and tap “Trust” on the device.",":WebDriverAgent 启动失败,会自动重试":": WebDriverAgent failed to start; retrying automatically","不可用":"Unavailable","正在挂开发者镜像、启动 WebDriverAgent,最长约 2 分钟。这台设备低于 iOS 27,没有 HID 后备,期间不能截图和操作。":"Mounting the developer disk image and starting WebDriverAgent, up to about 2 minutes. This device is below iOS 27, so there is no HID fallback: no screenshots or actions until then.","重新签名并安装 WDA":"Re-sign and install WDA"};
-Object.assign(EN, {'关于与更新':'About & updates','完成':'Done','检查更新':'Check for updates','检查中…':'Checking…','发行说明':'Release notes','升级命令':'Upgrade command','复制命令':'Copy command','已复制':'Copied','请选中命令并手动复制。':'Select the command and copy it manually.'});
+const EN = {" · 演示数据":" · demo data"," 等":" and more","<div class=\"ph-kb\" data-type=\"Keyboard\">键盘</div>":"<div class=\"ph-kb\" data-type=\"Keyboard\">Keyboard</div>","<li class=\"empty-note\">打开这一页时会读取已安装的 App。</li>":"<li class=\"empty-note\">The installed apps are read when this tab opens.</li>","<li class=\"sr-only\">正在读取 App 列表…</li>":"<li class=\"sr-only\">Reading the app list…</li>","<li class=\"sr-only\">正在读取元素…</li>":"<li class=\"sr-only\">Reading elements…</li>","<option>没有可用的 AI</option>":"<option>No AI available</option>","<p class=\"empty-note\">正在连接 iphone-control 服务…</p>":"<p class=\"empty-note\">Connecting to the iphone-control service…</p>","<span class=\"chip\"><span class=\"chip-dot warn\"></span><span>演示模式</span></span>":"<span class=\"chip\"><span class=\"chip-dot warn\"></span><span>Demo</span></span>","AI 任务已停止":"AI task stopped","AI 任务已完成":"AI task done","AI 任务没有完成":"AI task not done","AI 任务的事件流断开了,正在重连…":"Lost the AI task's event stream, reconnecting…","AI 会立刻停下。已经在设备上做完的操作不会撤销。":"The AI stops right away. What it already did on the device isn't undone.","AI 助手":"AI assistant","AI 在等你确认一步操作":"The AI is waiting for you to confirm a step","AI 在等你确认一步操作,确认前画面保持锁定。":"The AI is waiting for you to confirm a step; the screen stays locked until you do.","AI 已暂停":"AI paused","AI 已暂停。交还后它会先重新看一遍屏幕。":"The AI is paused. When you hand back, it looks at the screen again first.","AI 正在操作这台设备":"The AI is operating this device","AI 正在操作这台设备。要自己操作,先点「接管」。":"The AI is operating this device. To act yourself, click “Take over” first.","AI 继续执行":"AI resumed","AI 能用的操作":"Actions the AI can use","Enter 发送 · Shift+Enter 换行":"Enter to send · Shift+Enter for a new line","HID 后备":"HID fallback","USB 连接":"USB connection","WDA 已签名安装":"WDA signed and installed","WDA 运行中":"WDA running","https://… 或 App 的 URL scheme":"https://… or an app's URL scheme","iMessage 信息":"iMessage","iOS 版本":"iOS Version","iPad mini(第 6 代)":"iPad mini (6th generation)","iphone-control 控制台":"iphone-control console","、":", ","。":".","。可以换个说法再试,或者接管后手动完成。":". Try rephrasing, or take over and finish by hand.","「":"“","」":"”","」。":"”.","」。界面可能已经变了,需要重新截图判断。":"” on the screen. It may have changed; take a new screenshot.","」出现,最多 5 秒":"” to appear, up to 5 s","」发给「":"” to “","」已在前台":"” is in front","」已经出现(":"” appeared (","」的 App。":"”.","」的元素。":"”.","」的对话":"”","」的对话。":"”.","」,能看到:":"”, showing: ","」:":"”: ","一共":"","上滑:":": ","与「":"Chat with “","世界时钟":"World Clock","个":"items","个带文字的元素":"elements with text","个步骤":"steps","个闹钟":"alarms","个闹钟:":"alarms: ","主屏幕":"Home Screen","乐":"M","交给 AI 的任务":"Task for the AI","交还 AI":"Hand back","今天":"Today","今天,−13 小时":"Today, −13 hours","今天,−8 小时":"Today, −8 hours","从":"Swipe up from","任务已交给 AI,画面的手动操作已锁定":"Task handed to the AI; manual control of the screen is locked","任务控制":"Task controls","任务没能交给 AI。手动操作和设备面板不受影响。":"The task couldn't be handed to the AI. Manual control and the device panel still work.","任务记录":"Task history","伦敦":"London","你刚才接管过设备,先重新看一下界面再继续。":"You took over the device just now, so first a fresh look at the screen.","你在接管":"You're in control","你已接管:现在可以直接在画面上操作。":"You're in control: act on the screen directly now.","你拒绝了发送。消息还留在输入框里,没有发出。":"You declined to send. The message is still in the text field, not sent.","你拒绝了这一步,没有执行。":"You rejected this step; it wasn't done.","例如:秒表":"e.g. Stopwatch","信":"M","信任这台电脑":"Trust this computer","信息":"Messages","停止":"Stop","停止任务":"Stop task","停止这个任务?":"Stop this task?","健康":"Health","像素":"px","元素":"Elements","先写下要 AI 做的事,例如「打开设置,查看系统版本」。":"First write what the AI should do, for example “Open Settings and check the iOS version”.","先填要打开的链接":"Enter the link to open first","先填要等的文字。":"Enter the text to wait for first.","先看一下设备现在的界面。":"First a look at the device's screen.","先输入要打到设备上的文字":"Enter the text to type on the device first","全部就绪":"All ready","关":"off","关于本机":"About","内容填好了。发消息需要你先确认。":"The message is ready. Sending it needs your confirmation.","再点「关于本机」。":"Then tap “About”.","切到「":"Switched to “","切换到实际尺寸(100%)":"Actual size (100%)","切换视图":"Switch view","切换语言":"Switch language","列表里没有闹钟":"No alarms in the list","删除":"Delete","删除这条记录":"Delete this record","刷新":"Refresh","刷新 App 列表":"Refresh the app list","刷新画面":"Refresh the picture","前台":"Front","前台 App":"Foreground app","助手":"assistant","包含系统 App":"Include system apps","北京":"Beijing","去确认":"Review","发给「":"To “","发送":"Send","发送消息":"Send message","取消":"Cancel","只清除左侧的任务和步骤记录,不会影响设备上已经做过的操作。清空后无法恢复。":"Only clears the tasks and steps on the left; nothing already done on the device changes. This can't be undone.","名称":"Name","向上轻扫以打开":"Swipe up to open","向设备输入文字":"Type on the device","启动":"Start","启动、关闭 App":"Open and quit apps","周末":"Weekends","回到「信息」列表":"Back to the Messages list","回到主屏幕":"Back to the Home Screen","图":"M","在第":"Stopped at step","在设备「设置 › 隐私与安全性 › 开发者模式」里打开,重启后确认。":"Turn it on in Settings › Privacy & Security › Developer Mode on the device, then confirm after the restart.","地图":"Maps","型号名称":"Model Name","型号未知":"Unknown model","备忘录":"Notes","复位":"Reset","天气":"Weather","失败":"Failed","妈妈":"Mom","它不是可点的控件,界面没有变化":"it isn't a control, nothing changed","完成":"Done","实体按键":"Hardware buttons","实时画面":"Live","容量":"Capacity","就绪":"Ready","就绪检查":"Readiness","屏幕":"Screen","屏幕尺寸":"Screen size","工作日":"Weekdays","已中止":"Stopped","已交还 AI,它会先重新看一遍屏幕":"Handed back to the AI; it looks at the screen again first","已停止":"Stopped","已切换到":"Switched to","已删除这条记录":"Record deleted","已刷新演示画面":"Demo screen refreshed","已发送给「":"Sent to “","已回到主屏幕。":"Back on the Home Screen.","已安装的 App":"Installed apps","已完成":"Done","已批准,AI 继续执行":"Approved, the AI continues","已把「":"Sent “","已拒绝":"Rejected","已拒绝这一步":"Step rejected","已改为自动选择:继续控制":"Switched to automatic: still controlling","已显示设备面板":"Device panel shown","已暂停":"Paused","已清空操作记录":"History cleared","已用 IPHONE_UDID 固定设备,不能切换":"IPHONE_UDID pins the device, so it can't be switched","已用 Safari 打开":"Opened in Safari:","已经在控制这台设备":"Already controlling this device","已结束「":"Quit “","已自动解锁,回到主屏幕":"Unlocked automatically, back to the Home Screen","已设置密码":"Passcode set","已输入「":"Typed “","已连接":"Connected","已连接的设备":"Connected device","已锁定":"Locked","已锁屏":"Locked","已隐藏设备面板,点右上角「设备面板」可以再打开":"Device panel hidden; open it again with “Device panel” at the top right","应用":"Apps","底部有「闹钟」标签,点它。":"There's an “Alarms” tab at the bottom; tap it.","康":"H","开":"on","开发者模式":"Developer Mode","开始任务":"Start task","当前任务结束后可以发新任务":"A new task can start when this one ends","当前任务结束后可以重新执行":"Can run again when the current task ends","当前在「":"Now on “","当前界面没有带文字的元素。":"No elements with text on the current screen.","当前界面的元素":"Elements on screen","当前缩放比例,点击切换到实际尺寸":"Current zoom; click for actual size","当前设备":"Current device","待确认":"Confirm","快递通知":"Delivery","您的包裹已到驿站,凭取件码取件":"Your parcel is at the pickup point; bring your pickup code","想让设备做什么?":"What should the device do?","我晚点到":"I'll be late","手动操作已锁定,避免和 AI 同时点击。":"Manual control is locked so you and the AI don't tap at once.","打开":"On","打开「":"Open “","打开了「":"Opened “","打开了与「":"Opened the chat with “","打开链接":"Open links","执行中":"Running","执行任务的 AI":"AI that runs the task","执行任务的本地 AI":"Local AI that runs the task","执行步骤":"Steps","批准并执行":"Approve","找到":"Found","拒绝":"Reject","拖动调整宽度,双击恢复默认":"Drag to resize, double-click to reset","按一下主屏幕键。":"Press the Home button.","按名字点「":"Tap by name “","按名称或 bundle id 搜索":"Search by name or bundle id","按文字或类型筛选":"Filter by text or type","按窗口大小自动适应":"Fit to the window","接管":"Take over","接管中":"You're in control","控制台":"console","控制设备":"Device","搜索":"Search","搜索 App":"Search apps","摄":"C","操作失败":"Action failed","操作往返":"round trip","操作没有生效:":"That didn't take effect: ","操作通道":"Route","收起步骤":"Hide steps","放大画面":"Zoom in","放大(也可以按住 Ctrl/⌘ 滚动滚轮)":"Zoom in (or Ctrl/⌘ + scroll)","无线局域网":"Wi-Fi","日历":"Calendar","日期与时间":"Date & Time","时":"C","时钟":"Clock","明天的评审改到上午十点了":"Tomorrow's review moved to 10 a.m.","昨天":"Yesterday","显示与亮度":"Display & Brightness","晚上回来吃饭吗?":"Coming home for dinner tonight?","晴":"W","暂停":"Pause","未就绪":"Not ready","未设置":"Not set","未锁定":"Unlocked","查看":"Show","次计次":"","正在打开":"Opening","正在挂开发者镜像、启动 WebDriverAgent,最长约 2 分钟。期间截图和点击会改走 HID 后备。":"Mounting the developer disk image and starting WebDriverAgent, up to about 2 minutes. Meanwhile screenshots and taps use the HID fallback.","正在查找…":"Looking…","正在连接 iphone-control 服务…":"Connecting to the iphone-control service…","正在连接…":"Connecting…","正在连接画面…":"Connecting to the screen…","正在重新连接画面…":"Reconnecting the picture…","步":"steps","步停下了。已经做完的操作不会撤销。":". What was already done isn't undone.","步时的屏幕截图":"screen","步没走通:":"failed: ","没找到「iOS 版本」":"“iOS Version” not found","没有你自己安装的 App。勾上「包含系统 App」可以看到系统自带的。":"No apps you installed yourself. Check “Include system apps” to see the built-in ones.","没有名称或 bundle id 含「":"No app whose name or bundle id contains “","没有含「":"No element contains “","没有完成":"Not done","没有弹出键盘:先在画面里点一下输入框。":"No keyboard on screen: tap a text field on the screen first.","没有画面:画面来自设备上的 WebDriverAgent,它现在没有运行。3 秒后自动重试…":"No picture: it comes from WebDriverAgent on the device, which isn't running right now. Retrying in 3 s…","没有设备":"No device","没有读到 App。":"No apps were read.","没有这个接口(":"has no such endpoint (","清空":"Clear","清空全部操作记录?":"Clear all history?","清空记录":"Clear history","滑动":"Swipe","演示模式":"Demo","演示模式只内置了几个示例:查系统版本、看闹钟、秒表、发信息、回主屏幕、看屏幕。这条在模拟画面上做不了。":"The demo only knows a few examples: check the iOS version, look at alarms, the stopwatch, send a message, go Home, look at the screen. This one can't be done on the simulated screen.","演示模式只模拟 http(s) 链接,URL scheme 要连上真机才能试":"The demo only simulates http(s) links; try URL schemes with a real device","演示模式只能跑内置示例。连上服务后,这条指令会交给真正的 agent。":"The demo only runs its built-in examples. Connected to the service, this task goes to a real agent.","演示模式没有模拟计时器":"The demo doesn't simulate timers","演示模式没有模拟这一页":"The demo doesn't simulate this page","演示模式没有模拟这个 App。按主屏幕键或从底部上滑返回。":"The demo doesn't simulate this app. Press Home or swipe up from the bottom to go back.","演示模式没有模拟这个任务":"The demo doesn't simulate this task","演示模式:没有连上 iphone-control 服务。设备画面、App 列表、元素和 AI 的每一步都是本地模拟的。":"Demo mode: not connected to the iphone-control service. The screen, app list, elements and every AI step are simulated locally.","演示模式:没有连上 iphone-control 服务,画面是本地模拟的。":"Demo mode: not connected to the iphone-control service; the screen is simulated locally.","演示画面 · 本地模拟":"Demo screen · simulated locally","点「启动」。":"Tap “Start”.","点「读取」列出当前界面上带文字的元素。鼠标移上去会在画面上框出位置。":"Click “Read” to list the elements with text on the current screen. Hover one to outline it on the picture.","点一下底部的输入框。":"Tap the text field at the bottom.","点了":"Tapped","点击重新执行这条指令":"Click to run this task again","点它":"Tap","点底部的「秒表」。":"Tap “Stopwatch” at the bottom.","点开和「":"Open the chat with “","点按、滑动、长按":"Tap, swipe, long press","照":"P","照片":"Photos","状态":"Status","王磊":"Wang Lei","现在在「":"Now on “","用 USB 连上设备,确认数据线能传数据。":"Connect the device over USB with a cable that carries data.","用一句话描述目标。AI 会看真实屏幕,用下面这些现成的操作一步步完成;遇到付款、删除、发消息这类操作会先停下来等你确认。":"Describe the goal in a sentence. The AI looks at the real screen and gets there step by step with the actions below; before paying, deleting, sending a message and the like it stops and waits for you to confirm.","电池":"Battery","电话":"Phone","画面仍为 AI 保留,要自己操作先接管。":"The screen stays reserved for the AI; take over to act yourself.","画面断开":"Picture lost","画面断开 · 自动重试中":"Picture lost · retrying","画面缩放":"Zoom","界面上没找到「":"Couldn't find “","界面变了,":"The screen changed. ","相机":"Camera","看屏幕、读元素":"See the screen, read elements","确认删除":"Delete","确认前画面保持锁定。":"The screen stays locked until you confirm.","确认已经在主屏幕。":"Check that the Home Screen is in front.","确认秒表在走。":"Check that the stopwatch runs.","秒内没有出现「":"s passed without “","秒表":"Stopwatch","秒表已停止":"Stopwatch stopped","秒表已复位":"Stopwatch reset","秒表已经在计时":"The stopwatch is already running","秒表已经开始计时。":"The stopwatch has started.","秒表开始计时":"Stopwatch started","秒表时间":"Stopwatch time","秒表正在计时:":"Stopwatch running: ","秒表没有在计时":"The stopwatch isn't running","秒)":" s)","秒:演示模式没有模拟长按菜单":"s: the demo doesn't simulate long-press menus","空闲":"Idle","第":"Step","等「":"Waiting for “","等一段文字出现":"Wait for text","等你确认":"Needs you","等待 5 秒":"Wait 5 s","等待中…":"Waiting…","等待前一步":"waiting for the step before","筛选元素":"Filter elements","系统":"System","系统版本在「通用 › 关于本机」里,先点「通用」。":"The version is under General › About; tap “General” first.","纽约":"New York","结束":"Quit","结束「":"Quit “","继续":"Resume","继续执行":"Keep running","缩小画面":"Zoom out","缩小(也可以按住 Ctrl/⌘ 滚动滚轮)":"Zoom out (or Ctrl/⌘ + scroll)","自动解锁":"Auto-unlock","自动选择":"Automatic","蓝牙":"Bluetooth","计时器":"Timers","计次":"Lap","让 AI 操作你的 Apple 设备":"Let AI operate your Apple device","记":"N","记了第":"Recorded lap","设":"S","设备":"Device","设备实时画面:单击轻点,拖动或滚动滚轮滑动,按住长按":"Live device screen: click to tap, drag or scroll to swipe, hold to long-press","设备屏幕":"Device screen","设备按键和输入":"Device buttons and typing","设备的实时画面":"Live picture of the device","设备重启后还没解锁过,需要在设备上手动解锁一次。":"The device hasn't been unlocked since it restarted; unlock it by hand once.","设备重启后首次启用 UI 自动化,请在设备上输入锁屏密码。":"UI automation is starting for the first time since the restart; enter the passcode on the device.","设备面板":"Device panel","设置":"Settings","话":"P","请求失败(":"Request failed (","读一下列表里的闹钟。":"Read the alarms in the list.","读一下界面上带文字的元素。":"Read the elements with text on the screen.","读出「iOS 版本」这一行。":"Read the “iOS Version” row.","读取":"Read","调整 AI 助手栏宽度":"Resize the AI assistant column","调整设备面板宽度":"Resize the device panel","软件更新":"Software Update","轻点":"Tap","输入":"Type","输入并回车":"Type and press Return","输入文字":"Type text","输入框":"Text field","输入框是空的,没有发出任何内容":"The text field is empty, nothing was sent","输入框获得焦点,弹出了键盘":"The text field has focus and the keyboard is up","输入要发的内容。":"Type the message.","运行 <code>iphone-control sign</code>,用免费 Apple ID 签名并安装。":"Run <code>iphone-control sign</code> to sign and install it with a free Apple ID.","还不知道屏幕尺寸,稍后再试":"The screen size isn't known yet; try again shortly","还停在「":"Still on “","还在读取可用的 AI,稍等一下再试。":"Still reading the available AIs; try again in a moment.","还在连接服务,稍等一下再开始":"Still connecting to the service; start in a moment","还没有拿到守护进程状态。":"No daemon status yet.","这个位置在画面外面":"That point is outside the screen","这台机器上没有可用的 AI。安装并登录 Claude Code 或 Codex,再重新运行 iphone-control viewer。":"No AI is available on this machine. Install and log in to Claude Code or Codex, then run iphone-control viewer again.","这台机器的 PATH 里没有 claude 或 codex":"Neither claude nor codex is on this machine's PATH","这台设备的系统版本是 iOS 18.1。":"This device runs iOS 18.1.","这里没有可点的东西":"nothing to tap here","进入「":"Opened “","进行中":"in progress","连接中":"Connecting","适应":"Fit","通用":"General","通道":"Route","邮":"M","邮件":"Mail","重新执行":"Run again","重新执行:":"Run again: ","钱":"W","钱包":"Wallet","锁定屏幕":"Lock Screen","锁屏":"Lock","键盘":"Keyboard","长按":"Long press","闹钟":"Alarms","闹钟 ":"Alarm ","闹钟,":"Alarm, ","隐私与安全性":"Privacy & Security","隐藏设备面板":"Hide the device panel","需要你确认:":"Needs your confirmation: ","需要处理":"needs attention","音乐":"Music","音量减":"Volume down","音量减(演示画面没有变化)":"Volume down (no change on the demo screen)","音量加":"Volume up","音量加(演示画面没有变化)":"Volume up (no change on the demo screen)","页面刷新时这个任务还在执行,刷新后页面不再跟踪它的进度。":"This task was still running when the page reloaded, so the page no longer follows it.","(":" (","(未安装)":" (not installed)","(演示画面不加载网页)":" (the demo doesn't load web pages)","(演示)":" (demo)",")":")",",":", ",":":": ",":演示画面不支持滚动":": the demo screen doesn't scroll","看一下屏幕":"Look at the screen","读取屏幕上的内容":"Read what's on the screen","查看手机状态":"Check the phone's status","点击屏幕":"Tap the screen","点击":"Tap","长按屏幕":"Long-press the screen","滑动屏幕":"Swipe the screen","按主屏幕键":"Press Home","按键":"Press a button","打开 App":"Open","关闭":"Quit","等待":"Wait for","出现":"to appear","查看已安装的 App":"List installed apps","查看已连接的设备":"List connected devices","连续执行几步操作":"Run a few steps in a row","请你确认":"Ask you to confirm","操作手机":"Operate the phone","这一步没成功":"This step didn't work","另一台设备":"another device","设备已在别处切换到":"The device was switched elsewhere to",",画面已跟过去":"; the picture follows it","没有连上设备:用数据线连上 iPhone,确认数据线能传数据。":"No device connected: connect the iPhone with a cable that carries data.","还没设置好(配对、开发者模式)。在终端运行":"isn’t set up yet (pairing, Developer Mode). In a terminal, run",",选「手机」。":" and pick Phone.","上还没装 WebDriverAgent。":"doesn’t have WebDriverAgent yet.","正在签名安装…":"Signing and installing…","签名并安装 WDA":"Sign and install WDA","上还没装 WebDriverAgent,需要先登录 Apple ID:在终端运行":"doesn’t have WebDriverAgent yet, and an Apple ID is needed to sign it: in a terminal, run",",选「Apple ID」。":" and pick Apple ID.","正在":"Starting WebDriverAgent on","上启动 WebDriverAgent,通常 10–60 秒…":"— usually 10–60 seconds…","设备重启后还没解锁过,在设备上手动解锁一次,画面就会出来。":"The device hasn’t been unlocked since it restarted. Unlock it once by hand and the picture appears.","正在签名并安装 WebDriverAgent,大约 1–2 分钟,保持手机解锁…":"Signing and installing WebDriverAgent, about 1–2 minutes; keep the phone unlocked…","运行 <code>iphone-control setup --reconfigure</code> 选「手机」,在设备上点「信任」。":"Run <code>iphone-control setup --reconfigure</code>, pick Phone, and tap “Trust” on the device.",":WebDriverAgent 启动失败,会自动重试":": WebDriverAgent failed to start; retrying automatically","不可用":"Unavailable","正在挂开发者镜像、启动 WebDriverAgent,最长约 2 分钟。这台设备低于 iOS 27,没有 HID 后备,期间不能截图和操作。":"Mounting the developer disk image and starting WebDriverAgent, up to about 2 minutes. This device is below iOS 27, so there is no HID fallback: no screenshots or actions until then.","重新签名并安装 WDA":"Re-sign and install WDA","只清除任务和步骤记录,不会影响设备上已经做过的操作。清空后无法恢复。":"Only clears the tasks and steps on the left; nothing already done on the device changes. This can't be undone."};
+Object.assign(EN, {
+ '未连接设备':'No device connected', '用数据线连接 iPhone 或 iPad。':'Connect an iPhone or iPad with a USB cable.', '等待设备连接':'Waiting for a device',
+ '外观':'Appearance', '界面字号':'Text size', '标准':'Standard', '大':'Large', '特大':'Extra large',
+ '暂无任务':'No tasks yet', '执行步骤和确认请求会显示在这里。':'Steps and approval requests appear here.',
+ '可以先写下任务,连接设备后再执行。':'Draft a task while waiting for a device.',
+ '任务将在模拟设备上运行。':'Tasks run on the simulated device.', '开始任务(Enter)':'Start task (Enter)',
+ '明暗':'Theme', '跟随系统':'System', '浅色':'Light', '深色':'Dark', '完成':'Done'
+});
+Object.assign(EN, {
+ '设备列表':'Devices', '设备标识':'Device identifiers', '连接检查':'Connection checks',
+ '连接设备后可查看应用。':'Connect a device to view its apps.',
+ '连接设备后可查看界面元素。':'Connect a device to inspect its interface.'
+});
+Object.assign(EN, {
+ '设备画面':'Device view', '连接你的设备':'Connect your device', '连接帮助':'Connection help',
+ '用 USB 数据线连接 iPhone 或 iPad,并在设备上轻点「信任」。':'Connect your iPhone or iPad with a USB cable, then tap Trust on the device.',
+ '等待设备画面':'Waiting for the screen', '正在连接本地服务':'Connecting to the local service'
+});
+Object.assign(EN, {'版本详情':'Details','复制升级命令':'Copy upgrade command','关闭版本信息':'Close version information','关于与更新':'About & updates','完成':'Done','检查更新':'Check for updates','检查中…':'Checking…','发行说明':'Release notes','升级命令':'Upgrade command','复制命令':'Copy command','已复制':'Copied','请选中命令并手动复制。':'Select the command and copy it manually.'});
/* 中文原文 → 当前语言 */
+Object.assign(EN, { '画面已连接 · 等待屏幕尺寸和方向,仅可观看':'Picture connected · waiting for screen dimensions and orientation (view only)', '没有收到设备画面,3 秒后自动重试。':'No picture received. Retrying in 3 seconds.' });
+Object.assign(EN, {
+ '设置': 'Settings', '界面语言': 'Language', '没有可用的 AI': 'No AI available'
+});
function tr(zh) { return LANG === 'en' ? (EN[zh] ?? zh) : zh; }
/* 静态标记里的文字和提示(aria-label、title、placeholder、alt)开始时译一次 */
(function translateStatic() {
@@ -904,9 +1097,13 @@ function tr(zh) { return LANG === 'en' ? (EN[zh] ?? zh) : zh; }
for (const a of ['aria-label', 'title', 'placeholder', 'alt']) { const v = el.getAttribute(a); if (v && EN[v] !== undefined) el.setAttribute(a, EN[v]); }
});
})();
-document.getElementById('lang-btn').textContent = LANG === 'en' ? '中文' : 'EN';
-document.getElementById('lang-btn').addEventListener('click', () => {
- try { localStorage.setItem('ictl.lang', LANG === 'en' ? 'zh' : 'en'); } catch { /* 存不了就只换这一次 */ }
+const language = document.getElementById('language-value');
+language.value = LANG;
+language.addEventListener('change', () => {
+ try {
+ localStorage.setItem('ictl.lang', language.value);
+ sessionStorage.setItem('ictl.languageDraft', document.getElementById('prompt').value);
+ } catch { /* Storage can be unavailable in a local preview. */ }
location.reload();
});
/* ================================================================
@@ -955,6 +1152,10 @@ const fmtSw = ms => { const cs = Math.floor(ms / 10); return `${pad(Math.floor(c
/* ---------- 图标:一套 24 网格描边图标 ---------- */
const ICONS = {
+ control: '<rect x="5" y="2.5" width="12" height="19" rx="3"/><path d="m13.5 11 7.7 3.5-3.4 1.3-1.2 3.3z" fill="currentColor" stroke="#252a30" stroke-width="1"/>',
+ settings: '<path d="m9.6 3-.5 2.1-1.5.9-2.1-.6-2.2 3.8 1.6 1.5v2.6l-1.6 1.5 2.2 3.8 2.1-.6 1.5.9.5 2.1h4.8l.5-2.1 1.5-.9 2.1.6 2.2-3.8-1.6-1.5v-2.6l1.6-1.5-2.2-3.8-2.1.6-1.5-.9-.5-2.1Z"/><circle cx="12" cy="12" r="3"/>',
+ chat: '<path d="M20.5 13.5a3 3 0 0 1-3 3H10l-4.5 4V16a3 3 0 0 1-2-2.8V6.5a3 3 0 0 1 3-3h11a3 3 0 0 1 3 3z"/><path d="M8 8h8m-8 4h5"/>',
+ display: '<rect x="3" y="4.5" width="18" height="13" rx="2.4"/><path d="M8 20.5h8m-4-3v3"/>',
home: '<path d="M3.5 10.5 12 3.5l8.5 7V20a1 1 0 0 1-1 1H15v-6H9v6H4.5a1 1 0 0 1-1-1z"/>',
lock: '<rect x="5" y="11" width="14" height="10" rx="2"/><path d="M8 11V7.5a4 4 0 0 1 8 0V11"/>',
voldown: '<path d="M11 5 6.5 9H3v6h3.5L11 19z"/><path d="M15.5 12h5"/>',
@@ -986,6 +1187,7 @@ const ICONS = {
search: '<circle cx="11" cy="11" r="6.5"/><path d="m16 16 4 4"/>',
zoomin: '<circle cx="11" cy="11" r="6.5"/><path d="m16 16 4 4M8.5 11h5M11 8.5v5"/>',
zoomout: '<circle cx="11" cy="11" r="6.5"/><path d="m16 16 4 4M8.5 11h5"/>',
+ conversation: '<path d="M6 4.5h12a2.5 2.5 0 0 1 2.5 2.5v8a2.5 2.5 0 0 1-2.5 2.5h-7l-5 3v-3A2.5 2.5 0 0 1 3.5 15V7A2.5 2.5 0 0 1 6 4.5Z"/><path d="M8 9h8M8 12.5h5"/>',
bot: '<rect x="4.5" y="7.5" width="15" height="11" rx="3"/><path d="M12 3.5v4M9.5 12.5v1.5M14.5 12.5v1.5"/>'
};
function icon(name, extra = '') {
@@ -993,6 +1195,109 @@ function icon(name, extra = '') {
}
function hydrateIcons(root = document) { $$('[data-icon]', root).forEach(el => { el.innerHTML = icon(el.dataset.icon); }); }
+// All five controls share the same popover. Each select supplies its current
+// options, value and disabled state and still emits the usual change event.
+function positionPopover(button, popup, preferAbove = false) {
+ if (!popup.matches(':popover-open')) return;
+ const rect = button.getBoundingClientRect();
+ const above = rect.top - 14, below = innerHeight - rect.bottom - 14;
+ const height = popup.scrollHeight + popup.offsetHeight - popup.clientHeight;
+ const openAbove = preferAbove ? above >= height || above >= below : below < height && above > below;
+ popup.style.maxHeight = Math.max(0, openAbove ? above : below) + 'px';
+ popup.style.top = (openAbove ? rect.top - 6 - popup.offsetHeight : rect.bottom + 6) + 'px';
+ popup.style.left = Math.max(8, Math.min(rect.right - popup.offsetWidth, innerWidth - popup.offsetWidth - 8)) + 'px';
+}
+function bindPicker(select) {
+ const id = select.dataset.picker;
+ select.insertAdjacentHTML('afterend', `
+ <button type="button" class="picker-trigger" id="${id}" popovertarget="${id}-options" aria-haspopup="listbox" aria-controls="${id}-options" aria-expanded="false" aria-labelledby="${id}-label ${id}-name">
+ <span class="od-truncate" id="${id}-name"></span><span class="ic">${icon('chevron')}</span>
+ </button>
+ <div id="${id}-options" class="picker-menu glass" role="listbox" aria-labelledby="${id}-label" popover="auto" tabindex="-1" autofocus></div>`);
+ const button = document.getElementById(id), menu = document.getElementById(id + '-options');
+ const name = document.getElementById(id + '-name');
+ const position = () => positionPopover(button, menu, select.hasAttribute('data-open-above'));
+ const active = () => menu.querySelector('[data-active]');
+ let optionRows = '', prefix = '', lastKey = 0;
+
+ function highlight(row) {
+ if (!row || row.hasAttribute('data-active') || row.getAttribute('aria-disabled') === 'true') return;
+ active()?.removeAttribute('data-active');
+ row.setAttribute('data-active', '');
+ menu.setAttribute('aria-activedescendant', row.id);
+ }
+ function renderOptions(opening) {
+ const rows = Array.from(select.options, (o, i) =>
+ `<div class="picker-option" role="option" id="${id}-opt-${i}" data-value="${esc(o.value)}" aria-selected="${o.selected}" aria-disabled="${o.disabled}"><span${o.lang ? ` lang="${esc(o.lang)}"` : ''}>${esc(o.label)}</span>${icon('check')}</div>`
+ ).join('');
+ if (!opening && rows === optionRows) return;
+ // A device poll may reorder, rename or remove rows while keyboard navigation is in progress.
+ const previous = opening ? null : active()?.dataset.value;
+ optionRows = rows;
+ menu.innerHTML = rows;
+ menu.removeAttribute('aria-activedescendant');
+ const enabled = $$('[aria-disabled="false"]', menu);
+ highlight(enabled.find(row => row.dataset.value === previous) || enabled.find(row => row.getAttribute('aria-selected') === 'true') || enabled[0]);
+ requestAnimationFrame(() => { position(); active()?.scrollIntoView({ block: 'nearest' }); });
+ }
+ function sync() {
+ const label = select.selectedOptions[0]?.label || '';
+ if (label !== name.textContent) name.textContent = label;
+ button.disabled = select.disabled;
+ button.title = select.title;
+ if (menu.matches(':popover-open')) {
+ if (button.disabled || !button.getClientRects().length) menu.hidePopover();
+ else renderOptions(false);
+ }
+ }
+ function choose(row) {
+ if (!row || button.disabled || row.getAttribute('aria-disabled') === 'true') return;
+ const changed = select.value !== row.dataset.value;
+ select.value = row.dataset.value;
+ menu.hidePopover();
+ button.focus();
+ sync();
+ if (changed) select.dispatchEvent(new Event('change', { bubbles: true }));
+ }
+ menu.addEventListener('beforetoggle', ev => {
+ const opening = ev.newState === 'open';
+ button.setAttribute('aria-expanded', String(opening));
+ if (opening) { prefix = ''; renderOptions(true); }
+ });
+ menu.addEventListener('pointermove', ev => highlight(ev.target.closest('[role="option"]')));
+ menu.addEventListener('click', ev => choose(ev.target.closest('[role="option"]')));
+ button.addEventListener('keydown', ev => {
+ if (ev.key === 'ArrowDown' || ev.key === 'ArrowUp') { ev.preventDefault(); menu.showPopover(); }
+ });
+ menu.addEventListener('keydown', ev => {
+ const enabled = $$('[role="option"][aria-disabled="false"]', menu);
+ const index = enabled.indexOf(active());
+ let next;
+ switch (ev.key) {
+ case 'ArrowDown': next = enabled[Math.min(index + 1, enabled.length - 1)]; break;
+ case 'ArrowUp': next = enabled[Math.max(0, index - 1)]; break;
+ case 'Home': next = enabled[0]; break;
+ case 'End': next = enabled.at(-1); break;
+ case 'Enter': case ' ': ev.preventDefault(); choose(active()); return;
+ case 'Tab': menu.hidePopover(); button.focus(); return;
+ case 'Escape': ev.preventDefault(); ev.stopPropagation(); menu.hidePopover(); button.focus(); return;
+ default:
+ if (ev.key.length !== 1 || ev.ctrlKey || ev.metaKey || ev.altKey || ev.isComposing) return;
+ prefix = (ev.timeStamp - lastKey < 600 ? prefix : '') + ev.key.toLowerCase();
+ lastKey = ev.timeStamp;
+ next = enabled.find(row => row.textContent.toLowerCase().startsWith(prefix));
+ }
+ ev.preventDefault();
+ highlight(next);
+ next?.scrollIntoView({ block: 'nearest' });
+ });
+ new ResizeObserver(position).observe(button.closest('dialog, .pane') || button);
+ window.addEventListener('resize', position);
+ sync();
+ return sync;
+}
+const pickerSync = Object.fromEntries($$('select[data-picker]').map(select => [select.dataset.picker, bindPicker(select)]));
+
const TASK_STATUS = {
idle: { label: tr('空闲'), tone: 'muted', icon: 'dot' },
running: { label: tr('执行中'), tone: 'accent', icon: 'loader' },
@@ -1015,19 +1320,22 @@ const ACTIVE = ['running', 'paused', 'takeover', 'waiting'];
const badge = st => `<span class="badge tone-${st.tone}">${icon(st.icon, st.icon === 'loader' ? 'spin' : '')}<span>${esc(st.label)}</span></span>`;
/* ---------- 元素与状态 ---------- */
-const shell = $('#shell'), stage = $('#stage'), frame = $('#frame'), live = $('#live'), demoEl = $('#demo'), marks = $('#marks'), stageMsg = $('#stage-msg');
+const shell = $('#shell'), stage = $('#stage'), frame = $('#frame'), demoEl = $('#demo'), marks = $('#marks'), stageMsg = $('#stage-msg');
const statusEl = $('#status'), promptEl = $('#prompt'), promptErr = $('#prompt-error'), typeEl = $('#type-text');
-const turnsEl = $('#turns'), stopDialog = $('#stop-dialog'), deviceEl = $('#device');
+const turnsEl = $('#turns'), stopDialog = $('#stop-dialog'), deviceEl = $('#device-value');
/* 实时画面:H.264 画在 canvas 上(见「H.264 画面」),否则是 MJPEG 的 img */
const cv = $('#live-v'), cvx = cv.getContext('2d');
-const V = { on: false, off: false, noDevice: false, device: false, crop: false, rot: 0, codecName: '', ctrl: null, dec: null, got: false, label: '', ts: 0, bytes: 0, rate: null, stream: '', recv: 0, acked: 0, acking: false };
+const V = { on: false, off: false, noDevice: false, device: false, crop: false, rot: null, frameRotation: null, codecName: '', ctrl: null, dec: null, got: false, label: '', ts: 0, bytes: 0, rate: null, stream: '', recv: 0, acked: 0, acking: false };
const picEl = () => V.on ? cv : live;
const picW = () => V.on ? cv.width : live.naturalWidth;
const picH = () => V.on ? cv.height : live.naturalHeight;
+let live = $('#live');
+let feedId = '', feedEpoch = 0, retryTimer = 0, infoSequence = 0;
+let frameWidth = 0, frameHeight = 0;
const S = {
mode: 'detecting', // detecting | live | demo
- size: null, stream: 'connecting', rtt: null,
+ display: null, size: null, video: null, deviceVideo: false, family: 'unknown', stream: 'connecting', rtt: null,
view: 'agent', devOpen: false, devTab: 'status',
daemon: null, dstatus: null, statusErr: '',
devices: [], devicesErr: '',
@@ -1084,13 +1392,21 @@ const SETTINGS = {
about: { title: tr('关于本机'), back: [tr('通用'), 'set:general'], groups: [[[tr('名称'), 'iPhone', null], [tr('iOS 版本'), '18.1', null], [tr('型号名称'), 'iPhone 15 Pro', null], [tr('容量'), '256 GB', null]]] }
};
const DEMO_DEVICES = [
- { udid: '00008130-001A2B3C4D5E001E', name: 'iPhone 15 Pro', model: 'iPhone16,1', ios: '18.1', kind: 'iphone', w: 393, h: 852 },
- { udid: '00008112-000C1D2E3F4A5B6C', name: tr('iPad mini(第 6 代)'), model: 'iPad14,1', ios: '18.1', kind: 'ipad', w: 1133, h: 744 } // iPad 默认横屏
+ { udid: '00008130-001A2B3C4D5E001E', name: 'iPhone 15 Pro', model: 'iPhone16,1', model_name: 'iPhone 15 Pro', family: 'iphone', ios: '18.1', kind: 'iphone', w: 393, h: 852 },
+ { udid: '00008112-000C1D2E3F4A5B6C', name: tr('iPad mini(第 6 代)'), model: 'iPad14,1', model_name: tr('iPad mini(第 6 代)'), family: 'ipad', ios: '18.1', kind: 'ipad', w: 1133, h: 744 } // iPad 默认横屏
];
let demoDev = DEMO_DEVICES[0];
const DW = () => demoDev.w, DH = () => demoDev.h;
-const isPad = dev => dev && (dev.kind === 'ipad' || /^iPad/.test(dev.model || ''));
-const osName = dev => isPad(dev) ? 'iPadOS' : 'iOS';
+function osVersion(device) {
+ const family = device.family ?? (/^iPad[0-9]+,[0-9]+$/.test(device.model) ? 'ipad' : /^iPhone[0-9]+,[0-9]+$/.test(device.model) ? 'iphone' : 'unknown');
+ const system = family === 'ipad' ? 'iPadOS' : family === 'iphone' ? 'iOS' : '';
+ return device.ios ? [system, device.ios].filter(Boolean).join(' ') : '';
+}
+function deviceOptionLabel(device) {
+ const model = device.model_name || device.model;
+ if (device.name && model && device.name !== model) return device.name + ' · ' + model;
+ return device.name || model || device.udid;
+}
const D = {
screen: 'home', clockTab: 'world', setPage: 'root', generic: '', genericSub: '',
@@ -1230,14 +1546,17 @@ function demoElements() {
* ================================================================ */
function dims() {
if (S.mode === 'demo') return { W: DW(), H: DH() };
- if (!S.size) return null;
- const land = picW() > picH();
- return land ? { W: S.size.h, H: S.size.w } : { W: S.size.w, H: S.size.h };
+ if (!S.display?.id || S.switching || S.stream !== 'ok' || !picH()) return null;
+ const { width, height, rotation } = S.display;
+ if (!(width > 0 && height > 0) || ![0, 90, 180, 270].includes(rotation)) return null;
+ if (V.device && V.frameRotation !== rotation) return null;
+ const land = rotation === 90 || rotation === 270;
+ const W = land ? height : width, H = land ? width : height;
+ return Math.abs(picW() / picH() / (W / H) - 1) <= 0.01 ? { W, H } : null;
}
function setRatio(w, h) {
stage.style.aspectRatio = `${w} / ${h}`; frame.style.setProperty('--ratio', String(w / h));
- // 短边/长边 > 0.6 是 iPad(约 0.66–0.77),iPhone 约 0.46;横竖屏都适用
- frame.dataset.kind = Math.min(w, h) / Math.max(w, h) > 0.6 ? 'ipad' : 'iphone';
+ frame.dataset.kind = S.mode === 'demo' ? demoDev.kind : S.family;
applyZoom();
}
function applyDemoGeometry() {
@@ -1246,17 +1565,19 @@ function applyDemoGeometry() {
requestAnimationFrame(() => demoEl.style.setProperty('--k', String(stage.clientWidth / DW())));
}
function syncMarksBox() { const d = dims(); if (d) marks.setAttribute('viewBox', `0 0 ${d.W} ${d.H}`); }
-function toPoints(cx, cy) {
- const d = dims(); if (!d) return null;
+function pictureRect() {
const r = stage.getBoundingClientRect();
- let w = r.width, h = r.height, ox = 0, oy = 0;
- if (S.mode === 'live' && picW()) {
- const sc = Math.min(r.width / picW(), r.height / picH());
- w = picW() * sc; h = picH() * sc; ox = (r.width - w) / 2; oy = (r.height - h) / 2;
- }
- const fx = (cx - r.left - ox) / w, fy = (cy - r.top - oy) / h;
- if (fx < 0 || fx > 1 || fy < 0 || fy > 1) return null;
- return { x: round1(fx * d.W), y: round1(fy * d.H) };
+ if (S.mode !== 'live') return r;
+ const k = Math.min(r.width / picW(), r.height / picH());
+ const width = k * picW(), height = k * picH();
+ return { left: r.left + (r.width - width) / 2, top: r.top + (r.height - height) / 2, width, height };
+}
+function toPoints(cx, cy, clamp = false) {
+ const d = dims(); if (!d) return null;
+ const r = pictureRect(); if (!r.width || !r.height) return null;
+ const x = (cx - r.left) / r.width, y = (cy - r.top) / r.height;
+ if (!clamp && (x < 0 || x > 1 || y < 0 || y > 1)) return null;
+ return { x: round1(Math.min(1, Math.max(0, x)) * d.W), y: round1(Math.min(1, Math.max(0, y)) * d.H) };
}
new ResizeObserver(() => { demoEl.style.setProperty('--k', String(stage.clientWidth / DW())); }).observe(stage);
@@ -1285,7 +1606,7 @@ function drawMark(kind, who, p, p2) {
let hlRect = null;
function highlight(el) {
hlRect?.remove(); hlRect = null;
- if (!el || !el.width) return;
+ if (!el || !el.width || !dims()) return;
hlRect = svgEl('rect', { x: el.x, y: el.y, width: el.width, height: el.height, rx: 6, class: 'mk-hl' });
marks.append(hlRect);
}
@@ -1293,11 +1614,11 @@ function highlight(el) {
/* ================================================================
* 请求
* ================================================================ */
-async function api(path, body) {
+async function api(path, body, device = S.udid) {
const opt = body === undefined ? {} : { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body) };
opt.headers = { ...(opt.headers || {}), 'X-Ictl-Lang': LANG };
// 操作只发给本页显示的那台;守护进程已换到别的设备时会被拒绝,不会点到用户没在看的手机上
- if (S.udid && !path.startsWith('/api/updates')) opt.headers['X-Ictl-Device'] = S.udid;
+ if (device && !path.startsWith('/api/updates')) opt.headers['X-Ictl-Device'] = device;
const r = await fetch(path, opt);
if (!r.ok) {
let msg = '';
@@ -1308,9 +1629,11 @@ async function api(path, body) {
return r.json();
}
async function act(path, body, quiet) {
- const t0 = performance.now();
+ if (S.mode === 'live' && path !== '/api/select' && (S.switching || !S.udid)) return { ok: false };
+ const t0 = performance.now(), epoch = feedEpoch;
try {
const v = await api(path, body);
+ if (epoch !== feedEpoch) return v;
S.rtt = Math.round(performance.now() - t0); renderFeed();
// 画面上的手势、底栏的按键和输入:成功时不弹提示,画面本身就是结果;失败照样提示
if (!quiet || !v.ok) show(v.message || (v.ok ? tr('完成') : tr('失败')), v.ok ? null : 'err');
@@ -1332,33 +1655,19 @@ function nudgeGuard() {
show(t && t.status === 'waiting' ? tr('AI 在等你确认一步操作,确认前画面保持锁定。') : tr('AI 正在操作这台设备。要自己操作,先点「接管」。'), 'warn');
}
/* 画面外的点夹到屏幕边上(拖动时手指不会离开屏幕) */
-function clampPoint(cx, cy) {
- const d = dims(); if (!d) return null;
- const r = stage.getBoundingClientRect();
- let w = r.width, h = r.height, ox = 0, oy = 0;
- if (S.mode === 'live' && picW()) {
- const sc = Math.min(r.width / picW(), r.height / picH());
- w = picW() * sc; h = picH() * sc; ox = (r.width - w) / 2; oy = (r.height - h) / 2;
- }
- const fx = Math.min(1, Math.max(0, (cx - r.left - ox) / w)), fy = Math.min(1, Math.max(0, (cy - r.top - oy) / h));
- return { x: round1(fx * d.W), y: round1(fy * d.H) };
-}
-/* 页面上一个 CSS 像素对应设备上多少点 */
function pointsPerPx() {
- const d = dims(), r = stage.getBoundingClientRect();
- if (!d || !r.width) return 1;
- if (S.mode === 'live' && picW()) return d.W / (picW() * Math.min(r.width / picW(), r.height / picH()));
- return d.W / r.width;
+ const d = dims();
+ return d ? d.W / pictureRect().width : 1;
}
/* ---------- 实时手指(iOS 27 起,经 CoreDevice HID):按下、移动、抬起各发一次,设备跟着鼠标动 ----------
* 一次只有一个请求在路上:还没发出去的移动只留最新的一个,按下、抬起一定按顺序发。
* 按住不动时每 100 毫秒再报一次当前位置,长按、拖动中途停顿都和真手指一样。 */
-const T = { q: [], busy: false, on: false, last: null, keep: 0, warm: 0, fails: 0, legacy: false };
+const T = { q: [], busy: false, on: false, last: null, keep: 0, warm: 0, fails: 0, gesture: 0 };
function touchSend(phase, p) {
const tail = T.q[T.q.length - 1];
- if (phase === 'move' && tail && tail.phase === 'move') tail.p = p;
- else T.q.push({ phase, p });
+ if (phase === 'move' && tail?.phase === 'move' && tail.gesture === T.gesture) tail.p = p;
+ else T.q.push({ phase, p, gesture: T.gesture, view: S.display?.id, device: S.udid, epoch: feedEpoch });
touchPump();
}
async function touchPump() {
@@ -1367,27 +1676,46 @@ async function touchPump() {
while (T.q.length) {
const e = T.q.shift(), t0 = performance.now();
let v;
- try { v = await api('/api/touch', { phase: e.phase, x: e.p ? e.p.x : 0, y: e.p ? e.p.y : 0 }); }
+ try { v = await api('/api/touch', { phase: e.phase, x: e.p ? e.p.x : 0, y: e.p ? e.p.y : 0, view: e.view }, e.device); }
catch (err) { v = { ok: false, message: String(err.message || err) }; }
+ if (!v.ok && e.phase === 'down') {
+ // Don't send moves from a failed press. Keep its release in case the reply was lost.
+ T.q = T.q.filter(next => next.gesture !== e.gesture || next.phase !== 'move');
+ }
+ if (e.epoch !== feedEpoch || e.gesture !== T.gesture) continue;
if (e.phase === 'down' || e.phase === 'up') { S.rtt = Math.round(performance.now() - t0); renderFeed(); }
- if (v.ok) { if (e.phase !== 'prepare') T.fails = 0; if (e.phase === 'up') refreshStatusSoon(); continue; }
+ if (v.ok) { if (e.phase === 'down') T.fails = 0; if (e.phase === 'up') refreshStatusSoon(); continue; }
if (e.phase === 'prepare') continue;
show(v.message || tr('操作失败'), 'err');
if (e.phase === 'down') {
- // 这一下没按下去:丢掉它后面的移动和抬起,松开时改用整段手势
- while (T.q.length && T.q[0].phase !== 'down') T.q.shift();
- if (down) down.legacy = true;
- // 连着两次按不下去(HID 不可用),本页之后都用整段手势
+ fingerUp(T.last);
+ if (v.retry_as_gesture !== true) {
+ if (down?.gesture === e.gesture) { down = null; hideHoverDot(); }
+ if (W.on && W.gesture === e.gesture) {
+ W.on = false; W.pend = { x: 0, y: 0 };
+ clearTimeout(W.idle); cancelAnimationFrame(W.raf);
+ }
+ loadInfo();
+ continue;
+ }
+ if (down?.gesture === e.gesture) down.legacy = true;
+ // 同一画面连续两次在按下前无法建立 HID 会话,后续改用整段手势。
if (++T.fails >= 2) { S.liveTouch = false; renderFeed(); }
}
}
T.busy = false;
}
function touchWarm() {
- if (!S.liveTouch || S.mode !== 'live' || guarded() || Date.now() - T.warm < 20000) return;
+ if (!S.liveTouch || S.mode !== 'live' || !dims() || guarded() || Date.now() - T.warm < 20000) return;
T.warm = Date.now(); touchSend('prepare', null);
}
-function fingerDown(p) { T.on = true; T.last = p; touchSend('down', p); clearInterval(T.keep); T.keep = setInterval(() => { if (T.on && T.last) touchSend('move', T.last); }, 100); }
+function fingerDown(p) {
+ ++T.gesture; T.on = true; T.last = p;
+ touchSend('down', p);
+ clearInterval(T.keep);
+ T.keep = setInterval(() => { if (T.on && T.last) touchSend('move', T.last); }, 100);
+ return T.gesture;
+}
function fingerMove(p) { if (!T.on) return; T.last = p; touchSend('move', p); }
function fingerUp(p) { if (!T.on) return; T.on = false; clearInterval(T.keep); touchSend('up', p || T.last); T.last = null; }
stage.addEventListener('pointerenter', touchWarm);
@@ -1396,11 +1724,12 @@ stage.addEventListener('pointerdown', ev => {
if (ev.button !== 0 || S.mode === 'detecting' || ev.target.closest('button, a, code')) return;
if (guarded()) { nudgeGuard(); return; }
const p = toPoints(ev.clientX, ev.clientY);
+ if (!p || down) return;
stage.setPointerCapture(ev.pointerId);
wheelEnd(true);
const liveFinger = S.mode === 'live' && S.liveTouch && !!p;
- down = { p, t: performance.now(), cx: ev.clientX, cy: ev.clientY, live: liveFinger, legacy: false };
- if (liveFinger) fingerDown(p);
+ down = { p, pointerId: ev.pointerId, t: performance.now(), cx: ev.clientX, cy: ev.clientY, live: liveFinger, legacy: false };
+ if (liveFinger) down.gesture = fingerDown(p);
});
/* 鼠标悬停时跟随光标的小圆点,标出将要点到的位置;触屏、画面外、AI 操作时不显示 */
let hoverDot = null;
@@ -1420,15 +1749,20 @@ function moveHoverDot(p, ev) {
function hideHoverDot() { hoverDot?.setAttribute('hidden', ''); }
stage.addEventListener('pointerleave', hideHoverDot);
stage.addEventListener('pointermove', ev => {
+ if (down && ev.pointerId !== down.pointerId) return;
const p = toPoints(ev.clientX, ev.clientY);
moveHoverDot(p, ev);
- if (down && down.live && !down.legacy) fingerMove(p || clampPoint(ev.clientX, ev.clientY));
+ if (down && down.live && !down.legacy) {
+ const pos = p || toPoints(ev.clientX, ev.clientY, true);
+ if (pos) fingerMove(pos); else cancelGestures();
+ }
});
function endPointer(ev, cancelled) {
- if (!down) return;
+ if (!down || ev.pointerId !== down.pointerId) return;
const start = down; down = null;
+ if (!dims()) { cancelGestures(); return; }
hoverDot?.classList.remove('pressed');
- if (start.live && !start.legacy) { fingerUp(clampPoint(ev.clientX, ev.clientY)); return; }
+ if (start.live && !start.legacy) { fingerUp(toPoints(ev.clientX, ev.clientY, true)); return; }
if (cancelled) return;
const end = toPoints(ev.clientX, ev.clientY), held = (performance.now() - start.t) / 1000;
if (!start.p) { show(dims() ? tr('这个位置在画面外面') : tr('还不知道屏幕尺寸,稍后再试'), 'err'); return; }
@@ -1447,7 +1781,7 @@ const W = { on: false, start: null, cur: null, pend: { x: 0, y: 0 }, idle: 0, ra
const EDGE = 90;
function wheelSafe(p) { const d = dims(); return { x: Math.min(d.W - 30, Math.max(30, p.x)), y: Math.min(d.H - EDGE, Math.max(EDGE, p.y)) }; }
stage.addEventListener('wheel', ev => {
- if (S.mode !== 'live' || ev.ctrlKey || down) return;
+ if (S.mode !== 'live' || ev.ctrlKey || ev.metaKey || down) return;
const p = toPoints(ev.clientX, ev.clientY);
if (!p) return;
ev.preventDefault();
@@ -1456,13 +1790,13 @@ stage.addEventListener('wheel', ev => {
W.pend.x += ev.deltaX * k * pointsPerPx(); W.pend.y += ev.deltaY * k * pointsPerPx();
if (!W.on) {
W.on = true; W.start = wheelSafe(p); W.cur = { ...W.start };
- if (S.liveTouch) { fingerDown(W.cur); W.raf = requestAnimationFrame(wheelStep); }
+ if (S.liveTouch) { W.gesture = fingerDown(W.cur); W.raf = requestAnimationFrame(wheelStep); }
}
clearTimeout(W.idle); W.idle = setTimeout(() => wheelEnd(false), 160);
}, { passive: false });
function wheelStep() {
if (!W.on) return;
- const d = dims();
+ const d = dims(); if (!d) { cancelGestures(); return; }
// 一格滚轮分几帧走完,像手指拖过去
const step = a => (Math.abs(a) < 1 ? a : a * 0.45);
const sx = step(W.pend.x), sy = step(W.pend.y);
@@ -1470,13 +1804,14 @@ function wheelStep() {
if (sx || sy) {
const next = { x: round1(W.cur.x - sx), y: round1(W.cur.y - sy) };
if (next.x < 20 || next.x > d.W - 20 || next.y < 40 || next.y > d.H - 40) {
- fingerUp(W.cur); W.cur = { ...W.start }; fingerDown(W.cur);
+ fingerUp(W.cur); W.cur = { ...W.start }; W.gesture = fingerDown(W.cur);
} else { W.cur = next; fingerMove(W.cur); }
}
W.raf = requestAnimationFrame(wheelStep);
}
function wheelEnd(now) {
if (!W.on) return;
+ if (!dims()) { cancelGestures(); return; }
// 边移动边滑动时等手指把剩下的滚动量走完;整段手势(iOS 27 以下)没人消耗它,等下去就永远发不出滑动
if (!now && S.liveTouch && (Math.abs(W.pend.x) > 1 || Math.abs(W.pend.y) > 1)) { W.idle = setTimeout(() => wheelEnd(false), 60); return; }
clearTimeout(W.idle); cancelAnimationFrame(W.raf); W.on = false;
@@ -1487,7 +1822,7 @@ function wheelEnd(now) {
const dx = Math.max(-max, Math.min(max, W.pend.x)), dy = Math.max(-max, Math.min(max, W.pend.y));
if (Math.abs(dx) > 4 || Math.abs(dy) > 4) {
const a = W.start, b = { x: round1(Math.min(d.W - 10, Math.max(10, a.x - dx))), y: round1(Math.min(d.H - 10, Math.max(10, a.y - dy))) };
- act('/api/swipe', { x1: a.x, y1: a.y, x2: b.x, y2: b.y, seconds: 0.3 }, true);
+ act('/api/swipe', { view: S.display.id, x1: a.x, y1: a.y, x2: b.x, y2: b.y, seconds: 0.3 }, true);
}
}
W.pend = { x: 0, y: 0 };
@@ -1496,9 +1831,9 @@ function wheelEnd(now) {
/* 整段手势(没有实时手指时):松开后一次发出 */
function userGesture(kind, p, p2, held, cx, cy) {
if (S.mode === 'live') {
- if (kind === 'tap') act('/api/tap', p, true);
- else if (kind === 'long_press') act('/api/long_press', { ...p, seconds: round1(held) }, true);
- else act('/api/swipe', { x1: p.x, y1: p.y, x2: p2.x, y2: p2.y, seconds: Math.max(round1(held), 0.1) }, true);
+ if (kind === 'tap') act('/api/tap', { ...p, view: S.display.id }, true);
+ else if (kind === 'long_press') act('/api/long_press', { ...p, view: S.display.id, seconds: round1(held) }, true);
+ else act('/api/swipe', { view: S.display.id, x1: p.x, y1: p.y, x2: p2.x, y2: p2.y, seconds: Math.max(round1(held), 0.1) }, true);
return;
}
const at = `(${p.x}, ${p.y})`;
@@ -1532,34 +1867,43 @@ typeEl.addEventListener('keydown', ev => { if (ev.key === 'Enter' && !ev.isCompo
/* ================================================================
* 实时画面
* ================================================================ */
+function cancelGestures() {
+ down = null; W.on = false; W.pend = { x:0, y:0 };
+ clearTimeout(W.idle); cancelAnimationFrame(W.raf);
+ T.q = T.q.filter(e => e.phase === 'up');
+ fingerUp(T.last);
+ hideHoverDot();
+}
function applyInfo(v) {
- S.size = v.width && v.height ? { w: v.width, h: v.height } : null;
- S.video = v.video || null;
- S.deviceVideo = !!v.device_video;
- if (v.device) S.deviceName = v.device;
- if (v.udid && S.udid && v.udid.toLowerCase() !== S.udid.toLowerCase()) { onDeviceChanged(v); return; }
- if (v.udid) S.udid = v.udid;
- // 一旦改用整段手势(连着按不下去),本页之后不再改回来
- if (S.liveTouch !== false) S.liveTouch = !!v.live_touch;
- if (v.warning) show(v.warning, 'err');
-}
-/* 守护进程控制的设备变了(本页、别的页面、命令行切换,或拔掉后自动换了一台):画面和各面板都换过去 */
-function onDeviceChanged(v) {
- // 新设备可能支持手机自己的视频(iOS 27),重新试
- V.noDevice = false;
- const mine = S.switching;
- S.udid = v.udid;
- // 上一台设备上按着的手指、没走完的滚动,都不能带到新设备上
- W.on && (clearTimeout(W.idle), cancelAnimationFrame(W.raf), W.on = false);
- T.q.length = 0; T.on = false; T.last = null; clearInterval(T.keep); T.warm = 0; T.fails = 0; down = null;
- S.liveTouch = !!v.live_touch;
- S.dstatus = null; S.rtt = null;
- S.apps = []; S.appsState = 'idle'; S.elements = []; S.elState = 'idle'; appNames.map = null;
- highlight(null);
- connect(); loadDeviceState();
- if (S.devTab === 'apps') loadApps(); else if (S.devTab === 'elements') renderElements();
- const name = v.device || tr('另一台设备');
- show(mine ? `${tr('已切换到')} ${name}` : `${tr('设备已在别处切换到')} ${name}${tr(',画面已跟过去')}`);
+ const udid = v.udid || null;
+ S.video = v.video || null; S.deviceVideo = !!v.device_video;
+ S.size = v.width > 0 && v.height > 0 ? { w: v.width, h: v.height } : null;
+ frame.toggleAttribute('data-absent', v.state === 'Absent' && !udid);
+ const changed = S.udid !== udid, display = v.display || null;
+ if (changed || S.display?.id !== display?.id) {
+ cancelGestures(); // queue a release for the original device and view
+ T.fails = 0;
+ S.rtt = null; S.elements = []; S.elState = 'idle';
+ highlight(null); marks.replaceChildren(); hoverDot = null;
+ if (changed) {
+ S.daemon = null; S.dstatus = null; S.apps = []; S.appsState = 'idle'; appNames.map = null; appNames.loading = false;
+ T.warm = 0; V.noDevice = false;
+ }
+ }
+ const reconnect = feedId && (changed || S.display?.id !== display?.id);
+ S.udid = udid; S.display = display;
+ if (changed) { renderManual(); syncSend(); }
+ S.family = v.family || 'unknown'; frame.dataset.kind = S.family; S.deviceName = v.device || '';
+ S.liveTouch = T.fails < 2 && !!v.live_touch;
+ if (reconnect) {
+ connect();
+ loadDeviceState();
+ if (changed && S.devTab === 'apps') loadApps();
+ } else if (v.feed_open === false && S.stream === 'ok') {
+ feedError();
+ }
+ if (v.warning && !S.infoWarning) show(v.warning, 'err');
+ S.infoWarning = v.warning || '';
}
function signButton(label) {
return `<button type="button" data-action="sign"${S.signing ? ' disabled' : ''} class="btn btn-primary btn-sm">${esc(S.signing ? tr('正在签名安装…') : label)}</button>`;
@@ -1567,8 +1911,8 @@ function signButton(label) {
/* 没有画面时,按守护进程的状态说清楚卡在哪、怎么办 */
function stageNote() {
const d = S.daemon, name = d?.device?.name || S.deviceName || tr('设备');
- switch (d?.state) {
- case 'Absent': return esc(tr('没有连上设备:用数据线连上 iPhone,确认数据线能传数据。'));
+ switch (d?.state || (frame.hasAttribute('data-absent') ? 'Absent' : null)) {
+ case 'Absent': return '<span class="idle-heading">' + tr('未连接设备') + '</span>' + tr('用数据线连接 iPhone 或 iPad。');
case 'NeedsTrust': case 'DeveloperModeOff':
return `${esc(name)} ${esc(tr('还没设置好(配对、开发者模式)。在终端运行'))} <code>iphone-control setup --reconfigure</code>${esc(tr(',选「手机」。'))}`;
case 'NeedsSigning':
@@ -1582,7 +1926,7 @@ function stageNote() {
return `${esc(tr('正在'))} ${esc(name)} ${esc(tr('上启动 WebDriverAgent,通常 10–60 秒…'))}`;
case 'NeedsUnlock': return esc(tr('设备重启后还没解锁过,在设备上手动解锁一次,画面就会出来。'));
case 'NeedsAutomationPin': return esc(tr('设备重启后首次启用 UI 自动化,请在设备上输入锁屏密码。'));
- default: return esc(tr('没有画面:画面来自设备上的 WebDriverAgent,它现在没有运行。3 秒后自动重试…'));
+ default: return esc(tr('没有收到设备画面,3 秒后自动重试。'));
}
}
function showStageNote() {
@@ -1590,28 +1934,38 @@ function showStageNote() {
const html = stageNote(); if (stageMsg.dataset.note !== html) { stageMsg.innerHTML = html; stageMsg.dataset.note = html; } // 不变就不重画,免得按钮丢了焦点
stageMsg.hidden = false;
}
-// This dialog always talks to the host, including when there is no phone. Opening it reads only the cache.
+// Opening the popover reads the host's cached report, even when no device is connected.
const updateDialog = $('#updates-dialog'), updateCheck = $('#update-check');
const aboutUpdates = $('#about-updates'), updateCommand = $('#update-command'), copyStatus = $('#update-copy-status');
let updatePoll, readingUpdates = false;
const updateText = (zh, en) => LANG === 'en' ? en : zh;
+function newerRelease(r) {
+ return r.available_version && ['available', 'brew_check', 'platform_pending', 'manual_only', 'unsupported'].includes(r.availability);
+}
function drawUpdateBadge(r) {
- const newer = r.available_version && ['available', 'brew_check', 'platform_pending', 'manual_only', 'unsupported'].includes(r.availability);
+ const newer = newerRelease(r);
$('#update-dot').hidden = !newer;
const label = tr('关于与更新') + (newer ? updateText(' · 新版本 ', ' · New release ') + r.available_version : '');
aboutUpdates.title = label;
aboutUpdates.setAttribute('aria-label', label);
}
function setUpdateCommand(command) {
- if (updateCommand.textContent !== command) copyStatus.textContent = '';
- updateCommand.textContent = command;
- $('#update-command-block').hidden = !command;
+ if (updateCommand.textContent !== command) {
+ copyStatus.textContent = '';
+ updateCommand.textContent = command;
+ }
+ $('#update-command-block').hidden = $('#update-copy').hidden = !command;
+}
+// The first changelog item is an excerpt. The release page has the full notes.
+function updateExcerpt(markdown) {
+ const line = markdown.split(/\r?\n/).map(s => s.trim()).find(s => s && !/^#|^---|^<!--/.test(s)) || '';
+ return line.replace(/^(?:[-*+] |\d+[.)] )/, '').replace(/!?\[([^\]]*)\]\([^)]*\)/g, '$1').replace(/\*\*|__/g, '').replace(/`([^`]+)`/g, '$1');
}
function drawUpdates(r) {
const t = updateText, unknown = t('未知', 'Unknown');
const channels = { managed: t('受管脚本安装', 'Managed installer'), script: t('手动脚本安装', 'Manual installer'),
development: t('源码构建', 'Source build'), homebrew: 'Homebrew', debian: 'Debian', unknown };
- const states = { development: t('开发构建,未绑定发布仓库', 'Development build; no release repository'),
+ const states = { development: t('开发构建 · 未绑定发布仓库', 'Development build · No release repository'),
unchecked: t('尚未检查', 'Not checked yet'), current: t('已是最新版', 'Up to date'),
ahead: t('当前版本领先于公开稳定版', 'Ahead of the public stable release'),
available: t('有可用更新', 'Update available'), platform_pending: t('已发布,当前平台安装包准备中', 'Released; waiting for this platform’s package'),
@@ -1620,10 +1974,13 @@ function drawUpdates(r) {
manual_only: t('此版本需要手动升级', 'Manual upgrade required') };
const policies = { manual: t('仅手动检查', 'Manual checks'), notify: t('后台检查,不自动安装', 'Check only'),
'auto-patch': t('空闲时自动安装补丁版', 'Install patches when idle') };
- $('#update-version').textContent = 'Viewer ' + (r.running_version || unknown);
+ const newer = newerRelease(r);
+ $('#update-version').textContent = newer ? (r.availability === 'available' ? t('可更新至 ', 'Update to ') : t('新版本 ', 'New release ')) + r.available_version : 'Viewer ' + (r.running_version || unknown);
+ $('#update-notes').textContent = newer ? updateExcerpt(r.release_notes || '') : '';
const facts = $('#update-facts'); facts.replaceChildren();
const row = (label, value) => { const dt = document.createElement('dt'), dd = document.createElement('dd');
dt.textContent = label; dd.textContent = value; facts.append(dt, dd); };
+ row(t('当前 Viewer', 'Running Viewer'), r.running_version || unknown);
row(t('发布者', 'Publisher'), r.publisher || t('未绑定', 'Unbound'));
row(t('安装方式', 'Installation'), (channels[r.install_method] || unknown) + (r.pinned ? t(' · 固定版本', ' · pinned') : ''));
row(t('磁盘 / 守护进程', 'Disk / daemon'), (r.installed_version || unknown) + ' / ' + (r.daemon_version || unknown));
@@ -1633,24 +1990,38 @@ function drawUpdates(r) {
const errors = { network: t('无法连接发布仓库', 'Release repository unreachable'), invalid_release: t('发行元数据无效', 'Invalid release metadata'),
rate_limited: t('请求受限', 'Rate limited'), http_error: t('发布仓库返回错误', 'Release repository returned an error') };
const failure = errors[r.error_code] || r.error_code || r.check_error;
- const result = failure ? t('检查失败:', 'Check failed: ') + failure : states[r.availability];
+ const result = failure ? t('检查失败:', 'Check failed: ') + failure : states[r.availability] || unknown;
if (r.retry_after && r.retry_after * 1000 > Date.now()) row(t('可重试时间', 'Retry after'), new Date(r.retry_after * 1000).toLocaleString(LANG));
- $('#update-result').textContent = r.checking ? tr('检查中…') : result || unknown;
+ const status = $('#update-result');
+ status.textContent = r.checking ? tr('检查中…') : newer && !failure && r.availability === 'available' ? '' : result;
+ status.dataset.error = String(Boolean(failure && !r.checking));
$('#update-guide').textContent = r.guidance || '';
setUpdateCommand(failure ? '' : r.upgrade_command || '');
+ $('#update-copy').title = r.guidance || tr('复制升级命令');
$('#update-policy').textContent = r.install_method === 'managed' && !r.pinned ?
t('本机策略:', 'Local policy: ') + 'iphone-control update policy ' + (r.policy === 'auto-patch' ? 'manual' : 'auto-patch') : '';
const outcomes = { installed: t('安装成功', 'Installed'), rolled_back: t('已手动回滚', 'Rolled back'), restored: t('升级失败,已恢复旧版本', 'Previous version restored'),
failed: t('更新失败', 'Update failed'), manual_migration: t('需要手动迁移', 'Manual migration required'),
- needs_operator: t('此版本不自动安装,请手动运行 update apply', 'Not installed automatically; run update apply'),
+ needs_operator: t('等待手动升级', 'Waiting for manual upgrade'),
busy: t('等待空闲', 'Waiting for idle'), recovery_failed: t('需要手动恢复', 'Recovery needs attention') };
- $('#update-outcome').textContent = r.last_update ? [r.last_update.target_version, outcomes[r.last_update.status] || r.last_update.status, r.last_update.detail].filter(Boolean).join(' · ') : '';
+ const last = r.last_update?.status;
+ const outcome = last === 'needs_operator' ? t('需手动运行 iphone-control update apply', 'Run iphone-control update apply manually') : outcomes[last] || last;
+ $('#update-outcome').textContent = r.last_update ? [r.last_update.target_version, outcome, r.last_update.detail].filter(Boolean).join(' · ') : '';
$('#update-mismatch').textContent = [r.installed_version, r.daemon_version].some(v => v && v !== r.running_version) ?
t('进程版本不同。重新打开 Viewer,重连 MCP 客户端,并按安装渠道重启 daemon。', 'Versions differ. Reopen Viewer, reconnect MCP clients and restart the daemon through its installation channel.') : '';
- const link = $('#update-release'); link.hidden = !r.release_url;
- if (r.release_url) link.href = r.release_url; else link.removeAttribute('href');
+ const more = $('#update-more');
+ const attention = last && !['installed', 'rolled_back'].includes(last) ? outcomes[last] || last :
+ $('#update-mismatch').textContent ? t('版本不一致', 'Version mismatch') : '';
+ more.dataset.attention = String(Boolean(attention));
+ more.firstElementChild.textContent = attention || tr('版本详情');
+ const link = $('#update-release');
+ link.hidden = !r.release_url?.startsWith('https://');
+ if (link.hidden) link.removeAttribute('href'); else link.href = r.release_url;
+ updateCheck.hidden = !r.publisher;
updateCheck.disabled = r.checking || !r.publisher;
- updateCheck.textContent = tr(r.checking ? '检查中…' : '检查更新');
+ updateCheck.title = tr(r.checking ? '检查中…' : '检查更新');
+ updateCheck.setAttribute('aria-label', updateCheck.title);
+ updateCheck.firstElementChild.classList.toggle('spin', r.checking);
}
async function loadUpdates(check = false) {
if (readingUpdates) return;
@@ -1661,21 +2032,42 @@ async function loadUpdates(check = false) {
if (check) { $('#update-result').textContent = tr('检查中…'); await api('/api/updates/check', {}); }
const report = await api('/api/updates');
drawUpdateBadge(report);
- if (updateDialog.open) drawUpdates(report);
- if (report.checking && updateDialog.open) updatePoll = setTimeout(loadUpdates, 700);
+ drawUpdates(report);
+ if (report.checking && updateDialog.matches(':popover-open')) updatePoll = setTimeout(loadUpdates, 700);
} catch (e) {
setUpdateCommand('');
$('#update-result').textContent = e.message;
- updateCheck.disabled = false; updateCheck.textContent = tr('检查更新');
+ $('#update-result').dataset.error = 'true';
+ updateCheck.disabled = updateCheck.hidden;
+ updateCheck.firstElementChild.classList.remove('spin');
+ updateCheck.title = tr('检查更新');
+ updateCheck.setAttribute('aria-label', updateCheck.title);
} finally {
readingUpdates = false;
}
}
-aboutUpdates.addEventListener('click', () => {
+function positionUpdates() {
+ if (updateDialog.matches(':popover-open')) positionPopover(aboutUpdates, updateDialog, true);
+}
+function showUpdateDetails(show) {
+ $('#update-details').hidden = !show;
+ $('#update-more').setAttribute('aria-expanded', String(show));
+ positionUpdates();
+}
+updateDialog.addEventListener('beforetoggle', ev => {
+ const opening = ev.newState === 'open';
+ aboutUpdates.setAttribute('aria-expanded', String(opening));
+ if (!opening) { clearTimeout(updatePoll); return; }
copyStatus.textContent = '';
- updateDialog.showModal();
+ showUpdateDetails(false);
+ updateDialog.scrollTop = 0;
+ requestAnimationFrame(positionUpdates);
loadUpdates();
});
+$('#update-more').addEventListener('click', () => showUpdateDetails($('#update-details').hidden));
+new ResizeObserver(positionUpdates).observe(updateDialog);
+new ResizeObserver(positionUpdates).observe($('#pane-agent'));
+window.addEventListener('resize', positionUpdates);
$('#update-copy').addEventListener('click', async () => {
const command = updateCommand.textContent;
if (!command) return;
@@ -1684,54 +2076,100 @@ $('#update-copy').addEventListener('click', async () => {
copyStatus.textContent = tr('已复制');
} catch {
const range = document.createRange(), selection = window.getSelection();
+ showUpdateDetails(true);
range.selectNodeContents(updateCommand);
selection.removeAllRanges();
selection.addRange(range);
- copyStatus.textContent = document.execCommand('copy') ? tr('已复制') : tr('请选中命令并手动复制。');
+ let copied = false;
+ try { copied = document.execCommand('copy'); } catch { /* The command stays selected for manual copy. */ }
+ copyStatus.textContent = tr(copied ? '已复制' : '请选中命令并手动复制。');
}
});
updateCheck.addEventListener('click', () => loadUpdates(true));
-updateDialog.addEventListener('close', () => clearTimeout(updatePoll));
// Refresh the host's cached report without initiating a release check.
const refreshVisibleUpdates = () => { if (!document.hidden) loadUpdates(); };
refreshVisibleUpdates();
setInterval(refreshVisibleUpdates, 60000);
document.addEventListener('visibilitychange', refreshVisibleUpdates);
-async function loadInfo() { try { applyInfo(await (await fetch('/api/info', { headers: { 'X-Ictl-Lang': LANG } })).json()); } catch { /* 跟着画面一起重试 */ } }
+async function loadInfo() {
+ const seq = ++infoSequence, epoch = feedEpoch;
+ try {
+ const r = await fetch('/api/info?feed=' + encodeURIComponent(feedId), { headers: { 'X-Ictl-Lang': LANG }, signal: AbortSignal.timeout(4800) });
+ if (!r.ok) throw new Error('offline');
+ const v = await r.json();
+ if (seq === infoSequence && epoch === feedEpoch) applyInfo(v);
+ } catch {
+ if (seq === infoSequence && epoch === feedEpoch) feedError();
+ }
+}
+async function pollInfo() {
+ await loadInfo();
+ setTimeout(pollInfo, 2000);
+}
+let firstFrameTimer = 0;
+function feedError() {
+ if (S.stream === 'error') return;
+ cancelGestures(); ++feedEpoch;
+ clearTimeout(firstFrameTimer); S.stream = 'error'; S.rtt = null;
+ stopVideo(); cv.hidden = true; live.style.visibility = 'hidden'; live.removeAttribute('src');
+ marks.replaceChildren(); hoverDot = null; S.elements = []; S.elState = 'idle'; renderElements();
+ applyZoom(); showStageNote(); renderFeed(); renderChips();
+ const epoch = feedEpoch;
+ retryTimer = setTimeout(async () => {
+ await loadInfo();
+ if (epoch === feedEpoch) connect();
+ }, 3000);
+}
+function refreshFrame(reoriented = false) {
+ if (S.mode !== 'live' || S.stream === 'error' || (V.on && !V.got) || !picW() || !picH()) return;
+ if (S.stream === 'ok' && !reoriented && picW() === frameWidth && picH() === frameHeight) return;
+ if (S.stream === 'ok') {
+ cancelGestures(); marks.replaceChildren(); hoverDot = null; S.elements = []; S.elState = 'idle';
+ loadInfo();
+ }
+ clearTimeout(firstFrameTimer);
+ S.stream = 'ok'; stageMsg.hidden = true; picEl().style.visibility = '';
+ frameWidth = picW(); frameHeight = picH();
+ setRatio(frameWidth, frameHeight); syncMarksBox(); renderElements(); renderFeed(); renderChips();
+}
function connect() {
- S.stream = 'connecting'; stageMsg.textContent = tr('正在连接画面…'); delete stageMsg.dataset.note; stageMsg.hidden = false;
- stopVideo();
- const q = `${S.udid ? `udid=${encodeURIComponent(S.udid)}&` : ''}t=${Date.now()}`;
- // 先试手机自己编的视频(iOS 27,HEVC),再试本机编的 H.264,都不行用 MJPEG
+ cancelGestures(); const epoch = ++feedEpoch;
+ clearTimeout(firstFrameTimer); clearTimeout(retryTimer);
+ stopVideo(); cv.hidden = true;
+ feedId = crypto.randomUUID();
+ S.stream = 'connecting'; frameWidth = frameHeight = 0;
+ applyZoom();
+ stageMsg.textContent = tr('正在连接画面…'); delete stageMsg.dataset.note; stageMsg.hidden = false;
+ const next = live.cloneNode(false); next.removeAttribute('src'); next.hidden = false; next.style.visibility = 'hidden';
+ live.replaceWith(next); live.removeAttribute('src'); live = next;
+ if (!S.udid) { feedError(); return; }
+ const q = 'udid=' + encodeURIComponent(S.udid) + '&feed=' + encodeURIComponent(feedId);
const dev = S.deviceVideo && !V.noDevice;
if ((dev || (S.video && !V.off)) && 'VideoDecoder' in window) {
- V.on = true; live.hidden = true; live.removeAttribute('src'); cv.hidden = false; startVideo(q, dev);
+ V.on = true; next.hidden = true; cv.style.visibility = 'hidden'; cv.hidden = false;
+ startVideo(q, dev);
} else {
- cv.hidden = true; live.hidden = false; live.src = `/stream?${q}`;
+ next.onload = () => { if (epoch === feedEpoch) refreshFrame(); };
+ next.onerror = () => { if (epoch === feedEpoch) feedError(); };
+ next.src = '/stream?' + q;
}
+ firstFrameTimer = setTimeout(() => {
+ if (epoch !== feedEpoch) return;
+ if (V.on && !V.got) {
+ if (dev) V.noDevice = true; else V.off = true;
+ connect();
+ } else feedError();
+ }, 9000);
renderFeed(); renderChips();
}
-/* 有画面了(第一帧、尺寸变了):和 MJPEG 的 load 一样处理 */
-function streamOk() {
- S.stream = 'ok'; stageMsg.hidden = true; picEl().style.visibility = ''; setRatio(picW(), picH()); syncMarksBox(); renderFeed(); renderChips();
-}
-function streamLost() {
- S.stream = 'error'; picEl().style.visibility = 'hidden'; showStageNote();
- renderFeed(); renderChips(); loadDeviceState();
- // 换了设备时 loadInfo 自己会重连;没换就重试这一台
- setTimeout(async () => { const u = S.udid; await loadInfo(); if (S.udid === u) connect(); }, 3000);
-}
-live.addEventListener('load', () => { if (S.mode === 'live' && !V.on) streamOk(); });
-live.addEventListener('error', () => { if (S.mode === 'live' && !V.on && live.getAttribute('src')) streamLost(); });
-
/* ---------- H.264 画面:服务端用 ffmpeg 编码(硬件优先),这里用 WebCodecs 解码(浏览器自己选硬件)画到 canvas。
* 消息:1 字节类型 + 4 字节长度 + 内容。0 是解码配置(JSON),1 关键帧,2 其他帧。
* 这一页从没出过画面就失败(没有编码器、浏览器解不了)就改用 MJPEG,之后不再试 ---------- */
function stopVideo() {
if (V.ctrl) V.ctrl.abort();
V.ctrl = null; V.on = false; V.got = false; V.rate = null; V.stream = ''; V.recv = 0; V.acked = 0; V.acking = false;
- V.device = false; V.crop = false; V.rot = 0; V.codecName = '';
+ V.device = false; V.crop = false; V.rot = null; V.frameRotation = null; V.bytes = 0; V.codecName = '';
if (V.dec && V.dec.state !== 'closed') { try { V.dec.close(); } catch { /* 已经关了 */ } }
V.dec = null;
}
@@ -1743,7 +2181,7 @@ async function startVideo(q, dev) {
stopVideo();
// 这一路从没出过画面就走不通:手机的视频走不通改用本机编码,本机编码也不行改用 MJPEG,之后不再试
if (permanent && !got) { if (dev) V.noDevice = true; else V.off = true; connect(); return; }
- streamLost();
+ feedError();
};
const onFrame = f => {
if (V.ctrl !== ctrl) { f.close(); return; }
@@ -1753,7 +2191,7 @@ async function startVideo(q, dev) {
const pw = Math.min(S.size.w, S.size.h), ph = Math.max(S.size.w, S.size.h), k = Math.round(sw / pw) || 1;
sw = Math.min(sw, Math.round(pw * k)); sh = Math.min(sh, Math.round(ph * k));
}
- const r = V.crop ? V.rot : 0, turned = r === 90 || r === 270;
+ const r = V.crop ? (V.rot ?? S.display?.rotation ?? 0) : 0, turned = r === 90 || r === 270;
const W = turned ? sh : sw, H = turned ? sw : sh;
const resized = cv.width !== W || cv.height !== H;
if (resized) { cv.width = W; cv.height = H; }
@@ -1762,7 +2200,9 @@ async function startVideo(q, dev) {
cvx.drawImage(f, 0, 0, sw, sh, -sw / 2, -sh / 2, sw, sh); cvx.restore();
} else cvx.drawImage(f, 0, 0, sw, sh, 0, 0, sw, sh);
f.close();
- if (!V.got || resized) { V.got = true; streamOk(); }
+ const reoriented = V.frameRotation !== r;
+ V.frameRotation = r; V.got = true;
+ refreshFrame(reoriented);
};
try {
const r = await fetch(`/video?${q}${dev ? '&src=device' : ''}`, { signal: ctrl.signal, headers: { 'X-Ictl-Lang': LANG } });
@@ -1771,7 +2211,8 @@ async function startVideo(q, dev) {
let buf = new Uint8Array(0);
for (;;) {
const { value, done } = await rd.read();
- if (done) return ended(false);
+ if (V.ctrl !== ctrl) return;
+ if (done) return ended(!V.got);
V.bytes += value.length; V.recv += value.length;
const n = new Uint8Array(buf.length + value.length); n.set(buf); n.set(value, buf.length); buf = n;
while (buf.length >= 5) {
@@ -1789,7 +2230,7 @@ async function startVideo(q, dev) {
try { ok = (await VideoDecoder.isConfigSupported(config)).supported; } catch { /* 当作不支持 */ }
if (!ok) return ended(true);
if (V.ctrl !== ctrl) return;
- if (!V.dec) V.dec = new VideoDecoder({ output: onFrame, error: () => ended(false) });
+ if (!V.dec) V.dec = new VideoDecoder({ output: onFrame, error: () => ended(!V.got) });
V.dec.configure(config); V.label = c.encoder || ''; V.stream = c.stream || '';
} else if (kind === 3) {
// 手机的视频:界面转了多少度(竖放的顶边顺时针转过去的角度),下一帧按它转正
@@ -1814,14 +2255,16 @@ setInterval(() => {
fetch('/api/video/ack', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ stream, bytes }) })
.then(r => { if (r.ok && V.stream === stream) V.acked = Math.max(V.acked, bytes); })
.catch(() => {})
- .finally(() => { V.acking = false; });
+ .finally(() => { if (V.stream === stream) V.acking = false; });
}, 100);
function renderFeed() {
const dot = $('#feed-dot'), txt = $('#feed-text');
dot.className = 'feed-dot';
if (S.mode === 'demo') { txt.textContent = tr('演示画面 · 本地模拟'); return; }
if (S.mode === 'detecting' || S.stream === 'connecting') { dot.classList.add('wait'); txt.textContent = tr('正在连接画面…'); return; }
+ if (frame.hasAttribute('data-absent')) { dot.classList.add('wait'); txt.textContent = tr('等待设备连接'); return; }
if (S.stream === 'error') { dot.classList.add('off'); txt.textContent = tr('画面断开 · 自动重试中'); return; }
+ if (!dims()) { dot.classList.add('wait'); txt.textContent = tr('画面已连接 · 等待屏幕尺寸和方向,仅可观看'); return; }
const route = S.dstatus?.route === 'hid' ? tr('HID 后备') : 'WDA';
const codec = V.on ? ` · ${V.codecName || 'H.264'}${V.label ? ` ${V.label}` : ''}${V.rate != null ? ` ${Math.round(V.rate / 1024)} KB/s` : ''}` : ' · MJPEG';
txt.textContent = `${tr('实时画面')} · ${route}${codec}${S.rtt != null ? ` · ${tr('操作往返')} ${S.rtt} ms` : ''}`;
@@ -1843,7 +2286,7 @@ const STARTING_HINT = {
NeedsUnlock: tr('设备重启后还没解锁过,需要在设备上手动解锁一次。'),
NeedsAutomationPin: tr('设备重启后首次启用 UI 自动化,请在设备上输入锁屏密码。')
};
-let statusTimerId = 0;
+let statusTimerId = 0, statusSequence = 0;
function refreshStatusSoon() { clearTimeout(statusTimerId); statusTimerId = setTimeout(loadDeviceState, 600); }
async function loadDeviceState() {
if (S.mode === 'demo') {
@@ -1851,35 +2294,51 @@ async function loadDeviceState() {
S.dstatus = { wda_ready: true, locked: D.screen === 'lock', foreground: foreground(), width: DW(), height: DH(), route: 'wda' };
S.devices = DEMO_DEVICES.map(d => ({ ...d, controlled: d === demoDev })); S.statusErr = ''; S.devicesErr = '';
} else if (S.mode === 'live') {
+ const udid = S.udid, sequence = ++statusSequence;
const [d, s, l] = await Promise.allSettled([api('/api/daemon'), api('/api/status'), api('/api/devices')]);
+ // Video can reconnect while the same device is still waiting for trust or signing.
+ if (udid !== S.udid || sequence !== statusSequence) return;
S.daemon = d.status === 'fulfilled' ? d.value : null;
S.dstatus = s.status === 'fulfilled' ? s.value : null;
S.statusErr = d.status === 'rejected' ? String(d.reason.message) : s.status === 'rejected' ? String(s.reason.message) : '';
if (l.status === 'fulfilled') { S.devices = l.value.devices || []; S.devicesFixed = !!l.value.fixed; S.devicesErr = ''; } else { S.devices = []; S.devicesErr = String(l.reason.message); }
}
- renderDevices(); renderChips(); renderFeed(); showStageNote(); if (S.devTab === 'status') renderStatusPanel();
+ $('#pane-dev').dataset.noDevice = String(S.mode === 'live' && !S.udid);
+ renderDevices(); renderChips(); renderFeed(); if (S.devTab === 'status') renderStatusPanel();
}
/* 新设备上还没装 WDA:用已登录的 Apple ID 签名并安装,大约 1–2 分钟 */
async function signWda() {
if (S.signing) return;
- S.signing = true; showStageNote(); if (S.devTab === 'status') renderStatusPanel();
+ S.signing = true; renderFeed(); if (S.devTab === 'status') renderStatusPanel();
show(tr('正在签名并安装 WebDriverAgent,大约 1–2 分钟,保持手机解锁…'));
try { await act('/api/sign', {}); } finally { S.signing = false; await loadDeviceState(); }
}
function renderDevices() {
if (S.mode === 'detecting') return;
if (!S.devices.length) {
- deviceEl.innerHTML = `<option>${esc(S.mode === 'live' ? tr('当前设备') : tr('没有设备'))}</option>`; deviceEl.disabled = true;
- deviceEl.title = S.devicesErr || ''; return;
+ deviceEl.innerHTML = `<option>${esc(S.udid ? tr('当前设备') : tr('没有设备'))}</option>`; deviceEl.disabled = true;
+ deviceEl.title = S.devicesErr || ''; pickerSync.device(); return;
}
const cur = S.devices.find(d => d.controlled);
- deviceEl.innerHTML = S.devices.map(d => `<option value="${esc(d.udid)}"${d.controlled ? ' selected' : ''}>${esc(d.name)}${S.mode === 'demo' ? tr('(演示)') : ''}</option>`).join('')
+ const labels = S.devices.map(deviceOptionLabel);
+ deviceEl.innerHTML = S.devices.map((d, index) => {
+ const name = labels[index];
+ const duplicate = labels.indexOf(name) !== labels.lastIndexOf(name);
+ const label = duplicate ? name + ' · ' + d.udid : name;
+ return `<option value="${esc(d.udid)}"${d.controlled ? ' selected' : ''}>${esc(label)}</option>`;
+ }).join('')
+ `<option value="auto"${cur ? '' : ' selected'}>${tr('自动选择')}</option>`;
- deviceEl.disabled = guarded() || S.devicesFixed;
- deviceEl.title = S.devicesFixed ? tr('已用 IPHONE_UDID 固定设备,不能切换') : '';
-}
-deviceEl.addEventListener('change', async () => {
- const v = deviceEl.value;
+ deviceEl.disabled = guarded() || S.switching || S.devicesFixed;
+ deviceEl.title = [deviceEl.selectedOptions[0]?.textContent, S.devicesFixed && tr('已用 IPHONE_UDID 固定设备,不能切换')].filter(Boolean).join(' · ');
+ pickerSync.device();
+}
+deviceEl.addEventListener('change', () => selectDevice(deviceEl.value));
+$('#nav-devices').addEventListener('click', ev => {
+ const row = ev.target.closest('button[data-device]');
+ if (row && !row.disabled && row.getAttribute('aria-current') !== 'true') selectDevice(row.dataset.device);
+});
+async function selectDevice(v) {
+ if (guarded() || S.switching || S.devicesFixed) return;
if (S.mode === 'demo') {
const next = v === 'auto' ? demoDev : DEMO_DEVICES.find(d => d.udid === v);
if (!next || next === demoDev) { show(v === 'auto' ? `${tr('已改为自动选择:继续控制')} ${demoDev.name}` : tr('已经在控制这台设备')); return; }
@@ -1889,55 +2348,77 @@ deviceEl.addEventListener('change', async () => {
show(`${tr('已切换到')} ${next.name}${tr('(演示)')}`);
return;
}
- S.switching = true; deviceEl.disabled = true;
+ cancelGestures(); S.switching = true; deviceEl.disabled = true; pickerSync.device();
try {
const r = await act('/api/select', { device: v }, true);
- // /api/info 拿到新设备后 onDeviceChanged 换画面、清面板;选的就是当前这台时什么也不用换
+ // /api/info 确认当前设备后才重新启用输入
if (r.ok) { const u = S.udid; await loadInfo(); if (S.udid === u) show(r.message || tr('已经在控制这台设备')); }
- } finally { S.switching = false; await loadDeviceState(); }
-});
+ } finally { S.switching = false; renderFeed(); renderElements(); await loadDeviceState(); }
+}
function renderChips() {
const c = $('#chips'), d = S.daemon, s = S.dstatus;
if (S.mode === 'detecting') { c.innerHTML = ''; return; }
const chips = [];
- const ready = d ? d.state === 'Ready' : S.stream === 'ok';
+ if (frame.hasAttribute('data-absent')) { c.replaceChildren(); return; }
+ const ready = d?.state === 'Ready';
chips.push(`<span class="chip"><span class="chip-dot ${ready ? 'ok' : d ? 'warn' : S.stream === 'error' ? 'off' : 'warn'}"></span><span>${ready ? tr('就绪') : d ? tr('未就绪') : S.stream === 'error' ? tr('画面断开') : tr('连接中')}</span></span>`);
// 不知道锁没锁(WDA 没起来、又没有 HID)时不显示
if (s && s.locked != null) {
chips.push(`<span class="chip"><span class="k">${tr('屏幕')}</span><span>${s.locked ? tr('已锁定') : tr('未锁定')}</span></span>`);
}
- if (S.mode === 'demo') chips.push(tr('<span class="chip"><span class="chip-dot warn"></span><span>演示模式</span></span>'));
c.innerHTML = chips.join('');
}
+// Keep the native disclosures and focused device buttons intact between status polls.
+function navigatorHTML(id, html) {
+ const node = $(id);
+ if (node.navMarkup !== html) { node.innerHTML = html; node.navMarkup = html; }
+}
function renderStatusPanel() {
- const p = $('#tp-status'), d = S.daemon, s = S.dstatus;
- if (S.mode === 'detecting') { p.innerHTML = tr('<p class="empty-note">正在连接 iphone-control 服务…</p>'); return; }
- const dev = d?.device || {};
+ const d = S.daemon, s = S.dstatus, dev = d?.device;
+ const list = S.devices.length ? S.devices : dev?.udid ? [dev] : [];
+ const selected = dev?.udid || S.udid;
+ const entries = list.map(item => {
+ const active = !!item.controlled || item.udid === selected;
+ const title = item.name || item.model_name || item.model || item.udid;
+ const model = item.model_name || item.model;
+ const duplicate = list.some(other => other.udid !== item.udid && deviceOptionLabel(other) === deviceOptionLabel(item));
+ const sub = [model && model !== title && model, osVersion(item), duplicate && item.udid].filter(Boolean).join(' · ');
+ return `<li><button type="button" class="nav-device" data-device="${esc(item.udid)}" aria-current="${active}" ${S.devicesFixed || guarded() || S.switching ? 'disabled' : ''}>
+ ${icon(item.family === 'ipad' ? 'tablet' : 'phone')}<span class="nav-device-copy"><span class="device-name">${esc(title)}</span>${sub ? `<span class="device-sub">${esc(sub)}</span>` : ''}</span></button></li>`;
+ });
+ const empty = S.mode === 'detecting' ? tr('正在查找…') : S.devicesErr ? tr('不可用') : tr('没有设备');
+ navigatorHTML('#nav-devices', entries.join('') || `<li class="nav-device nav-device-empty">${icon('phone')}${esc(empty)}</li>`);
+
+ const screen = dims();
+ const fact = ([k, v], mono = false) => `<div class="fact"><dt class="fact-k">${esc(k)}</dt><dd class="fact-v${mono ? ' mono' : ''}">${esc(v)}</dd></div>`;
const facts = [
- [tr('前台 App'), s?.foreground || '—'], [tr('屏幕'), s && s.locked != null ? (s.locked ? tr('已锁定') : tr('未锁定')) : '—'],
- [tr('操作通道'), s ? (s.route === 'hid' ? tr('HID 后备') : s.route === 'none' ? tr('不可用') : 'WDA') : '—'], [tr('屏幕尺寸'), s?.width ? `${s.width}×${s.height} pt` : S.size ? `${S.size.w}×${S.size.h} pt` : '—'],
- [tr('自动解锁'), d ? (d.auto_unlock ? tr('已设置密码') : tr('未设置')) : '—'], [tr('系统'), dev.ios ? `${osName(dev)} ${dev.ios}` : '—']
- ];
- let checks = '';
- if (d) {
- const failAt = d.state === 'Ready' ? -1 : CHECKS.findIndex(c => c.fail.includes(d.state));
- checks = CHECKS.map((c, i) => {
- const st = failAt === -1 || i < failAt ? 'ok' : i === failAt ? (d.state === 'WdaStarting' ? 'busy' : 'bad') : 'pending';
- // iOS 27 以下没有 HID 后备,别说「改走 HID」
- const hint = i === failAt ? (c.hint || (d.state === 'WdaStarting' && S.dstatus?.route === 'none' ? STARTING_NO_HID : STARTING_HINT[d.state]) || '') : '';
- const dot = st === 'ok' ? `<span class="check-dot tone-ok">${icon('check')}</span>` : st === 'busy' ? `<span class="check-dot tone-accent">${icon('loader', 'spin')}</span>` : st === 'bad' ? `<span class="check-dot tone-warn">${icon('alert')}</span>` : '<span class="check-dot pending"></span>';
- const label = st === 'ok' ? tr('已完成') : st === 'busy' ? tr('进行中') : st === 'bad' ? tr('需要处理') : tr('等待前一步');
- return `<li class="check${st === 'pending' ? ' pending' : ''}"><div class="check-rail">${dot}<span class="check-line"></span></div>
- <div class="check-body"><span class="check-name">${c.name}<span class="sr-only">${tr(':')}${label}</span></span>${hint ? `<span class="check-hint">${hint}</span>` : ''}${i === failAt && c.action === 'sign' && d.signed_in ? `<span><button type="button" class="btn btn-sm" data-action="sign"${S.signing ? ' disabled' : ''}>${esc(S.signing ? tr('正在签名安装…') : tr('签名并安装 WDA'))}</button></span>` : ''}${i === failAt && d.last_error ? `<span class="check-err">${esc(d.last_error)}</span>` : ''}</div></li>`;
- }).join('');
- }
- p.innerHTML = `
- <div class="device-card"><span class="device-ic">${icon(isPad(dev) || frame.dataset.kind === 'ipad' ? 'tablet' : 'phone')}</span>
- <div class="od-field"><span class="device-name od-truncate">${esc(dev.name || (S.mode === 'live' ? tr('已连接的设备') : '—'))}</span><span class="device-sub od-truncate">${esc([dev.model, dev.ios && `${osName(dev)} ${dev.ios}`].filter(Boolean).join(' · ') || tr('型号未知'))}${S.mode === 'demo' ? tr(' · 演示数据') : ''}</span></div></div>
- <div class="facts">${facts.map(([k, v]) => `<div class="fact"><span class="fact-k">${k}</span><span class="fact-v">${esc(v)}</span></div>`).join('')}
- <div class="fact" style="grid-column:1/-1"><span class="fact-k">UDID</span><span class="fact-v mono">${esc(dev.udid || '—')}</span></div></div>
- <div class="sec"><div class="sec-head"><span class="sec-title">${tr('就绪检查')}</span>${d ? badge(d.state === 'Ready' ? { label: tr('全部就绪'), tone: 'ok', icon: 'check' } : { label: tr('未就绪'), tone: 'warn', icon: 'alert' }) : ''}</div>
- ${d ? `<ol class="checks">${checks}</ol>` : `<p class="empty-note${S.statusErr ? ' err' : ''}">${esc(S.statusErr || tr('还没有拿到守护进程状态。'))}</p>`}</div>`;
+ [tr('前台 App'), s?.foreground], [tr('屏幕'), s?.locked != null && (s.locked ? tr('已锁定') : tr('未锁定'))],
+ [tr('操作通道'), s?.route === 'wda' ? 'WDA' : s?.route === 'hid' ? tr('HID 后备') : null],
+ [tr('屏幕尺寸'), screen && `${screen.W} × ${screen.H} pt`], [tr('自动解锁'), d && (d.auto_unlock ? tr('已设置密码') : tr('未设置'))]
+ ].filter(([,v]) => v);
+ $('#nav-facts').hidden = !selected || !facts.length;
+ navigatorHTML('#nav-facts', facts.map(row => fact(row)).join(''));
+ const ids = [['ProductType', dev?.model], ['UDID', selected]].filter(([,v]) => v);
+ $('#device-identifiers').hidden = !ids.length;
+ navigatorHTML('#nav-ids', ids.map(row => fact(row, true)).join(''));
+
+ const error = S.statusErr || S.devicesErr;
+ const failAt = CHECKS.findIndex(check => check.fail.includes(d?.state));
+ const checks = d?.state === 'Ready' ? CHECKS : CHECKS.slice(0, failAt + 1);
+ const rows = checks.map((c,i) => {
+ const issue = i === failAt;
+ const busy = issue && d.state === 'WdaStarting';
+ const hint = issue && (c.hint || (busy && s?.route === 'none' ? STARTING_NO_HID : STARTING_HINT[d.state]));
+ const label = issue ? (busy ? tr('进行中') : tr('需要处理')) : tr('已完成');
+ const sign = issue && c.action === 'sign' && d.signed_in;
+ return `<li>${icon(issue ? (busy ? 'loader' : 'info') : 'check', issue ? (busy ? 'spin' : '') : 'check-ok')}
+ <div><span class="check-name">${c.name}<span class="sr-only">${tr(':')}${label}</span></span>
+ ${hint ? `<span class="check-hint">${hint}</span>` : ''}
+ ${sign ? `<button type="button" class="btn btn-sm" data-action="sign"${S.signing ? ' disabled' : ''}>${esc(S.signing ? tr('正在签名安装…') : tr('签名并安装 WDA'))}</button>` : ''}
+ ${issue && d.last_error ? `<span class="check-err">${esc(d.last_error)}</span>` : ''}</div></li>`;
+ });
+ navigatorHTML('#nav-checks', (rows.length ? `<ol class="nav-check-list">${rows.join('')}</ol>` : '') +
+ (error || !d ? `<p class="check-hint">${esc(error || tr('还没有拿到守护进程状态。'))}</p>` : ''));
}
/* ================================================================
@@ -1945,12 +2426,16 @@ function renderStatusPanel() {
* ================================================================ */
async function loadApps() {
S.appsState = 'loading'; renderApps();
- const sys = $('#app-sys').checked;
+ const sys = $('#app-sys').checked, target = S.udid;
try {
if (S.mode === 'demo') { await sleep(350); S.apps = sys ? ALL_APPS.map(a => ({ name: a.name, bundle_id: a.bundle })) : []; }
- else S.apps = (await api(`/api/apps?system=${sys ? 1 : 0}`)).apps || [];
+ else {
+ const result = await api(`/api/apps?system=${sys ? 1 : 0}`);
+ if (target !== S.udid || sys !== $('#app-sys').checked) return;
+ S.apps = result.apps || [];
+ }
S.appsState = 'ok';
- } catch (e) { S.appsState = 'error'; S.appsErr = String(e.message || e); }
+ } catch (e) { if (target !== S.udid || sys !== $('#app-sys').checked) return; S.appsState = 'error'; S.appsErr = String(e.message || e); }
renderApps();
}
function renderApps() {
@@ -1997,16 +2482,21 @@ $('#url').addEventListener('keydown', ev => { if (ev.key === 'Enter' && !ev.isCo
* 元素
* ================================================================ */
async function loadElements() {
+ const epoch = feedEpoch;
S.elState = 'loading'; renderElements();
try {
if (S.mode === 'demo') { await sleep(300); S.elements = demoElements(); }
- else S.elements = (await api('/api/elements?filter=')).elements || [];
+ else {
+ const result = await api('/api/elements?filter=');
+ if (epoch !== feedEpoch) return;
+ S.elements = result.elements || [];
+ }
S.elState = 'ok';
- } catch (e) { S.elState = 'error'; S.elErr = String(e.message || e); }
+ } catch (e) { if (epoch !== feedEpoch) return; S.elState = 'error'; S.elErr = String(e.message || e); }
renderElements();
}
function renderElements() {
- const ul = $('#elements'), q = $('#el-q').value.trim().toLowerCase(), lock = guarded();
+ const ul = $('#elements'), q = $('#el-q').value.trim().toLowerCase(), lock = guarded() || (S.mode === 'live' && (!S.udid || S.switching));
const list = S.elements.map((e, i) => ({ ...e, i })).filter(e => !q || e.label.toLowerCase().includes(q) || e.type.toLowerCase().includes(q));
$('#el-count').textContent = S.elState === 'ok' ? `${list.length} ${tr('个')}${S.mode === 'demo' ? tr(' · 演示数据') : ''}` : '';
if (S.elState === 'loading') { ul.innerHTML = tr('<li class="sr-only">正在读取元素…</li>') + '<li class="skel-row no-tile" aria-hidden="true"><span class="skel-lines"><span class="skel l1"></span><span class="skel l2"></span></span></li>'.repeat(6); return; }
@@ -2027,12 +2517,11 @@ async function tapElement(i) {
if (guarded()) { nudgeGuard(); return; }
const e = S.elements[i]; if (!e) return;
const same = S.elements.slice(0, i).filter(x => x.label === e.label).length;
- const p = { x: round1(e.x + e.width / 2), y: round1(e.y + e.height / 2) };
highlight(null);
- if (S.mode === 'live') { drawMark('tap', 'user', p); await act('/api/tap_element', { text: e.label, index: same }); }
+ if (dims()) drawMark('tap', 'user', { x: round1(e.x + e.width / 2), y: round1(e.y + e.height / 2) });
+ if (S.mode === 'live') await act('/api/tap_element', { text: e.label, index: same });
else {
const el = $$('[data-label]', demoEl).filter(x => x.dataset.label === e.label)[same];
- drawMark('tap', 'user', p);
show(`${tr('按名字点「')}${e.label}${tr('」:')}${el && el.dataset.act ? demoAct(el.dataset.act) : tr('它不是可点的控件,界面没有变化')}`);
}
S.elState = 'stale'; renderElements();
@@ -2062,7 +2551,7 @@ function setDevTab(tab) {
$(`#tp-${t}`).hidden = t !== tab;
});
if (tab === 'status') renderStatusPanel();
- if (tab === 'apps' && S.appsState === 'idle' && S.mode !== 'detecting') loadApps(); else if (tab === 'apps') renderApps();
+ if (tab === 'apps' && S.appsState === 'idle' && (S.mode === 'demo' || S.udid)) loadApps(); else if (tab === 'apps') renderApps();
if (tab === 'elements') renderElements();
}
@@ -2215,9 +2704,21 @@ async function liveControl(task, action, body) {
/* ---------- 发送、控制、确认 ---------- */
function clearPromptError() { promptErr.hidden = true; promptErr.textContent = ''; promptEl.removeAttribute('aria-invalid'); $('#composer').classList.remove('invalid'); }
-function autosize() { promptEl.style.height = 'auto'; promptEl.style.height = Math.min(promptEl.scrollHeight, 176) + 'px'; }
+function syncSend() {
+ const empty = !promptEl.value.trim();
+ $('#send').disabled = promptEl.disabled || empty || (S.mode === 'live' && !S.udid);
+}
+function autosize() { promptEl.style.height = 'auto'; promptEl.style.height = Math.min(promptEl.scrollHeight, 176) + 'px'; syncSend(); }
+try {
+ const draft = sessionStorage.getItem('ictl.languageDraft');
+ if (draft !== null) {
+ sessionStorage.removeItem('ictl.languageDraft');
+ promptEl.value = draft;
+ autosize();
+ }
+} catch { /* No draft when session storage is unavailable. */ }
function sendPrompt() {
- if (activeTask()) return;
+ if (activeTask() || (S.mode === 'live' && !S.udid)) return;
const text = promptEl.value.trim();
if (!text) {
promptErr.textContent = tr('先写下要 AI 做的事,例如「打开设置,查看系统版本」。'); promptErr.hidden = false;
@@ -2314,11 +2815,12 @@ function appLabel(app) {
if (a) return a.name;
if (appNames.map) return appNames.map[app] || app;
if (!appNames.loading && S.mode === 'live') {
- appNames.loading = true;
+ const target = S.udid; appNames.loading = true;
api('/api/apps?system=1').then(v => {
+ if (target !== S.udid) return;
appNames.map = Object.fromEntries((v.apps || []).map(x => [x.bundle_id, x.name]));
renderTurns();
- }).catch(() => { appNames.map = {}; });
+ }).catch(() => { if (target === S.udid) appNames.map = {}; });
}
return app;
}
@@ -2399,7 +2901,7 @@ function renderRunbar() {
bar.hidden = false;
}
const busy = !!t;
- promptEl.disabled = busy; $('#send').disabled = busy;
+ promptEl.disabled = busy; syncSend();
promptEl.placeholder = busy ? tr('当前任务结束后可以发新任务') : tr('想让设备做什么?');
const clear = $('#clear-btn');
clear.hidden = !S.tasks.length || busy;
@@ -2422,7 +2924,7 @@ function renderGuard() {
waiting: { tone: 'warn', ic: 'alert', title: tr('AI 在等你确认一步操作'), sub: tr('确认前画面保持锁定。'), btns: [['goto-confirm', tr('去确认'), 'arrow']] },
takeover: { tone: 'user', ic: 'cursor', title: tr('你在接管'), sub: tr('AI 已暂停。交还后它会先重新看一遍屏幕。'), btns: [['handback', tr('交还 AI'), 'play']] }
}[t.status];
- g.className = `guard tone-${cfg.tone}`;
+ g.className = `guard glass tone-${cfg.tone}`;
g.innerHTML = `<span class="t-${cfg.tone}">${icon(cfg.ic, cfg.ic === 'loader' ? 'spin' : '')}</span><div class="guard-text"><span class="guard-title od-truncate">${cfg.title}</span><span class="guard-sub od-truncate">${cfg.sub}</span></div>
<div class="od-row od-fixed">${cfg.btns.map(([a, l, i]) => `<button type="button" class="btn btn-sm" data-action="${a}" data-focus="guard-${a}">${icon(i)}<span>${l}</span></button>`).join('')}</div>`;
g.hidden = false;
@@ -2430,10 +2932,13 @@ function renderGuard() {
}
function renderManual() {
const lock = guarded() || S.mode === 'detecting';
- $$('[data-key]').forEach(b => { b.disabled = lock; });
- typeEl.disabled = lock; $('#type-btn').disabled = lock; $('#type-submit').disabled = lock;
- $('#url').disabled = lock; $('#url-btn').disabled = lock;
- deviceEl.disabled = lock || !S.devices.length || !!S.devicesFixed;
+ const deviceUnavailable = lock || (S.mode === 'live' && !S.udid);
+ $$('[data-key]').forEach(b => { b.disabled = deviceUnavailable; });
+ typeEl.disabled = deviceUnavailable; $('#type-btn').disabled = deviceUnavailable; $('#type-submit').disabled = deviceUnavailable;
+ $('#url').disabled = deviceUnavailable; $('#url-btn').disabled = deviceUnavailable;
+ deviceEl.disabled = lock || S.switching || !S.devices.length || !!S.devicesFixed;
+ pickerSync.device();
+ $$('#nav-devices button').forEach(row => { row.disabled = lock || S.switching || !!S.devicesFixed; });
const t = activeTask();
$('#vt-agent-label').textContent = t ? `AI · ${{ running: tr('执行中'), waiting: tr('待确认'), paused: tr('已暂停'), takeover: tr('接管中') }[t.status]}` : tr('AI 助手');
}
@@ -2466,6 +2971,7 @@ const mqDrawer = matchMedia('(min-width: 1024px) and (max-width: 1279.98px)');
const mqTabs = matchMedia('(max-width: 1023.98px)');
function syncInert() {
$('#pane-dev').inert = (mqDrawer.matches && !S.devOpen) || (mqTabs.matches && S.view !== 'device') || (isThreeCol() && devHidden);
+ $('#dev-toggle').setAttribute('aria-expanded', String(!$('#pane-dev').inert));
$('#pane-agent').inert = mqTabs.matches && S.view !== 'agent';
$('#pane-stage').inert = mqTabs.matches && S.view !== 'screen';
}
@@ -2489,7 +2995,6 @@ document.addEventListener('click', ev => {
const a = b.dataset.action;
switch (a) {
case 'send': sendPrompt(); break;
- case 'fill': if (activeTask()) return; promptEl.value = b.dataset.prompt; autosize(); clearPromptError(); promptEl.focus(); promptEl.setSelectionRange(promptEl.value.length, promptEl.value.length); break;
case 'pause': case 'resume': case 'takeover': case 'handback': control(a); break;
case 'approve': answerConfirm(true); break;
case 'reject': answerConfirm(false); break;
@@ -2518,14 +3023,14 @@ document.addEventListener('click', ev => {
case 'tap-el': tapElement(+b.dataset.el); break;
case 'wait-for': waitFor(); break;
case 'reconnect':
- if (S.mode === 'live') { loadInfo(); connect(); loadDeviceState(); show(tr('正在重新连接画面…')); }
+ if (S.mode === 'live') { connect(); loadInfo(); loadDeviceState(); show(tr('正在重新连接画面…')); }
else if (S.mode === 'demo') { renderDemo(); loadDeviceState(); show(tr('已刷新演示画面')); }
break;
}
});
promptEl.addEventListener('keydown', ev => { if (ev.key === 'Enter' && !ev.shiftKey && !ev.isComposing && ev.keyCode !== 229) { ev.preventDefault(); sendPrompt(); } });
promptEl.addEventListener('input', () => { autosize(); if (!promptErr.hidden && promptEl.value.trim()) clearPromptError(); });
-document.addEventListener('keydown', ev => { if (ev.key === 'Escape' && mqDrawer.matches && S.devOpen && !stopDialog.open) setDevOpen(false); });
+document.addEventListener('keydown', ev => { if (ev.key === 'Escape' && mqDrawer.matches && S.devOpen && !document.querySelector('dialog[open]')) setDevOpen(false); });
// 设备面板的标签页支持左右方向键切换
$('#pane-dev .seg').addEventListener('keydown', ev => {
if (ev.key !== 'ArrowLeft' && ev.key !== 'ArrowRight') return;
@@ -2570,44 +3075,51 @@ async function detect() {
if (!r.ok) throw new Error('no service');
const v = await r.json();
if (!v || typeof v !== 'object' || !('width' in v || 'warning' in v)) throw new Error('no service');
- S.mode = 'live'; applyInfo(v); connect(); loadAgents();
- setInterval(() => { loadInfo(); loadDeviceState(); }, 10000);
+ S.mode = 'live'; applyInfo(v);
} catch {
- S.mode = 'demo'; S.stream = 'ok';
- stageMsg.hidden = true; live.hidden = true; cv.hidden = true; demoEl.hidden = false; $('#demo-note').hidden = false;
- applyDemoGeometry(); renderDemo();
- show(tr('演示模式:没有连上 iphone-control 服务,画面是本地模拟的。'));
+ if (document.documentElement.hasAttribute('data-viewer')) {
+ S.mode = 'live';
+ } else {
+ S.mode = 'demo'; S.stream = 'ok';
+ stageMsg.hidden = true; live.hidden = true; cv.hidden = true; demoEl.hidden = false; $('#demo-note').hidden = false;
+ applyDemoGeometry(); renderDemo();
+ show(tr('演示模式:没有连上 iphone-control 服务,画面是本地模拟的。'));
+ }
+ }
+ if (S.mode === 'live') {
+ connect(); loadAgents();
+ setInterval(refreshFrame, 250);
+ setTimeout(pollInfo, 2000);
+ setInterval(loadDeviceState, 10000);
}
await loadDeviceState();
renderAll(); setDevTab(S.devTab);
}
/* ---------- 执行任务的 AI:本机装了哪些就列哪些,选择记在浏览器里 ---------- */
const AGENT_KEY = 'ictl.agent';
+const agentSelect = $('#agent-value');
async function loadAgents() {
try { S.agents = (await api('/api/agent/backends')).backends || []; } catch { S.agents = []; }
const ok = S.agents.filter(a => a.available);
let saved = null;
try { saved = localStorage.getItem(AGENT_KEY); } catch { /* 预览环境可能禁用存储 */ }
S.agent = (ok.find(a => a.id === saved) || ok[0] || {}).id || null;
+ agentSelect.innerHTML = S.agents.map(a => `<option value="${esc(a.id)}"${a.available ? '' : ' disabled'}>${esc(a.name)}${a.available ? '' : tr('(未安装)')}</option>`).join('');
+ if (!S.agent) agentSelect.add(new Option(tr('没有可用的 AI'), ''), 0);
renderAgentPick();
}
+agentSelect.addEventListener('change', () => {
+ S.agent = agentSelect.value;
+ try { localStorage.setItem(AGENT_KEY, S.agent); } catch { /* The choice still applies for this session. */ }
+});
function renderAgentPick() {
- const wrap = $('#agent-pick'), sel = $('#agent');
+ const wrap = $('#agent-pick');
wrap.hidden = S.mode !== 'live';
- if (wrap.hidden) return;
- if (!S.agents.some(a => a.available)) {
- sel.innerHTML = tr('<option>没有可用的 AI</option>');
- sel.title = tr('这台机器的 PATH 里没有 claude 或 codex');
- } else {
- sel.innerHTML = S.agents.map(a => `<option value="${esc(a.id)}"${a.id === S.agent ? ' selected' : ''}${a.available ? '' : ' disabled'}>${esc(a.name)}${a.available ? '' : tr('(未安装)')}</option>`).join('');
- sel.title = tr('执行任务的本地 AI');
- }
- sel.disabled = !S.agent || !!activeTask();
+ agentSelect.value = S.agent || '';
+ agentSelect.title = S.agent ? tr('执行任务的本地 AI') : tr('这台机器的 PATH 里没有 claude 或 codex');
+ agentSelect.disabled = !S.agent || !!activeTask();
+ pickerSync.agent();
}
-$('#agent').addEventListener('change', ev => {
- S.agent = ev.target.value;
- try { localStorage.setItem(AGENT_KEY, S.agent); } catch { /* 只在本次会话生效 */ }
-});
/* ---------- 右侧设备面板隐藏 / 显示(宽屏三栏时),记在浏览器里 ---------- */
let devHidden = false;
@@ -2623,6 +3135,30 @@ function setDevHidden(hidden, moveFocus) {
show(hidden ? tr('已隐藏设备面板,点右上角「设备面板」可以再打开') : tr('已显示设备面板'));
}
+/* Local appearance affects workspace text only. Device pixels have their own scale. */
+const appearanceKey = 'ictl.appearance.v1';
+const systemDark = matchMedia('(prefers-color-scheme: dark)');
+const textSize = $('#text-size-value'), theme = $('#theme-value');
+function applyAppearance() {
+ document.documentElement.dataset.textSize = textSize.value;
+ document.documentElement.dataset.scheme = theme.value === 'system' ? (systemDark.matches ? 'dark' : 'light') : theme.value;
+}
+function readAppearance() {
+ let saved;
+ try { saved = JSON.parse(localStorage.getItem(appearanceKey)); } catch {}
+ textSize.value = ['large','xlarge'].includes(saved?.textSize) ? saved.textSize : 'standard';
+ theme.value = ['dark','light'].includes(saved?.theme) ? saved.theme : 'system';
+ applyAppearance();
+ pickerSync.theme(); pickerSync['text-size']();
+}
+readAppearance();
+systemDark.addEventListener('change', applyAppearance);
+window.addEventListener('storage', event => { if (event.key === appearanceKey || event.key === null) readAppearance(); });
+$('#appearance').addEventListener('change', () => {
+ applyAppearance();
+ try { localStorage.setItem(appearanceKey, JSON.stringify({textSize:textSize.value, theme:theme.value})); } catch {}
+});
+$('#appearance-btn').addEventListener('click', () => $('#appearance').showModal());
/* ---------- 两侧栏宽度:拖拽、方向键调整,双击恢复默认,记在浏览器里 ---------- */
const MIN_STAGE = 420; // 中间设备画面至少保留的宽度
const isThreeCol = () => matchMedia('(min-width: 1280px)').matches;
@@ -2735,13 +3271,15 @@ function applyZoom() {
updateZoomUI();
}
function updateZoomUI() {
- const sc = currentScale();
- $('#zoom-val').textContent = `${Math.round(sc * 100)}%`;
+ const known = !!devPointsW(), sc = currentScale();
+ $('#zoom-val').textContent = known ? `${Math.round(sc * 100)}%` : '—';
+ $('#zoom-val').disabled = !known;
$('#zoom-fit').setAttribute('aria-pressed', String(zoom === 'fit'));
- $('#zoom-out').disabled = sc <= ZOOM.min + 0.001;
- $('#zoom-in').disabled = sc >= ZOOM.max - 0.001;
+ $('#zoom-out').disabled = !known || sc <= ZOOM.min + 0.001;
+ $('#zoom-in').disabled = !known || sc >= ZOOM.max - 0.001;
}
function setZoom(z, anchor) {
+ if (z !== 'fit' && !devPointsW()) return;
// 缩放前记下视野中心(或滚轮所在点)在内容里的相对位置,缩放后保持在原处
const r = stageWrap.getBoundingClientRect();
const ax = anchor ? anchor.x - r.left : stageWrap.clientWidth / 2, ay = anchor ? anchor.y - r.top : stageWrap.clientHeight / 2;
diff --git a/apps/iphone-control/src/viewer.rs b/apps/iphone-control/src/viewer.rs
index 185bbf2..dbeafd9 100644
--- a/apps/iphone-control/src/viewer.rs
+++ b/apps/iphone-control/src/viewer.rs
@@ -23,7 +23,7 @@
//! instead of tapping a phone the user isn't looking at. The device handle is looked up again for each stream, so a
//! replug (new usbmuxd id) doesn't break the picture.
-use std::collections::HashMap;
+use std::collections::{HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::sync::{Arc, Mutex};
use std::time::Duration;
@@ -55,17 +55,40 @@ struct Ctx {
port: u16,
/// The device the page shows and acts on
udid: Mutex<String>,
+ feeds: Mutex<HashSet<String>>,
agents: Arc<Agents>,
checking: Arc<tokio::sync::Mutex<()>>,
check_error: Arc<Mutex<Option<String>>>,
/// Bundle id → display name, for the foreground app
names: tokio::sync::Mutex<HashMap<String, String>>,
+ device_video_allowed: bool,
/// H.264 for the picture; `None`: MJPEG only
video: Option<Arc<crate::video::Encoders>>,
/// How much of each H.264 stream its page has read
acks: Arc<crate::video::Acks>,
}
+/// A picture handler can be cancelled at any await, including while opening its source.
+struct FeedGuard<'a> {
+ feeds: &'a Mutex<HashSet<String>>,
+ id: String,
+}
+
+impl<'a> FeedGuard<'a> {
+ fn register(feeds: &'a Mutex<HashSet<String>>, id: String) -> Option<Self> {
+ if !feeds.lock().unwrap_or_else(|p| p.into_inner()).insert(id.clone()) {
+ return None;
+ }
+ Some(Self { feeds, id })
+ }
+}
+
+impl Drop for FeedGuard<'_> {
+ fn drop(&mut self) {
+ self.feeds.lock().unwrap_or_else(|p| p.into_inner()).remove(&self.id);
+ }
+}
+
impl Ctx {
fn udid(&self) -> String {
self.udid.lock().unwrap_or_else(|p| p.into_inner()).clone()
@@ -103,7 +126,8 @@ pub async fn run(socket: &Path, data_dir: &Path, port: u16) -> anyhow::Result<()
if udid.is_empty() { ictl_l10n::tr!("跟随守护进程", "whichever the daemon controls") } else { &udid }
)
);
- if crate::video::device_allowed() {
+ let device_video_allowed = crate::video::device_allowed();
+ if device_video_allowed {
println!(
"{}",
ictl_l10n::tr!(
@@ -155,11 +179,13 @@ pub async fn run(socket: &Path, data_dir: &Path, port: u16) -> anyhow::Result<()
data_dir: data_dir.to_path_buf(),
port,
udid: Mutex::new(udid),
+ feeds: Mutex::default(),
agents,
checking: Arc::default(),
check_error: Arc::default(),
names: tokio::sync::Mutex::default(),
page: page_in(ictl_l10n::lang()),
+ device_video_allowed,
video,
acks: Arc::default(),
});
@@ -180,10 +206,11 @@ pub async fn run(socket: &Path, data_dir: &Path, port: u16) -> anyhow::Result<()
/// The page with `data-lang` set for English, which the page reads as its default language
fn page_in(lang: ictl_l10n::Lang) -> String {
- match lang {
- ictl_l10n::Lang::En => PAGE.replacen("<html lang=\"zh-CN\">", "<html lang=\"en\" data-lang=\"en\">", 1),
- ictl_l10n::Lang::Zh => PAGE.to_owned(),
- }
+ let html = match lang {
+ ictl_l10n::Lang::En => "<html lang=\"en\" data-lang=\"en\" data-viewer>",
+ ictl_l10n::Lang::Zh => "<html lang=\"zh-CN\" data-viewer>",
+ };
+ PAGE.replacen("<html lang=\"zh-CN\">", html, 1)
}
/// One request per connection (`Connection: close`), which keeps the parser small. It is handled in the page's
@@ -206,66 +233,16 @@ async fn handle(mut client: TcpStream, ctx: &Ctx, head: Vec<u8>, req: Head, mut
let path = req.path.as_str();
match (req.method.as_str(), path) {
("GET", "/") => reply(&mut client, 200, "text/html; charset=utf-8", ctx.page.as_bytes()).await,
- // the phone's own screen video (iOS 27 and later), see `crate::video::device`
- ("GET", "/video") if req.query("src").as_deref() == Some("device") => {
- if !crate::video::device_allowed() {
- return reply(&mut client, 404, "text/plain", b"turned off by IPHONE_CONTROL_VIEWER_CODEC").await;
- }
- let udid = req.query("udid").filter(|u| !u.is_empty()).unwrap_or_else(|| ctx.udid());
- if udid.is_empty() {
- return reply(&mut client, 503, "text/plain", b"no device yet").await;
- }
- match crate::video::device::open(&ctx.socket, &udid).await {
- // the page takes 404 as "not this way" and falls back to H.264 or MJPEG
- Err(e) => reply(&mut client, 404, "text/plain; charset=utf-8", e.as_bytes()).await,
- Ok((src, w)) => {
- client
- .write_all(
- b"HTTP/1.1 200 OK\r\nContent-Type: application/octet-stream\r\nCache-Control: no-store\r\n\
- X-Content-Type-Options: nosniff\r\nConnection: close\r\n\r\n",
- )
- .await?;
- crate::video::device::serve(src, w, ctx.acks.clone(), client).await;
- Ok(())
- }
- }
- }
("GET", "/stream" | "/video") => {
- let video = if path == "/video" {
- match ctx.video.clone().filter(|e| e.label().is_some()) {
- Some(e) => Some(e),
- None => return reply(&mut client, 404, "text/plain", b"no H.264 encoder").await,
- }
+ let _feed = if let Some(id) = req.query("feed").filter(|id| !id.is_empty() && id.len() <= 80) {
+ let Some(guard) = FeedGuard::register(&ctx.feeds, id) else {
+ return reply(&mut client, 409, "text/plain", b"duplicate stream").await;
+ };
+ Some(guard)
} else {
None
};
- // the device the page shows (`?udid=`), so a page that hasn't noticed a switch keeps its own picture
- // instead of silently showing another phone. Looked up again each time: after a replug usbmuxd gives the
- // device a new id
- let udid = req.query("udid").filter(|u| !u.is_empty()).unwrap_or_else(|| ctx.udid());
- if udid.is_empty() {
- return reply(&mut client, 503, "text/plain", b"no device yet").await;
- }
- let device = ictl_device::Device::find(Some(&udid)).await;
- let mut remote = match async { device?.connect_port(MJPEG_PORT).await }.await {
- Ok(r) => r,
- Err(e) => return reply(&mut client, 502, "text/plain", e.to_string().as_bytes()).await,
- };
- // WDA's MJPEG server answers any request with the multipart stream
- remote.write_all(b"GET / HTTP/1.1\r\nHost: localhost\r\n\r\n").await?;
- match video {
- Some(enc) => {
- client
- .write_all(
- b"HTTP/1.1 200 OK\r\nContent-Type: application/octet-stream\r\nCache-Control: no-store\r\n\
- X-Content-Type-Options: nosniff\r\nConnection: close\r\n\r\n",
- )
- .await?;
- crate::video::serve(enc, ctx.acks.clone(), remote, client).await;
- }
- None => crate::video::serve_mjpeg(remote, client).await,
- }
- Ok(())
+ picture(client, ctx, &req).await
}
("GET", p) if p.starts_with("/api/agent/tasks/") && p.ends_with("/events") => {
let id = &p["/api/agent/tasks/".len()..p.len() - "/events".len()];
@@ -280,7 +257,14 @@ async fn handle(mut client: TcpStream, ctx: &Ctx, head: Vec<u8>, req: Head, mut
("GET", p) if p.starts_with("/api/") => {
let v = match &p[5..] {
// always an answer: the page falls back to its offline demo when this one fails
- "info" => Ok(info(ctx).await.unwrap_or_else(|m| json!({"width": null, "height": null, "warning": m}))),
+ "info" => {
+ let mut v =
+ info(ctx).await.unwrap_or_else(|m| json!({"width": null, "height": null, "warning": m}));
+ if let Some(id) = req.query("feed") {
+ v["feed_open"] = json!(ctx.feeds.lock().unwrap_or_else(|p| p.into_inner()).contains(&id));
+ }
+ Ok(v)
+ }
"updates" => updates(ctx).await,
"daemon" => daemon(ctx).await,
"status" => status(ctx).await,
@@ -322,6 +306,60 @@ async fn handle(mut client: TcpStream, ctx: &Ctx, head: Vec<u8>, req: Head, mut
}
}
+async fn video_head(client: &mut TcpStream) -> anyhow::Result<()> {
+ let head = b"HTTP/1.1 200 OK\r\nContent-Type: application/octet-stream\r\nCache-Control: no-store\r\n\
+ X-Content-Type-Options: nosniff\r\nConnection: close\r\n\r\n";
+ tokio::time::timeout(crate::video::STREAM_IDLE, client.write_all(head)).await??;
+ Ok(())
+}
+
+async fn picture(mut client: TcpStream, ctx: &Ctx, req: &Head) -> anyhow::Result<()> {
+ // the device the page shows (`?udid=`), so a page that hasn't noticed a switch keeps its own picture
+ // instead of silently showing another phone. Looked up again each time: after a replug usbmuxd gives the
+ // device a new id
+ let udid = req.query("udid").filter(|u| !u.is_empty()).unwrap_or_else(|| ctx.udid());
+ if udid.is_empty() {
+ return reply(&mut client, 503, "text/plain", b"no device yet").await;
+ }
+ if req.path == "/video" && req.query("src").as_deref() == Some("device") {
+ if !ctx.device_video_allowed {
+ return reply(&mut client, 404, "text/plain", b"turned off by IPHONE_CONTROL_VIEWER_CODEC").await;
+ }
+ return match crate::video::device::open(&ctx.socket, &udid).await {
+ // the page takes 404 as "not this way" and falls back to H.264 or MJPEG
+ Err(e) => reply(&mut client, 404, "text/plain; charset=utf-8", e.as_bytes()).await,
+ Ok((src, w)) => {
+ video_head(&mut client).await?;
+ crate::video::device::serve(src, w, ctx.acks.clone(), client).await;
+ Ok(())
+ }
+ };
+ }
+ let video = if req.path == "/video" {
+ match ctx.video.clone().filter(|e| e.label().is_some()) {
+ Some(e) => Some(e),
+ None => return reply(&mut client, 404, "text/plain", b"no H.264 encoder").await,
+ }
+ } else {
+ None
+ };
+ let connection = async { ictl_device::Device::find(Some(&udid)).await?.connect_port(MJPEG_PORT).await };
+ let mut remote = match tokio::time::timeout(crate::video::STREAM_IDLE, connection).await {
+ Ok(Ok(r)) => r,
+ _ => return reply(&mut client, 502, "text/plain", b"device feed unavailable").await,
+ };
+ tokio::time::timeout(crate::video::STREAM_IDLE, remote.write_all(b"GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"))
+ .await??;
+ match video {
+ Some(enc) => {
+ video_head(&mut client).await?;
+ crate::video::serve(enc, ctx.acks.clone(), remote, client).await;
+ }
+ None => crate::video::serve_mjpeg(remote, client, crate::video::STREAM_IDLE).await,
+ }
+ Ok(())
+}
+
/// The release cache belongs to the host user; process versions belong to this Viewer and socket.
async fn updates(ctx: &Ctx) -> Result<Value, String> {
// Sample before reading cached metadata: a check that finishes while this GET
@@ -424,6 +462,29 @@ async fn post(ctx: &Ctx, name: &str, b: &Value, device: Option<&str>) -> (u16, V
.into(),
);
}
+ if matches!(req, Request::TapElement { .. }) {
+ // The daemon resolves the name in a fresh accessibility tree on this device.
+ let Some(target) = device.filter(|id| !id.is_empty()) else {
+ return conflict(ictl_l10n::tr!("请先选择设备", "Select a device first.").into());
+ };
+ return (200, run_action(&ctx.socket, &req, Some(target), SHORT).await);
+ }
+ let positional = matches!(
+ req,
+ Request::Tap { .. }
+ | Request::LongPress { .. }
+ | Request::Swipe { .. }
+ | Request::Touch { phase: TouchPhase::Down | TouchPhase::Move | TouchPhase::Up, .. }
+ );
+ if positional {
+ let (Some(target), Some(view)) = (device, b["view"].as_str().filter(|id| !id.is_empty())) else {
+ return conflict(
+ ictl_l10n::tr!("画面已变化,请刷新后重试", "Display changed. Refresh the viewer and try again.").into(),
+ );
+ };
+ let reply = protocol::call_in_view(&ctx.socket, &req, Some(SHORT), target, view).await;
+ return (200, action_result(&req, reply));
+ }
(200, run_action(&ctx.socket, &req, udid, SHORT).await)
}
@@ -636,14 +697,19 @@ const SHORT: Duration = Duration::from_secs(120);
const SIGN: Duration = Duration::from_secs(16 * 60);
async fn run_action(socket: &Path, req: &Request, udid: Option<&str>, timeout: Duration) -> Value {
- match protocol::call_expecting(socket, req, Some(timeout), udid).await {
+ action_result(req, protocol::call_expecting(socket, req, Some(timeout), udid).await)
+}
+
+fn action_result(req: &Request, result: Result<Response, impl std::fmt::Display>) -> Value {
+ match result {
// tapping by text that found nothing is an ordinary answer for the agent, a failure for the page
Ok(Response::Text { text, outcome }) => {
let missed = matches!(req, Request::TapElement { .. }) && protocol::tapped_nothing(&text, outcome);
json!({"ok": !missed, "message": text})
}
Ok(Response::Image { caption, .. }) => json!({"ok": true, "message": caption}),
- Ok(Response::Error { message }) => json!({"ok": false, "message": message}),
+ Ok(Response::Error { message, retry_as_gesture }) => json!({"ok": false, "message": message,
+ "retry_as_gesture": retry_as_gesture && matches!(req, Request::Touch { phase: TouchPhase::Down, .. })}),
Err(e) => json!({"ok": false, "message": e.to_string()}),
}
}
@@ -654,7 +720,7 @@ async fn text_of(socket: &Path, req: Request, en: bool) -> Result<String, String
let r = if en { ictl_l10n::scope(ictl_l10n::Lang::En, call).await } else { call.await };
match r {
Ok(Response::Text { text, .. }) => Ok(text),
- Ok(Response::Error { message }) => Err(message),
+ Ok(Response::Error { message, .. }) => Err(message),
Ok(Response::Image { caption, .. }) => Ok(caption),
Err(e) => Err(e.to_string()),
}
@@ -666,26 +732,26 @@ async fn text_of(socket: &Path, req: Request, en: bool) -> Result<String, String
/// then its actions carry the old UDID and are refused, never sent to a phone the user isn't looking at
async fn info(ctx: &Ctx) -> Result<Value, String> {
let s = crate::snapshot(&ctx.socket).await.map_err(|e| e.to_string())?;
- if let Some(d) = &s.device
- && !d.udid.eq_ignore_ascii_case(&ctx.udid())
- {
- *ctx.udid.lock().unwrap_or_else(|p| p.into_inner()) = d.udid.clone();
- }
- let udid = ctx.udid();
- let screen = screen_of(&s.persisted, &udid);
+ let udid = s.device.as_ref().map(|d| d.udid.as_str()).unwrap_or_default();
+ *ctx.udid.lock().unwrap_or_else(|p| p.into_inner()) = udid.to_owned();
+ let screen = screen_of(&s.persisted, udid);
let live_touch = s.device.as_ref().is_some_and(|d| d.major_version() >= 27);
Ok(json!({
+ "display": s.display,
"width": screen.map(|s| s.width),
"height": screen.map(|s| s.height),
"udid": udid,
// the picture's pointer drives a finger over CoreDevice HID (iOS 27 and later); older phones get whole gestures
"live_touch": live_touch,
- "device": s.device.map(|d| d.name),
+ "device": s.device.as_ref().map(|d| &d.name),
+ "model": s.device.as_ref().map(|d| &d.product_type),
+ "model_name": s.device.as_ref().and_then(|d| d.model_name()),
+ "family": s.device.as_ref().map_or("unknown", |d| d.family()),
"state": state_of(&s.state).0,
// the picture as H.264 (`/video`) and with which encoder; null: MJPEG only
"video": ctx.video.as_ref().and_then(|e| e.label()),
// the phone's own screen video can be tried (`/video?src=device`): iOS 27 and later, not turned off
- "device_video": crate::video::device_allowed() && live_touch,
+ "device_video": ctx.device_video_allowed && live_touch,
}))
}
@@ -703,10 +769,13 @@ fn state_of(s: &DeviceState) -> (&'static str, Option<String>) {
}
fn device_json(d: &ictl_device::DeviceInfo) -> Value {
- json!({"udid": d.udid, "name": d.name, "model": d.product_type, "ios": d.product_version})
+ json!({
+ "udid": d.udid, "name": d.name, "model": d.product_type, "ios": d.product_version,
+ "model_name": d.model_name(), "family": d.family(),
+ })
}
-/// `{ state, last_error?, device: { name, model, ios, udid }, auto_unlock }`
+/// `{ state, last_error?, device: { name, model, model_name, family, ios, udid }, auto_unlock }`
async fn daemon(ctx: &Ctx) -> Result<Value, String> {
let s = crate::snapshot(&ctx.socket).await.map_err(|e| e.to_string())?;
let (state, last_error) = state_of(&s.state);
@@ -721,7 +790,7 @@ async fn daemon(ctx: &Ctx) -> Result<Value, String> {
}))
}
-/// `{ devices: [{ udid, name, model, ios, controlled }], fixed }`
+/// `{ devices: [{ udid, name, model, model_name, family, ios, controlled }], fixed }`
async fn devices(ctx: &Ctx) -> Result<Value, String> {
let s = crate::snapshot(&ctx.socket).await.map_err(|e| e.to_string())?;
let cur = s.device.as_ref().map(|d| d.udid.to_ascii_lowercase());
@@ -852,24 +921,53 @@ fn screen_of(p: &ictl_daemon::core::Persisted, udid: &str) -> Option<ictl_device
mod tests {
use super::*;
- #[tokio::test]
- async fn update_poll_keeps_polling_if_refresh_finishes_after_cache_read() {
- let temp = tempfile::tempdir_in("/tmp").unwrap();
- let socket = temp.path().join("daemon.sock");
- let daemon = tokio::net::UnixListener::bind(&socket).unwrap();
- let ctx = Ctx {
- agents: Agents::new(&socket, temp.path().join("gate")).unwrap(),
- socket,
- data_dir: temp.path().into(),
+ fn test_ctx(dir: &Path, socket: &Path) -> Ctx {
+ Ctx {
+ agents: Agents::new(socket, dir.join("gate")).unwrap(),
+ socket: socket.to_owned(),
+ data_dir: dir.into(),
port: 0,
page: String::new(),
checking: Arc::default(),
check_error: Arc::default(),
names: Default::default(),
udid: Default::default(),
+ device_video_allowed: true,
video: None,
acks: Arc::default(),
- };
+ feeds: Mutex::default(),
+ }
+ }
+
+ #[tokio::test]
+ async fn cancelled_picture_unregisters_its_feed() {
+ let temp = tempfile::tempdir_in("/tmp").unwrap();
+ let socket = temp.path().join("daemon.sock");
+ let daemon = tokio::net::UnixListener::bind(&socket).unwrap();
+ let ctx = test_ctx(temp.path(), &socket);
+ let listener = tokio::net::TcpListener::bind(("127.0.0.1", 0)).await.unwrap();
+ let (tab, accepted) = tokio::join!(TcpStream::connect(listener.local_addr().unwrap()), listener.accept());
+ let _tab = tab.unwrap();
+ let raw = b"GET /video?src=device&udid=TEST&feed=tab HTTP/1.1\r\nHost: localhost\r\n\r\n";
+ let (client, _) = accepted.unwrap();
+ let mut request = Box::pin(handle(client, &ctx, raw.to_vec(), Head::parse(raw).unwrap(), vec![]));
+ // The simulated daemon has accepted the request but has not supplied a stream.
+ tokio::select! {
+ result = &mut request => panic!("picture ended before cancellation: {result:?}"),
+ peer = daemon.accept() => { let _peer = peer.unwrap(); }
+ }
+ assert!(FeedGuard::register(&ctx.feeds, "tab".into()).is_none(), "the first request still owns this ID");
+ assert!(ctx.feeds.lock().unwrap().contains("tab"));
+ drop(request);
+ assert!(!ctx.feeds.lock().unwrap().contains("tab"));
+ }
+
+ #[tokio::test]
+ async fn update_poll_keeps_polling_if_refresh_finishes_after_cache_read() {
+ let temp = tempfile::tempdir_in("/tmp").unwrap();
+ let socket = temp.path().join("daemon.sock");
+ let daemon = tokio::net::UnixListener::bind(&socket).unwrap();
+ let ctx = test_ctx(temp.path(), &socket);
let guard = ctx.checking.lock().await;
let finish_check = async {
// The GET has consumed the release cache when its daemon snapshot begins.
@@ -888,6 +986,86 @@ mod tests {
Head::parse(s.as_bytes()).unwrap()
}
+ async fn reply_to_action(daemon: &tokio::net::UnixListener, reply: Response) -> Value {
+ use tokio::io::{AsyncBufReadExt, BufReader};
+ let (mut peer, _) = daemon.accept().await.unwrap();
+ let mut line = String::new();
+ BufReader::new(&mut peer).read_line(&mut line).await.unwrap();
+ peer.write_all(format!("{}\n", serde_json::to_string(&reply).unwrap()).as_bytes()).await.unwrap();
+ serde_json::from_str(&line).unwrap()
+ }
+
+ #[tokio::test]
+ async fn element_tap_requires_only_an_explicit_device() {
+ let temp = tempfile::tempdir_in("/tmp").unwrap();
+ let socket = temp.path().join("daemon.sock");
+ let daemon = tokio::net::UnixListener::bind(&socket).unwrap();
+ let ctx = test_ctx(temp.path(), &socket);
+ let body = json!({"text": "Settings", "index": 1});
+ *ctx.udid.lock().unwrap() = "different-device".into();
+ assert_eq!(post(&ctx, "tap_element", &body, None).await.0, 409);
+ assert_eq!(post(&ctx, "tap", &json!({"x": 1, "y": 2}), Some("phone")).await.0, 409);
+ let (result, req) = tokio::time::timeout(Duration::from_secs(3), async {
+ tokio::join!(
+ post(&ctx, "tap_element", &body, Some("phone")),
+ reply_to_action(&daemon, Response::text("ok"))
+ )
+ })
+ .await
+ .unwrap();
+ assert_eq!(result.1["ok"], true);
+ assert_eq!(req["op"], "tap_element");
+ assert_eq!(req["expect_udid"], "phone");
+ assert_eq!(req["index"], 1);
+ assert!(req.get("expect_view").is_none());
+ }
+
+ #[tokio::test]
+ async fn only_daemon_confirmed_pre_contact_failure_allows_gesture_retry() {
+ let temp = tempfile::tempdir_in("/tmp").unwrap();
+ let socket = temp.path().join("daemon.sock");
+ let daemon = tokio::net::UnixListener::bind(&socket).unwrap();
+ let ctx = test_ctx(temp.path(), &socket);
+ for (phase, daemon_retry, allow) in [("down", false, false), ("down", true, true), ("move", true, false)] {
+ let body = json!({"phase":phase, "x":1, "y":2, "view":"portrait"});
+ let reply = Response::Error { message: "touch failed".into(), retry_as_gesture: daemon_retry };
+ // The result comes directly from the action, with no follow-up status request.
+ let ((_, result), req) = tokio::time::timeout(Duration::from_secs(3), async {
+ tokio::join!(post(&ctx, "touch", &body, Some("phone")), reply_to_action(&daemon, reply))
+ })
+ .await
+ .unwrap();
+ assert_eq!(req["expect_view"], "portrait");
+ assert_eq!(req["expect_udid"], "phone");
+ assert_eq!(result["retry_as_gesture"], allow);
+ }
+ }
+
+ #[tokio::test]
+ async fn mjpeg_relays_a_frame_and_ends_on_disconnect() {
+ let frames = b"HTTP/1.1 200 OK\r\n\r\n--wda\r\nContent-Length: 4\r\n\r\n\xff\xd8\xff\xd9\r\n";
+ let (client, mut browser) = tokio::io::duplex(512);
+ let mut received = Vec::new();
+ let (_, count) = tokio::join!(
+ crate::video::serve_mjpeg(&frames[..], client, Duration::from_secs(2)),
+ browser.read_to_end(&mut received),
+ );
+ assert!(count.unwrap() > frames.len());
+ assert!(received.windows(4).any(|frame| frame == b"\xff\xd8\xff\xd9"));
+ }
+
+ #[tokio::test]
+ async fn mjpeg_expires_on_stalled_phone_or_browser() {
+ let idle = Duration::from_millis(25);
+ for capacity in [1, 512] {
+ let (_phone, remote) = tokio::io::duplex(8);
+ let (client, _browser) = tokio::io::duplex(capacity);
+ tokio::time::timeout(Duration::from_secs(2), crate::video::serve_mjpeg(remote, client, idle))
+ .await
+ .unwrap();
+ }
+ }
+
#[test]
fn actions_need_own_origin_and_json() {
let ok = "POST /api/tap HTTP/1.1\r\nHost: 127.0.0.1:8200\r\nOrigin: http://127.0.0.1:8200\r\nContent-Type: application/json\r\nContent-Length: 2\r\n\r\n";
@@ -982,8 +1160,8 @@ mod tests {
#[test]
fn the_page_says_its_default_language() {
- assert!(page_in(ictl_l10n::Lang::En).contains("<html lang=\"en\" data-lang=\"en\">"));
- assert!(page_in(ictl_l10n::Lang::Zh).contains("<html lang=\"zh-CN\">"));
+ assert!(page_in(ictl_l10n::Lang::En).contains("<html lang=\"en\" data-lang=\"en\" data-viewer>"));
+ assert!(page_in(ictl_l10n::Lang::Zh).contains("<html lang=\"zh-CN\" data-viewer>"));
}
#[test]
diff --git a/crates/ictl-daemon/Cargo.toml b/crates/ictl-daemon/Cargo.toml
index bda899b..feb9bc1 100644
--- a/crates/ictl-daemon/Cargo.toml
+++ b/crates/ictl-daemon/Cargo.toml
@@ -27,3 +27,4 @@ anyhow.workspace = true
image.workspace = true
base64.workspace = true
sha2.workspace = true
+uuid.workspace = true
diff --git a/crates/ictl-daemon/src/core.rs b/crates/ictl-daemon/src/core.rs
index ee4eeb6..f6f6127 100644
--- a/crates/ictl-daemon/src/core.rs
+++ b/crates/ictl-daemon/src/core.rs
@@ -197,6 +197,31 @@ pub struct CallCtx {
pub gone: Option<tokio::sync::oneshot::Receiver<()>>,
/// 正在控制的不是这台就不执行
pub expect_udid: Option<String>,
+ /// Identity of the measured display used for this coordinate.
+ pub expect_view: Option<String>,
+}
+
+/// Logical points measured on this connection. A different id invalidates queued coordinates.
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+pub struct DisplayGeometry {
+ pub id: String,
+ pub width: f64,
+ pub height: f64,
+ pub rotation: u16,
+}
+
+impl DisplayGeometry {
+ pub(crate) fn update(current: &mut Option<Self>, measurement: Option<(ScreenSize, Rotation)>) -> bool {
+ let Some((size, rotation)) = measurement else { return current.take().is_some() };
+ let width = size.width;
+ let height = size.height;
+ let rotation = rotation.degrees();
+ if current.as_ref().is_some_and(|v| (v.width, v.height, v.rotation) == (width, height, rotation)) {
+ return false;
+ }
+ *current = Some(Self { id: uuid::Uuid::new_v4().to_string(), width, height, rotation });
+ true
+ }
}
/// 快照:`iphone-control status` 显示
@@ -214,6 +239,8 @@ pub struct Snapshot {
/// USB 上接着的全部设备(读不到名字的只有 UDID)
#[serde(default)]
pub devices: Vec<DeviceInfo>,
+ #[serde(default)]
+ pub display: Option<DisplayGeometry>,
/// 选定的设备:`IPHONE_UDID` 或运行中选的;None 是自动选
#[serde(default)]
pub pinned: Option<String>,
@@ -233,14 +260,17 @@ pub struct Snapshot {
/// ([`Daemon::forget_device`]), so a new field can't be left holding the previous device's value
#[derive(Default)]
pub(crate) struct PerDevice {
+ pub display: Option<DisplayGeometry>,
+ /// Last complete measurement; passive partial samples never extend this window.
+ pub display_verified_at: Option<Instant>,
/// 这台手机上的 WDA 描述文件
pub device_profile: DeviceProfile,
/// 那份描述文件里没有本机签名私钥的证书(Some(true)):WDA 是别的机器、旧的数据目录签的,或本机的证书是后来才
/// 新建的。这时 WDA 起不来多半是签它的证书被吊销了,用本机的证书重签就好([`Daemon::heal_certificate`])。
/// None:不知道(没读到描述文件、本机还没签过名)
pub foreign_wda: Option<bool>,
- /// WDA 最近一次报的界面旋转及读取时间。只在短暂掉线时给 HID 使用,不持久化
- pub wda_rotation: Option<(Instant, Rotation)>,
+ /// 最近一次由 WDA 或 SpringBoard 确认的界面旋转及读取时间。只在短暂掉线时给 HID 使用,不持久化
+ pub last_rotation: Option<(Instant, Rotation)>,
/// 开发者镜像连续挂载失败次数,到 3 次清缓存重新下载
pub ddi_failures: u32,
/// 最近一次经本进程锁屏的时间(自动解锁要等锁屏过渡走完,见 [`crate::tools::LOCK_SETTLE`])
@@ -263,8 +293,8 @@ pub(crate) struct Inner {
pub info: Option<DeviceInfo>,
/// 最近一轮巡检时 USB 上接着的全部设备
pub connected: Vec<UsbDevice>,
- /// 各设备的名字、型号(第一次见到时读一次)
- pub infos: HashMap<String, DeviceInfo>,
+ /// 每次 USB 接入的设备信息;字段不齐时限制重试频率
+ pub infos: HashMap<String, crate::devices::CachedInfo>,
/// HID 和截图用的隧道(HID 会话归它所有)
pub tunnel: Option<Tunnel>,
pub runner: Option<WdaRunner>,
@@ -310,6 +340,7 @@ pub struct Daemon {
/// 停掉 HID 会话(屏幕媒体流),隧道保留。媒体流不停的话手机一直以为「配对的电脑」在看屏幕:
/// 灵动岛常驻图标、不会自动锁屏,本进程退出、拔插数据线都清不掉(iOS 27 真机)
pub(crate) async fn close_hid(g: &mut Inner) {
+ g.dev.touch_rotation = None;
if let Some(t) = g.tunnel.as_mut() {
t.close_hid().await;
}
@@ -317,6 +348,7 @@ pub(crate) async fn close_hid(g: &mut Inner) {
/// 丢掉隧道。一律走这里:先停 HID 媒体流再断(见 [`close_hid`])
pub(crate) async fn drop_tunnel(g: &mut Inner) {
+ g.dev.touch_rotation = None;
if let Some(t) = g.tunnel.take() {
t.close().await;
}
@@ -407,6 +439,7 @@ impl Daemon {
state: DeviceState::Absent,
device: None,
devices: Vec::new(),
+ display: None,
pinned: cfg.udid.clone().or_else(|| inner.persisted.selected_udid.clone()),
pinned_by_env: cfg.udid.is_some(),
persisted: inner.persisted.clone(),
@@ -441,7 +474,7 @@ impl Daemon {
.map(|d| {
g.infos
.get(&d.udid)
- .cloned()
+ .and_then(|entry| entry.value.clone())
.unwrap_or_else(|| DeviceInfo { udid: d.udid.clone(), ..Default::default() })
})
.collect()
@@ -530,6 +563,8 @@ impl Daemon {
r.stop();
}
g.wda = None;
+ g.dev.display = None;
+ g.dev.display_verified_at = None;
g.elements_cache = None;
g.swiped_tree = None;
drop_tunnel(g).await;
@@ -572,13 +607,23 @@ impl Daemon {
self.heartbeat.beat();
let unlock = self.unlock_cfg(g.device.as_ref().map(|d| d.udid.as_str()));
let pinned = self.pinned(g);
+ let devices = self.connected_infos(g);
+ // USB identity is available even when lockdown refuses the metadata connection.
+ let device = g.device.as_ref().map(|selected| {
+ g.info
+ .as_ref()
+ .or_else(|| devices.iter().find(|info| info.udid == selected.udid))
+ .cloned()
+ .unwrap_or_else(|| DeviceInfo { udid: selected.udid.clone(), ..Default::default() })
+ });
self.snap.send_replace(Snapshot {
version: Some(env!("CARGO_PKG_VERSION").into()),
pid: Some(std::process::id()),
maintenance: None,
state: g.state.clone(),
- device: g.info.clone(),
- devices: self.connected_infos(g),
+ device,
+ devices,
+ display: g.dev.display.clone(),
pinned,
pinned_by_env: self.cfg.udid.is_some(),
persisted: g.persisted.clone(),
@@ -668,9 +713,19 @@ impl Daemon {
if let Err(r) = admit(&req, queued_at, &ctx, g.device.as_ref().map(|d| d.udid.as_str())) {
return r;
}
+ let view = ctx.expect_view.as_deref();
// 改变界面的操作做完后缓存的元素树就作废;只有调用方声明「不改变布局」的按名字点击(max_age_ms > 0)保留
let keeps_cache = matches!(req, Request::TapElement { max_age_ms, .. } if max_age_ms > 0);
let invalidates = req.is_device_action() && !keeps_cache;
+ let response = self.dispatch(g, req, view).await;
+ if invalidates {
+ g.elements_cache = None;
+ }
+ self.publish(g);
+ response
+ }
+
+ async fn dispatch(&self, g: &mut Inner, req: Request, view: Option<&str>) -> Response {
// what the text reports, for clients that act on it (Response::Text.outcome)
let mut outcome = crate::protocol::Outcome::default();
let r = match req {
@@ -680,25 +735,29 @@ impl Daemon {
Err("screen_stream is a streaming request: open it with open_screen_stream".into())
}
Request::Screenshot { region } => {
- let resp = self.screenshot(g, region).await.unwrap_or_else(Response::error);
- self.publish(g);
- return resp;
+ return self.screenshot(g, region).await.unwrap_or_else(Response::error);
}
Request::ListElements { filter, limit, max_age_ms } => {
self.list_elements(g, &filter, limit, Duration::from_millis(max_age_ms)).await
}
- Request::Tap { x, y } => self.tap(g, x, y).await,
+ Request::Tap { x, y } => self.tap(g, x, y, view).await,
Request::TapElement { text, index, max_age_ms } => {
self.tap_element(g, &text, index, Duration::from_millis(max_age_ms)).await.map(|(t, missed)| {
outcome.tapped_nothing = missed;
t
})
}
- Request::LongPress { x, y, seconds } => self.long_press(g, x, y, seconds).await,
- Request::Swipe { from, to, seconds } => self.swipe(g, from, to, seconds).await,
+ 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).await,
Request::TypeText { text, submit } => self.type_text(g, &text, submit).await,
Request::PressButton { button } => self.press_button(g, &button).await,
- Request::Touch { phase, x, y } => self.touch(g, phase, x, y).await,
+ Request::Touch { phase, x, y } => {
+ return self
+ .touch(g, phase, x, y, view)
+ .await
+ .map(|()| Response::text_with("", outcome))
+ .unwrap_or_else(|e| e);
+ }
Request::ListApps { include_system } => self
.list_apps(g, include_system)
.await
@@ -734,10 +793,6 @@ impl Daemon {
| Request::WebTargets
| Request::WebEval { .. } => unreachable!("other lanes"),
};
- if invalidates {
- g.elements_cache = None;
- }
- self.publish(g);
r.map(|t| Response::text_with(t, outcome)).unwrap_or_else(Response::error)
}
@@ -897,7 +952,7 @@ fn check_request(req: &Request) -> Result<(), String> {
}
#[cfg(test)]
-mod tests {
+pub(crate) mod tests {
use super::*;
/// 重签结果存成时间和成败,按看的人的语言显示;旧字段照旧写中文整句,旧版本的 state.json 照样读
@@ -925,7 +980,7 @@ mod tests {
assert_eq!(o.last_resign.as_deref(), Some("2027-01-15 08:00:00 失败:boom"));
}
- fn test_daemon(tag: &str) -> (Arc<Daemon>, std::path::PathBuf) {
+ pub(crate) fn test_daemon(tag: &str) -> (Arc<Daemon>, std::path::PathBuf) {
let dir = std::env::temp_dir().join(format!("ictl-core-{tag}-{}", std::process::id()));
std::fs::create_dir_all(&dir).unwrap();
(Daemon::new(Config::from_env(&dir)), dir)
@@ -938,9 +993,113 @@ mod tests {
let busy = d.inner.lock().await;
let (tx, rx) = tokio::sync::oneshot::channel();
tx.send(()).unwrap();
- let r = d.handle(Request::Status, Instant::now(), CallCtx { gone: Some(rx), expect_udid: None }).await;
+ let r = d
+ .handle(
+ Request::Status,
+ Instant::now(),
+ CallCtx { gone: Some(rx), expect_udid: None, ..Default::default() },
+ )
+ .await;
drop(busy);
- assert!(matches!(&r, Response::Error { message } if message.contains("已取消")), "{r:?}");
+ assert!(matches!(&r, Response::Error { message, .. } if message.contains("已取消")), "{r:?}");
+ std::fs::remove_dir_all(dir).unwrap();
+ }
+
+ #[test]
+ fn display_identity_expires_on_rotation_resize_and_reconnect() {
+ let size = ScreenSize { width: 393.0, height: 852.0 };
+ let portrait = Some((size, Rotation::Portrait));
+ let mut display = None;
+ assert!(DisplayGeometry::update(&mut display, portrait));
+ let first = display.clone().unwrap().id;
+ assert!(!DisplayGeometry::update(&mut display, portrait));
+ assert_eq!(display.as_ref().unwrap().id, first);
+ assert!(DisplayGeometry::update(&mut display, Some((size, Rotation::UpsideDown))));
+ assert_ne!(display.as_ref().unwrap().id, first);
+ let zoom = ScreenSize { width: 375.0, height: 812.0 };
+ assert!(DisplayGeometry::update(&mut display, Some((zoom, Rotation::UpsideDown))));
+ assert!(DisplayGeometry::update(&mut display, None));
+ assert!(!DisplayGeometry::update(&mut display, None));
+ assert!(DisplayGeometry::update(&mut display, portrait));
+ assert_ne!(display.as_ref().unwrap().id, first);
+ }
+
+ #[test]
+ fn a_down_dropped_in_the_queue_cannot_be_replayed() {
+ let req = Request::Touch { phase: crate::protocol::TouchPhase::Down, x: 1., y: 2. };
+ let ctx =
+ CallCtx { expect_udid: Some("phone".into()), expect_view: Some("portrait".into()), ..Default::default() };
+ let expired = Instant::now() - STALE - Duration::from_secs(1);
+ assert!(matches!(
+ admit(&req, expired, &ctx, Some("phone")),
+ Err(Response::Error { retry_as_gesture: false, .. })
+ ));
+ }
+
+ #[tokio::test]
+ async fn coordinate_from_a_previous_view_is_rejected_before_dispatch() {
+ let (d, dir) = test_daemon("previous-view");
+ let ctx = CallCtx { expect_view: Some("old-view".into()), ..Default::default() };
+ let r = d.handle(Request::Tap { x: 3.0, y: 4.0 }, Instant::now(), ctx).await;
+ assert!(matches!(r, Response::Error { message, retry_as_gesture: false } if message.contains("画面")));
+ std::fs::remove_dir_all(dir).unwrap();
+ }
+
+ #[tokio::test]
+ async fn transient_status_miss_keeps_the_view_and_finger_until_loss_is_confirmed() {
+ let (d, dir) = test_daemon("status-miss-display");
+ let mut g = d.inner.lock().await;
+ let size = ScreenSize { width: 393., height: 852. };
+ DisplayGeometry::update(&mut g.dev.display, Some((size, Rotation::Portrait)));
+ let id = g.dev.display.as_ref().unwrap().id.clone();
+ g.dev.touch_rotation = Some(Rotation::Portrait);
+ for _ in 1..Misses::LIMIT {
+ assert!(!d.confirm_wda_loss(&mut g, true).await);
+ assert_eq!(g.dev.display.as_ref().unwrap().id, id);
+ assert_eq!(g.dev.touch_rotation, Some(Rotation::Portrait));
+ }
+ assert!(d.confirm_wda_loss(&mut g, true).await);
+ assert!(g.dev.display.is_none());
+ assert!(g.dev.touch_rotation.is_none());
+ std::fs::remove_dir_all(dir).unwrap();
+ }
+
+ #[tokio::test]
+ async fn drag_continuations_only_validate_the_existing_view() {
+ let (d, dir) = test_daemon("display-move-up");
+ let mut g = d.inner.lock().await;
+ DisplayGeometry::update(
+ &mut g.dev.display,
+ Some((ScreenSize { width: 393., height: 852. }, Rotation::Portrait)),
+ );
+ let id = g.dev.display.as_ref().unwrap().id.clone();
+ // No WDA in this fixture: resampling would invalidate the geometry before the HID path.
+ for phase in [crate::protocol::TouchPhase::Move, crate::protocol::TouchPhase::Up] {
+ g.dev.touch_rotation = Some(Rotation::Portrait);
+ let _ = d.touch(&mut g, phase, 20., 50., Some(&id)).await;
+ assert_eq!(g.dev.display.as_ref().unwrap().id, id);
+ let stale = d.touch(&mut g, phase, 20., 50., Some("old")).await.unwrap_err();
+ assert!(
+ matches!(stale, Response::Error { message, retry_as_gesture: false } if message.contains("画面") || message.contains("display changed"))
+ );
+ }
+ std::fs::remove_dir_all(dir).unwrap();
+ }
+
+ #[tokio::test]
+ async fn a_known_view_losing_its_measurement_cannot_start_a_finger() {
+ let (d, dir) = test_daemon("lost-display");
+ let mut g = d.inner.lock().await;
+ let size = ScreenSize { width: 393.0, height: 852.0 };
+ DisplayGeometry::update(&mut g.dev.display, Some((size, Rotation::Portrait)));
+ let ctx = CallCtx { expect_view: Some(g.dev.display.as_ref().unwrap().id.clone()), ..Default::default() };
+ drop(g);
+ let req = Request::Touch { phase: crate::protocol::TouchPhase::Down, x: 20.0, y: 50.0 };
+ let response = d.handle(req, Instant::now(), ctx).await;
+ assert!(matches!(response, Response::Error { message, retry_as_gesture: false } if message.contains("画面")));
+ let g = d.inner.lock().await;
+ assert!(g.dev.display.is_none());
+ assert!(g.dev.touch_rotation.is_none());
std::fs::remove_dir_all(dir).unwrap();
}
@@ -948,9 +1107,9 @@ mod tests {
#[tokio::test]
async fn request_for_another_device_is_refused() {
let (d, dir) = test_daemon("expect");
- let ctx = CallCtx { gone: None, expect_udid: Some("00008130-AAAA".into()) };
+ let ctx = CallCtx { gone: None, expect_udid: Some("00008130-AAAA".into()), ..Default::default() };
let r = d.handle(Request::Status, Instant::now(), ctx).await;
- assert!(matches!(&r, Response::Error { message } if message.contains("设备变了")), "{r:?}");
+ assert!(matches!(&r, Response::Error { message, .. } if message.contains("设备变了")), "{r:?}");
std::fs::remove_dir_all(dir).unwrap();
}
diff --git a/crates/ictl-daemon/src/devices.rs b/crates/ictl-daemon/src/devices.rs
index 0cd9266..05b9815 100644
--- a/crates/ictl-daemon/src/devices.rs
+++ b/crates/ictl-daemon/src/devices.rs
@@ -3,6 +3,8 @@
//! 同一时间只控制一台(一个 WDA 会话、一把设备锁)。选哪台见 [`crate::machine::pick_device`]:
//! 选定了就只认那一台;没选定时正在控制的那台一直用到它断开。切换时拆掉上一台的会话,在新的一台上拉起 WDA
+use std::time::{Duration, Instant};
+
use ictl_device::{Device, DeviceInfo, UsbDevice};
use crate::core::{Daemon, Inner, device_label};
@@ -35,15 +37,54 @@ pub fn resolve_device(devices: &[DeviceInfo], query: &str) -> Result<usize, Stri
}
}
+const METADATA_RETRY: Duration = Duration::from_secs(60);
+
+#[derive(Default)]
+pub(crate) struct CachedInfo {
+ pub value: Option<DeviceInfo>,
+ retry_at: Option<Instant>,
+}
+
+impl CachedInfo {
+ async fn refresh(&mut self, now: Instant, probe: impl Future<Output = Option<DeviceInfo>>) {
+ if self.retry_at.is_some_and(|retry| now < retry) {
+ return;
+ }
+ if self
+ .value
+ .as_ref()
+ .is_some_and(|i| !i.name.is_empty() && !i.product_type.is_empty() && !i.product_version.is_empty())
+ {
+ return;
+ }
+ self.retry_at = Some(now + METADATA_RETRY);
+ if let Some(mut info) = probe.await {
+ if let Some(cached) = &self.value {
+ for (field, previous) in [
+ (&mut info.product_type, &cached.product_type),
+ (&mut info.name, &cached.name),
+ (&mut info.product_version, &cached.product_version),
+ ] {
+ if field.is_empty() {
+ field.clone_from(previous);
+ }
+ }
+ }
+ self.value = Some(info);
+ }
+ }
+}
+
impl Daemon {
- /// 记下这一轮 USB 上接着的设备;新接上的读一次名字、型号
+ /// Read identity on attachment; lockdown can return partial metadata until the device is trusted.
pub(crate) async fn note_connected(&self, g: &mut Inner, devices: Vec<UsbDevice>) {
+ g.infos.retain(|udid, _| devices.iter().any(|d| d.udid == *udid));
for d in &devices {
- if !g.infos.contains_key(&d.udid)
- && let Ok(i) = Device::from_usb(d).info().await
- {
- g.infos.insert(d.udid.clone(), i);
+ if !g.connected.contains(d) {
+ g.infos.remove(&d.udid);
}
+ let cached = g.infos.entry(d.udid.clone()).or_default();
+ cached.refresh(Instant::now(), async { Device::from_usb(d).info().await.ok() }).await;
}
g.connected = devices;
}
@@ -176,6 +217,28 @@ mod tests {
}
}
+ #[tokio::test]
+ async fn incomplete_metadata_retries_without_polling_lockdown_each_tick() {
+ let start = Instant::now();
+ let mut cached = CachedInfo::default();
+ cached.refresh(start, async { None }).await;
+ cached
+ .refresh(start + Duration::from_secs(10), async { panic!("retried a failed query on the next tick") })
+ .await;
+ let mut partial = dev("A", "Tablet");
+ partial.product_version.clear();
+ cached.refresh(start + METADATA_RETRY, async { Some(partial) }).await;
+ cached
+ .refresh(start + METADATA_RETRY + Duration::from_secs(10), async {
+ panic!("retried partial metadata on the next tick")
+ })
+ .await;
+ cached.refresh(start + 2 * METADATA_RETRY, async { Some(dev("A", "")) }).await;
+ let info = cached.value.as_ref().unwrap();
+ assert_eq!((&*info.name, &*info.product_version), ("Tablet", "27.0"));
+ cached.refresh(start + 3 * METADATA_RETRY, async { panic!("retried complete metadata") }).await;
+ }
+
#[test]
fn passcode_file_is_per_device_and_stays_in_its_dir() {
let cfg = crate::Config::from_env(std::path::Path::new("/data"));
diff --git a/crates/ictl-daemon/src/lib.rs b/crates/ictl-daemon/src/lib.rs
index 685bd1a..4052374 100644
--- a/crates/ictl-daemon/src/lib.rs
+++ b/crates/ictl-daemon/src/lib.rs
@@ -134,23 +134,21 @@ async fn serve_conn(daemon: Arc<Daemon>, stream: tokio::net::UnixStream) {
// checked when it opens (no stream starts during an update) and not held while it runs: a page
// watching for hours would otherwise keep the updater from ever finding the host idle. An update
// stops the daemon, which ends the stream; the viewer reconnects to the new one
- (Ok((protocol::Request::ScreenStream, _, expect_udid, lang)), Ok(lease)) => {
+ (Ok((protocol::Request::ScreenStream, _, ctx, lang)), Ok(lease)) => {
drop(lease);
- ictl_l10n::scope(lang, daemon.screen_stream(reader, w, expect_udid)).await;
+ ictl_l10n::scope(lang, daemon.screen_stream(reader, w, ctx.expect_udid)).await;
return;
}
- (Ok((req, false, expect_udid, lang)), Ok(_lease)) => {
- let handling = daemon.handle(req, queued_at, core::CallCtx { gone: None, expect_udid });
+ (Ok((req, false, ctx, lang)), Ok(_lease)) => {
+ let handling = daemon.handle(req, queued_at, ctx);
ictl_l10n::scope(lang, handling).await
}
- (Ok((req, true, expect_udid, lang)), Ok(_lease)) => {
+ (Ok((req, true, mut ctx, lang)), Ok(_lease)) => {
// 调用方断开(取消、超时)就告诉 handle:还在排队的话不再执行
let (gone_tx, gone_rx) = tokio::sync::oneshot::channel();
let mut gone_tx = Some(gone_tx);
- let handling = ictl_l10n::scope(
- lang,
- daemon.handle(req, queued_at, core::CallCtx { gone: Some(gone_rx), expect_udid }),
- );
+ ctx.gone = Some(gone_rx);
+ let handling = ictl_l10n::scope(lang, daemon.handle(req, queued_at, ctx));
tokio::pin!(handling);
let resp = loop {
tokio::select! {
@@ -180,17 +178,23 @@ async fn serve_conn(daemon: Arc<Daemon>, stream: tokio::net::UnixStream) {
/// 解析一行请求,并取出 [`protocol::CANCEL_ON_CLOSE`]、[`protocol::EXPECT_UDID`]、[`protocol::LANG`]。
/// No language (an older client) means Chinese, which is what those clients expect and parse
-fn parse_request(line: &[u8]) -> serde_json::Result<(protocol::Request, bool, Option<String>, ictl_l10n::Lang)> {
+fn parse_request(line: &[u8]) -> serde_json::Result<(protocol::Request, bool, core::CallCtx, ictl_l10n::Lang)> {
let mut v: serde_json::Value = serde_json::from_slice(line)?;
- let (cancel, expect, lang) = match v.as_object_mut() {
+ let (cancel, udid, view, lang) = match v.as_object_mut() {
Some(o) => (
o.remove(protocol::CANCEL_ON_CLOSE).is_some_and(|c| c == true),
o.remove(protocol::EXPECT_UDID).and_then(|u| u.as_str().map(str::to_owned)),
+ o.remove(protocol::EXPECT_VIEW).and_then(|v| v.as_str().map(str::to_owned)),
o.remove(protocol::LANG).and_then(|l| l.as_str().and_then(ictl_l10n::parse)),
),
- None => (false, None, None),
+ None => (false, None, None, None),
};
- Ok((serde_json::from_value(v)?, cancel, expect, lang.unwrap_or(ictl_l10n::Lang::Zh)))
+ Ok((
+ serde_json::from_value(v)?,
+ cancel,
+ core::CallCtx { gone: None, expect_udid: udid, expect_view: view },
+ lang.unwrap_or(ictl_l10n::Lang::Zh),
+ ))
}
/// 等到调用方关掉连接(读到 EOF 或出错)。带 cancel_on_close 的客户端一个连接只发一个请求,之后不会再写
@@ -208,16 +212,18 @@ mod tests {
#[test]
fn request_options_are_taken_out_before_parsing() {
use ictl_l10n::Lang;
- let (req, cancel, expect, lang) =
- parse_request(br#"{"op":"tap","x":1.0,"y":2.0,"cancel_on_close":true,"expect_udid":"U1","lang":"en"}"#)
- .unwrap();
+ let (req, cancel, expect, lang) = parse_request(
+ br#"{"op":"tap","x":1.0,"y":2.0,"cancel_on_close":true,"expect_udid":"U1","expect_view":"V1","lang":"en"}"#,
+ )
+ .unwrap();
assert_eq!(req, protocol::Request::Tap { x: 1.0, y: 2.0 });
assert!(cancel);
- assert_eq!(expect.as_deref(), Some("U1"));
+ assert_eq!(expect.expect_udid.as_deref(), Some("U1"));
+ assert_eq!(expect.expect_view.as_deref(), Some("V1"));
assert_eq!(lang, Lang::En);
// 旧版本客户端:没有这几个键;没说语言就是中文(它们按中文的固定写法认结果)
let (_, cancel, expect, lang) = parse_request(br#"{"op":"status"}"#).unwrap();
- assert!(!cancel && expect.is_none());
+ assert!(!cancel && expect.expect_udid.is_none());
assert_eq!(lang, Lang::Zh);
let (_, _, _, lang) = parse_request(br#"{"op":"status","lang":"klingon"}"#).unwrap();
assert_eq!(lang, Lang::Zh);
diff --git a/crates/ictl-daemon/src/screen.rs b/crates/ictl-daemon/src/screen.rs
index 1368b24..152548a 100644
--- a/crates/ictl-daemon/src/screen.rs
+++ b/crates/ictl-daemon/src/screen.rs
@@ -146,11 +146,16 @@ impl Daemon {
}
}
- /// The interface rotation in degrees: asked of WDA when the device lock is free, else the last one known
+ /// The fresh interface rotation, if this poll could measure it.
async fn current_rotation(&self) -> Option<u32> {
let mut g = self.inner.try_lock().ok()?;
- self.refresh_hid_rotation(&mut g).await;
- g.dev.wda_rotation.map(|(_, r)| degrees(r))
+ // The native stream can observe rotation between supervisor ticks. Publish the new view
+ // and release any old contact before sending that rotation with the video.
+ let (rotation, changed) = self.sample_display(&mut g, false).await;
+ if changed {
+ self.publish(&g);
+ }
+ rotation.map(degrees)
}
/// The screen feed of the controlled device, opening the HID session for it if needed
@@ -184,6 +189,8 @@ impl Daemon {
#[cfg(test)]
mod tests {
use super::*;
+ use crate::core::{DisplayGeometry, tests::test_daemon};
+ use ictl_device::ScreenSize;
#[test]
fn rotation_degrees() {
@@ -192,4 +199,22 @@ mod tests {
[0, 90, 180, 270]
);
}
+
+ #[tokio::test]
+ async fn native_video_does_not_announce_a_cached_rotation_after_wda_is_gone() {
+ let (d, dir) = test_daemon("stream-stale-rotation");
+ let mut g = d.inner.lock().await;
+ let rotation = Rotation::UpsideDown;
+ DisplayGeometry::update(&mut g.dev.display, Some((ScreenSize { width: 393., height: 852. }, rotation)));
+ g.dev.display_verified_at = Some(Instant::now());
+ g.dev.last_rotation = Some((Instant::now(), rotation));
+ g.dev.touch_rotation = Some(rotation);
+ drop(g);
+
+ assert_eq!(d.current_rotation().await, None);
+ let g = d.inner.lock().await;
+ assert!(g.dev.display.is_none());
+ assert!(g.dev.touch_rotation.is_none());
+ std::fs::remove_dir_all(dir).unwrap();
+ }
}
diff --git a/crates/ictl-daemon/src/supervise.rs b/crates/ictl-daemon/src/supervise.rs
index c969a4e..2309e5d 100644
--- a/crates/ictl-daemon/src/supervise.rs
+++ b/crates/ictl-daemon/src/supervise.rs
@@ -3,13 +3,16 @@
use std::sync::Arc;
use std::time::{Duration, Instant, UNIX_EPOCH};
-use ictl_device::{Device, DeviceError, LogStream, Tunnel, UsbDevice};
+use ictl_device::{Device, DeviceError, LogStream, Rotation, ScreenSize, Tunnel, UsbDevice};
use ictl_wda::{WdaClient, WdaError, WdaRunner, http::DeviceTransport};
use crate::core::{Daemon, DetachedWda, DeviceProfile, Inner, close_hid};
use crate::machine::DeviceState;
use crate::notify::Event;
+/// Three 10-second supervisor intervals. A missing background sample within this
+/// window can leave a verified gesture running, but can never authorize a new one.
+const DISPLAY_SAMPLE_GRACE: Duration = Duration::from_secs(30);
/// 正常 2~10 秒就绪。手机重启后未授权 automation 时,testmanagerd 握手每次卡 30 秒、要重试一两次,
/// 60 秒常常等不到 runner 启动,也就认不出「需要输入密码」
const WDA_START_TIMEOUT: Duration = Duration::from_secs(120);
@@ -158,6 +161,64 @@ impl Daemon {
self.publish(g);
}
+ /// Returns the rotation actually observed in this sample and whether the published view changed.
+ pub(crate) async fn sample_display(&self, g: &mut Inner, gesture_start: bool) -> (Option<Rotation>, bool) {
+ let previous = g.dev.display.as_ref().map(|v| v.rotation);
+ let device = g.device.clone();
+ let Some(wda) = self.wda(g) else { return (None, self.update_display(g, None).await) };
+ let (size, rotation) = wda
+ .display_sample(previous, gesture_start, async { device?.interface_rotation().await.ok().flatten() })
+ .await;
+ let changed = self.record_display_sample(g, size, rotation, gesture_start).await;
+ (rotation, changed)
+ }
+
+ async fn record_display_sample(
+ &self,
+ g: &mut Inner,
+ size: Option<ScreenSize>,
+ rotation: Option<Rotation>,
+ gesture_start: bool,
+ ) -> bool {
+ if let Some(r) = rotation {
+ g.dev.last_rotation = Some((Instant::now(), r));
+ }
+ // Other clients use the last known size for HID even on WDA versions without /rotation.
+ if let (Some(size), Some(device)) = (size, &g.device)
+ && (g.persisted.screen != Some(size) || g.persisted.screen_udid.as_deref() != Some(&device.udid))
+ {
+ g.persisted.screen = Some(size);
+ g.persisted.screen_udid = Some(device.udid.clone());
+ g.persisted.save(&self.cfg.state_file());
+ }
+ let sample = size.zip(rotation);
+ if sample.is_none()
+ && !gesture_start
+ && g.dev.display_verified_at.is_some_and(|at| at.elapsed() < DISPLAY_SAMPLE_GRACE)
+ && let Some(view) = &g.dev.display
+ && size.is_none_or(|s| (s.width, s.height) == (view.width, view.height))
+ && rotation.is_none_or(|r| r.degrees() == view.rotation)
+ {
+ return false;
+ }
+ self.update_display(g, sample).await
+ }
+
+ async fn update_display(&self, g: &mut Inner, sample: Option<(ScreenSize, Rotation)>) -> bool {
+ g.dev.display_verified_at = sample.map(|_| Instant::now());
+ if !crate::core::DisplayGeometry::update(&mut g.dev.display, sample) {
+ return false;
+ }
+ if g.dev.touch_rotation.is_some() {
+ close_hid(g).await;
+ } else if let Some((size, _)) = sample
+ && let Some(hid) = g.tunnel.as_mut().and_then(Tunnel::open_hid)
+ {
+ hid.screen = size;
+ }
+ true
+ }
+
async fn offline(&self, g: &mut Inner) {
let now = Instant::now();
if g.device.take().is_some() {
@@ -176,6 +237,7 @@ impl Daemon {
}
pub(crate) async fn online(&self, g: &mut Inner, seen: &UsbDevice) {
+ g.info = g.infos.get(&seen.udid).and_then(|entry| entry.value.clone());
// 只比 UDID 不够:断开几秒又接上(短于离线判定、落在两轮巡检之间)时 UDID 不变,
// usbmuxd 却换了编号,旧句柄的每个连接都报 bad device,永远恢复不了
if !g.device.as_ref().is_some_and(|d| d.is_connection(seen)) {
@@ -197,10 +259,6 @@ impl Daemon {
// 同一台重新接入也清(App 列表重读很便宜,日志流经的旧连接已经断了)
self.forget_device(g).await;
let d = Device::from_usb(seen);
- g.info = d.info().await.ok();
- if let Some(i) = &g.info {
- g.infos.insert(seen.udid.clone(), i.clone());
- }
let model =
g.info.as_ref().map(|i| format!(" {} iOS {}", i.product_type, i.product_version)).unwrap_or_default();
self.log.log(&ictl_l10n::log_trf!("手机在线{model}", "Phone online{model}"));
@@ -222,7 +280,10 @@ impl Daemon {
self.refresh_device_profile(g).await;
}
}
- Ok(false) => return self.set_state(g, DeviceState::NeedsTrust),
+ Ok(false) => {
+ self.update_display(g, None).await;
+ return self.set_state(g, DeviceState::NeedsTrust);
+ }
// usbmuxd 出错:这一轮不下结论
Err(e) => {
return tracing::debug!(
@@ -246,7 +307,7 @@ impl Daemon {
};
if ready {
g.wda_misses.reset();
- self.refresh_hid_rotation(g).await;
+ self.sample_display(g, false).await;
if g.state != DeviceState::Ready {
if g.state == DeviceState::NeedsAutomationPin || g.dedup.was_sent("pin") {
g.dedup.clear("pin");
@@ -254,18 +315,10 @@ impl Daemon {
}
self.set_state(g, DeviceState::Ready);
g.backoff.reset();
- if let Some(w) = g.wda.as_mut()
- && let Ok(s) = w.screen_size().await
- {
- // 存竖放尺寸:WDA 在横屏时就绪的话这里拿到的是横的
- g.persisted.screen = Some(s.portrait());
- g.persisted.screen_udid = g.device.as_ref().map(|d| d.udid.clone());
- g.persisted.save(&self.cfg.state_file());
- }
}
return;
}
- if runner_alive && !g.wda_misses.hit() {
+ if !self.confirm_wda_loss(g, runner_alive).await {
return;
}
if g.runner.is_some() {
@@ -281,6 +334,15 @@ impl Daemon {
self.spawn_start(g, device, bundle);
}
+ /// Keep an active view and finger through the same transient status misses as the runner.
+ pub(crate) async fn confirm_wda_loss(&self, g: &mut Inner, runner_alive: bool) -> bool {
+ if runner_alive && !g.wda_misses.hit() {
+ return false;
+ }
+ self.update_display(g, None).await;
+ true
+ }
+
/// 在后台启动 WDA:挂开发者镜像(单独开一条隧道,用完关掉)→ 启动 runner 等就绪。
/// 最长约 2 分钟(等「Enable UI Automation」密码时),期间不持锁:工具调用照常走 HID 后备路线
fn spawn_start(&self, g: &mut Inner, device: Device, bundle: String) {
@@ -820,3 +882,50 @@ async fn open_log(device: &Device) -> Option<LogStream> {
}
}
}
+
+#[cfg(test)]
+mod display_tests {
+ use super::*;
+ use crate::core::tests::test_daemon;
+
+ const SIZE: ScreenSize = ScreenSize { width: 393., height: 852. };
+
+ #[tokio::test]
+ async fn passive_display_sample_absence_only_holds_the_last_verified_view_temporarily() {
+ let (d, dir) = test_daemon("display-grace");
+ let mut g = d.inner.lock().await;
+ d.record_display_sample(&mut g, Some(SIZE), Some(Rotation::Portrait), false).await;
+ let id = g.dev.display.as_ref().unwrap().id.clone();
+ g.dev.touch_rotation = Some(Rotation::Portrait);
+
+ // A timeout/unknown sample during a drag should not tear down the video or finger.
+ assert!(!d.record_display_sample(&mut g, Some(SIZE), None, false).await);
+ assert_eq!(g.dev.display.as_ref().unwrap().id, id);
+ assert_eq!(g.dev.touch_rotation, Some(Rotation::Portrait));
+ assert!(!d.record_display_sample(&mut g, Some(SIZE), Some(Rotation::Portrait), false).await);
+
+ // A fresh rotation alone does not extend the validity of an old complete sample.
+ g.dev.display_verified_at = Some(Instant::now() - DISPLAY_SAMPLE_GRACE);
+ assert!(d.record_display_sample(&mut g, None, Some(Rotation::Portrait), false).await);
+ assert!(g.dev.display.is_none());
+ assert!(g.dev.touch_rotation.is_none());
+ std::fs::remove_dir_all(dir).unwrap();
+ }
+
+ #[tokio::test]
+ async fn changed_or_strict_display_sample_invalidates_immediately() {
+ let (d, dir) = test_daemon("display-incomplete");
+ let mut g = d.inner.lock().await;
+ let resized = ScreenSize { width: 360., height: 780. };
+ for (size, rotation, start) in
+ [(None, Some(Rotation::TopToLeft), false), (Some(resized), None, false), (Some(SIZE), None, true)]
+ {
+ d.record_display_sample(&mut g, Some(SIZE), Some(Rotation::Portrait), false).await;
+ g.dev.touch_rotation = Some(Rotation::Portrait);
+ assert!(d.record_display_sample(&mut g, size, rotation, start).await);
+ assert!(g.dev.display.is_none());
+ assert!(g.dev.touch_rotation.is_none());
+ }
+ std::fs::remove_dir_all(dir).unwrap();
+ }
+}
diff --git a/crates/ictl-daemon/src/tools.rs b/crates/ictl-daemon/src/tools.rs
index 6983fb9..d28e88c 100644
--- a/crates/ictl-daemon/src/tools.rs
+++ b/crates/ictl-daemon/src/tools.rs
@@ -81,19 +81,10 @@ impl Daemon {
.ok_or_else(|| ictl_l10n::tr!("WDA 不可用,也不知道屏幕尺寸;等 WDA 起来一次,或在 ~/.config/iphone-control/env 里设 SCREEN_W/SCREEN_H", "WDA is unavailable and the screen size is unknown; wait for WDA to start once, or set SCREEN_W/SCREEN_H in ~/.config/iphone-control/env").into())
}
- /// 记下 WDA 报的界面旋转角:WDA 挂了以后 HID 点击要靠它换算横屏坐标(约 20 毫秒)
- pub(crate) async fn refresh_hid_rotation(&self, g: &mut Inner) {
- if let Some(w) = self.wda(g)
- && let Ok(r) = w.rotation().await
- {
- g.dev.wda_rotation = Some((Instant::now(), r));
- }
- }
-
/// 每次 HID 触摸前重新截图核对横竖,不依赖上次截图(转屏、回主屏、解锁都可能改变方向)。
- /// 截图只给宽高,不能分辨横屏左右;短暂掉线时借用近期 WDA 方向,过期或不匹配就不触摸。
+ /// 截图只给宽高,不能分辨横屏左右;短暂掉线时借用近期实测方向,过期或不匹配就不触摸。
async fn hid_touch_rotation(&self, g: &mut Inner) -> Result<Rotation, String> {
- self.refresh_hid_rotation(g).await;
+ self.sample_display(g, false).await;
let png = self.hid_screenshot(g).await.map_err(|e| {
ictl_l10n::trf!(
"核对 HID 方向失败,没有发送触摸:{e}",
@@ -102,7 +93,7 @@ impl Daemon {
})?;
let (w, h) = imaging::png_size(&png)
.ok_or(ictl_l10n::tr!("无法读取截图尺寸,没有发送触摸", "Can't read the screenshot size, no touch sent"))?;
- let known = g.dev.wda_rotation.map(|(at, r)| (at.elapsed(), r));
+ let known = g.dev.last_rotation.map(|(at, r)| (at.elapsed(), r));
hid_rotation(w, h, known)
}
@@ -263,7 +254,7 @@ impl Daemon {
};
// 给短暂 WDA 掉线时的 HID 留一份近期方向;不把方向永久缓存到磁盘。
if wda_png.is_some() {
- self.refresh_hid_rotation(g).await;
+ self.sample_display(g, false).await;
}
let (png, via) = match wda_png {
Some(p) => (p, "WDA"),
@@ -464,17 +455,54 @@ impl Daemon {
r
}
- pub(crate) async fn tap(&self, g: &mut Inner, x: f64, y: f64) -> Result<String, String> {
+ /// 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.
+ async fn prepare_coordinates(
+ &self,
+ g: &mut Inner,
+ view: Option<&str>,
+ start: bool,
+ ) -> Result<Option<Rotation>, String> {
+ let changed = || {
+ ictl_l10n::tr!(
+ "画面已变化或尺寸尚未确认,请在新画面上重试",
+ "The display changed or its geometry is unavailable. Retry on the new picture."
+ )
+ .to_owned()
+ };
+ if let Some(id) = view
+ && g.dev.display.as_ref().is_none_or(|v| v.id != id)
+ {
+ return Err(changed());
+ }
+ // Move and Up use the finger's orientation from Down. A known display change
+ // has already invalidated the token and released that finger in update_display.
+ if !start {
+ return Ok(None);
+ }
self.ensure_unlocked(g).await?;
+ let Some(id) = view else { return Ok(None) };
+ let (rotation, _) = self.sample_display(g, true).await;
+ if g.dev.display.as_ref().is_none_or(|v| v.id != id) {
+ return Err(changed());
+ }
+ Ok(rotation)
+ }
+
+ pub(crate) async fn tap(&self, g: &mut Inner, x: f64, y: f64, view: Option<&str>) -> Result<String, String> {
+ self.prepare_coordinates(g, view, true).await?;
let pos = format!("({},{})", fmt_g(x), fmt_g(y));
if let Some(w) = self.wda(g) {
// 只有连不上才退到 HID;超时说明请求已发出,再用 HID 做一遍可能点两次
match w.tap(x, y).await {
Ok(()) => return Ok(ictl_l10n::trf!("已点击 {pos}", "Tapped {pos}")),
- Err(WdaError::Unavailable(_)) => {}
+ Err(WdaError::Unavailable(_)) if view.is_none() => {}
Err(e) => return Err(e.to_string()),
}
}
+ if view.is_some() {
+ return Err(wda_down(&g.state, g.info.as_ref()));
+ }
let rot = self.hid_touch_rotation(g).await?;
self.hid_do(g, move |h| {
Box::pin(async move {
@@ -486,69 +514,76 @@ impl Daemon {
Ok(ictl_l10n::trf!("已点击 {pos}(经 HID)", "Tapped {pos} (via HID)"))
}
- /// A finger following the web viewer's pointer, one HID report per call (see `Request::Touch`). The checks a
- /// gesture needs (unlocking, the orientation) are done once, when it touches down; moves and the lift only send
- /// their report on the open HID session, so the screen keeps up with the pointer
- pub(crate) async fn touch(&self, g: &mut Inner, phase: TouchPhase, x: f64, y: f64) -> Result<String, String> {
- let contact = match phase {
- TouchPhase::Prepare => {
- self.hid(g).await?;
- g.hid_used = Some(Instant::now());
- return Ok(String::new());
- }
- TouchPhase::Down => {
- self.ensure_unlocked(g).await?;
- // WDA knows which way the interface is turned (about 20 ms); without it, check with a screenshot
- let rot = match self.wda(g) {
- Some(w) => w.rotation().await.ok(),
+ /// Follow the viewer pointer with one HID report per call. The first event prepares the device.
+ /// Later events reuse the open HID session and reject a change in display orientation.
+ pub(crate) async fn touch(
+ &self,
+ g: &mut Inner,
+ phase: TouchPhase,
+ x: f64,
+ y: f64,
+ view: Option<&str>,
+ ) -> Result<(), Response> {
+ if phase == TouchPhase::Prepare {
+ self.hid(g).await.map_err(Response::error)?;
+ g.hid_used = Some(Instant::now());
+ return Ok(());
+ }
+ let measured = self.prepare_coordinates(g, view, phase == TouchPhase::Down).await.map_err(Response::error)?;
+ if phase == TouchPhase::Down {
+ let rotation = if let Some(rotation) = measured {
+ rotation
+ } else {
+ // Clients without a view id can use the HID fallback.
+ let fresh = match self.wda(g) {
+ Some(wda) => wda.rotation().await.ok(),
None => None,
};
- let rot = match rot {
+ match fresh {
Some(r) => {
- g.dev.wda_rotation = Some((Instant::now(), r));
+ g.dev.last_rotation = Some((Instant::now(), r));
r
}
- None => self.hid_touch_rotation(g).await?,
- };
- g.dev.touch_rotation = Some(rot);
- true
- }
- TouchPhase::Move => true,
- TouchPhase::Up => false,
- };
+ None => self.hid_touch_rotation(g).await.map_err(Response::error)?,
+ }
+ };
+ g.dev.touch_rotation = Some(rotation);
+ }
+ self.send_touch(g, phase, x, y).await
+ }
+
+ async fn send_touch(&self, g: &mut Inner, phase: TouchPhase, x: f64, y: f64) -> Result<(), Response> {
+ let contact = phase != TouchPhase::Up;
let Some(rot) = g.dev.touch_rotation else {
- return Err(ictl_l10n::tr!("没有按下的手指,先发 down", "No finger is down; send down first").into());
+ return Err(Response::error(ictl_l10n::tr!(
+ "没有按下的手指,先发 down",
+ "No finger is down; send down first"
+ )));
};
if !contact {
g.dev.touch_rotation = None;
}
- // the open session straight away: looking up the screen size for every move would cost a WDA request each
- let open = g.tunnel.as_mut().and_then(|t| t.open_hid()).is_some();
- let r = if open {
- let h = g.tunnel.as_mut().and_then(|t| t.open_hid()).expect("checked above");
- h.rotation = rot;
- let r = h.touch(contact, x, y).await;
- g.hid_used = Some(Instant::now());
- match r {
- Ok(()) => Ok(()),
- Err(e) => {
- drop_tunnel(g).await;
- Err(ictl_l10n::trf!("HID 命令失败: {e}", "HID command failed: {e}"))
+ // Reuse the open session without another WDA screen-size lookup on every move.
+ let h = match g.tunnel.as_mut().and_then(|t| t.open_hid()) {
+ Some(h) => h,
+ None => match self.hid(g).await {
+ Ok(h) => h,
+ Err(message) => {
+ g.dev.touch_rotation = None;
+ return Err(Response::Error { message, retry_as_gesture: phase == TouchPhase::Down });
}
- }
- } else {
- self.hid_do(g, move |h| {
- Box::pin(async move {
- h.rotation = rot;
- h.touch(contact, x, y).await
- })
- })
- .await
+ },
};
- if r.is_err() {
+ h.rotation = rot;
+ let result = h.touch(contact, x, y).await;
+ g.hid_used = Some(Instant::now());
+ if let Err(e) = result {
+ // A failed write may still have reached the phone.
g.dev.touch_rotation = None;
+ drop_tunnel(g).await;
+ return Err(Response::error(ictl_l10n::trf!("HID 命令失败: {e}", "HID command failed: {e}")));
}
- r.map(|()| String::new())
+ Ok(())
}
pub(crate) async fn tap_element(
@@ -618,8 +653,15 @@ impl Daemon {
Ok((ictl_l10n::trf!("已点击 {}{note}{moved}", "Tapped {}{note}{moved}", e.describe()), false))
}
- pub(crate) async fn long_press(&self, g: &mut Inner, x: f64, y: f64, seconds: f64) -> Result<String, String> {
- self.ensure_unlocked(g).await?;
+ pub(crate) async fn long_press(
+ &self,
+ g: &mut Inner,
+ x: f64,
+ y: f64,
+ seconds: f64,
+ view: Option<&str>,
+ ) -> Result<String, String> {
+ self.prepare_coordinates(g, view, true).await?;
self.require_wda(g)?.touch_and_hold(x, y, seconds).await.map_err(|e| e.to_string())?;
Ok(ictl_l10n::trf!("已长按 ({},{}) {} 秒", "Long-pressed ({},{}) for {} s", fmt_g(x), fmt_g(y), fmt_g(seconds)))
}
@@ -630,8 +672,9 @@ impl Daemon {
from: (f64, f64),
to: (f64, f64),
seconds: f64,
+ view: Option<&str>,
) -> Result<String, String> {
- self.ensure_unlocked(g).await?;
+ 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));
if let Some(w) = self.wda(g) {
match w.swipe_into_polling(from, to, (seconds * 1000.0) as u64).await {
@@ -643,10 +686,13 @@ impl Daemon {
g.swiped_tree = tree.map(|t| (Instant::now(), t));
return Ok(ictl_l10n::trf!("已滑动 {desc}{note}", "Swiped {desc}{note}"));
}
- Err(WdaError::Unavailable(_)) => {}
+ Err(WdaError::Unavailable(_)) if view.is_none() => {}
Err(e) => return Err(e.to_string()),
}
}
+ if view.is_some() {
+ return Err(wda_down(&g.state, g.info.as_ref()));
+ }
let rot = self.hid_touch_rotation(g).await?;
self.hid_do(g, move |h| {
Box::pin(async move {
@@ -1239,6 +1285,24 @@ async fn verify_typed(w: &mut WdaClient<DeviceTransport>, text: &str) -> Typed {
mod tests {
use super::*;
+ #[tokio::test]
+ async fn missing_hid_session_allows_retry_for_down_only() {
+ let (d, dir) = crate::core::tests::test_daemon("touch-no-hid");
+ let mut g = d.inner.lock().await;
+ // Older devices cannot open a HID session. Only a Down that already passed
+ // coordinate preparation can opt in to the whole-gesture fallback.
+ g.info = Some(ictl_device::DeviceInfo { product_version: "18.0".into(), ..Default::default() });
+ for phase in [TouchPhase::Down, TouchPhase::Move, TouchPhase::Up] {
+ g.dev.touch_rotation = Some(Rotation::Portrait);
+ let err = d.send_touch(&mut g, phase, 20., 50.).await.unwrap_err();
+ assert!(
+ matches!(err, Response::Error { retry_as_gesture, .. } if retry_as_gesture == (phase == TouchPhase::Down))
+ );
+ assert!(g.dev.touch_rotation.is_none());
+ }
+ std::fs::remove_dir_all(dir).unwrap();
+ }
+
#[test]
fn hid_rotation_requires_fresh_matching_landscape() {
use Rotation::*;
diff --git a/crates/ictl-device/src/hid.rs b/crates/ictl-device/src/hid.rs
index 86a43e8..eb125a4 100644
--- a/crates/ictl-device/src/hid.rs
+++ b/crates/ictl-device/src/hid.rs
@@ -109,6 +109,7 @@ pub struct HidSession {
pub screen: ScreenSize,
/// 界面现在转了多少;点击、拖动的坐标是界面上的,发出去前按它换算回竖放(调用方每次操作前设)
pub rotation: Rotation,
+ contact: Option<(u16, u16)>,
stream: Option<ScreenMediaStream>,
touch: UniversalHidServiceClient<Box<dyn ReadWrite>>,
indigo: IndigoHidClient<Box<dyn ReadWrite>>,
@@ -135,6 +136,7 @@ impl HidSession {
Ok((touch, indigo)) => Ok(Self {
screen: screen.portrait(),
rotation: Rotation::Portrait,
+ contact: None,
stream: Some(stream),
touch,
indigo,
@@ -180,7 +182,9 @@ impl HidSession {
let (hx, hy) = self.hid_point((x, y));
let state = if contact { TOUCHSCREEN_STATE_CONTACT } else { TOUCHSCREEN_STATE_RELEASE };
limit(ictl_l10n::tr!("HID 触摸", "HID touch"), Duration::from_secs(5), async {
- Ok(self.touch.send_touchscreen(state, hx, hy, None).await?)
+ self.touch.send_touchscreen(state, hx, hy, None).await?;
+ self.contact = contact.then_some((hx, hy));
+ Ok(())
})
.await
}
@@ -234,6 +238,13 @@ impl HidSession {
/// 停止屏幕媒体流。必须调用:直接丢掉的话手机端一直挂着这个会话(见 [`crate::Tunnel`])
pub async fn close(mut self) {
+ if let Some((x, y)) = self.contact.take() {
+ let _ = tokio::time::timeout(
+ Duration::from_millis(500),
+ self.touch.send_touchscreen(TOUCHSCREEN_STATE_RELEASE, x, y, None),
+ )
+ .await;
+ }
if let Some(s) = self.stream.take() {
s.stop().await;
}
diff --git a/crates/ictl-device/src/lib.rs b/crates/ictl-device/src/lib.rs
index 8f8881e..cb804c2 100644
--- a/crates/ictl-device/src/lib.rs
+++ b/crates/ictl-device/src/lib.rs
@@ -14,6 +14,7 @@ pub mod apps;
pub mod ddi;
pub mod hid;
mod media;
+mod models;
pub mod oslog;
use std::future::Future;
@@ -33,6 +34,7 @@ use idevice::{
misagent::MisagentClient,
provider::{IdeviceProvider, UsbmuxdProvider},
rsd::RsdHandshake,
+ springboardservices::{InterfaceOrientation, SpringBoardServicesClient},
tcp::handle::AdapterHandle,
usbmuxd::{Connection, UsbmuxdAddr},
};
@@ -192,6 +194,25 @@ impl Rotation {
})
}
+ fn from_interface(orientation: InterfaceOrientation) -> Option<Self> {
+ match orientation {
+ InterfaceOrientation::Portrait => Some(Self::Portrait),
+ InterfaceOrientation::PortraitUpsideDown => Some(Self::UpsideDown),
+ InterfaceOrientation::LandscapeRight => Some(Self::TopToLeft),
+ InterfaceOrientation::LandscapeLeft => Some(Self::TopToRight),
+ InterfaceOrientation::Unknown => None,
+ }
+ }
+
+ pub fn degrees(self) -> u16 {
+ match self {
+ Self::Portrait => 0,
+ Self::TopToRight => 90,
+ Self::UpsideDown => 180,
+ Self::TopToLeft => 270,
+ }
+ }
+
pub fn is_landscape(self) -> bool {
matches!(self, Self::TopToRight | Self::TopToLeft)
}
@@ -407,6 +428,15 @@ impl Device {
.await
}
+ /// SpringBoard reports the four interface orientations separately, even when WDA lacks /rotation.
+ pub async fn interface_rotation(&self) -> Result<Option<Rotation>> {
+ limit(ictl_l10n::tr!("读界面方向", "read interface orientation"), Duration::from_secs(2), async {
+ let mut springboard = SpringBoardServicesClient::connect(&*self.provider).await?;
+ Ok(Rotation::from_interface(springboard.get_interface_orientation().await?))
+ })
+ .await
+ }
+
pub async fn developer_mode_enabled(&self) -> Result<bool> {
limit(ictl_l10n::tr!("查开发者模式", "check Developer Mode"), QUERY, async {
Ok(AmfiClient::connect(&*self.provider).await?.get_developer_mode_status().await?)
@@ -675,6 +705,16 @@ impl Tunnel {
mod tests {
use super::*;
+ #[test]
+ fn springboard_interface_orientation_preserves_all_four_directions() {
+ use InterfaceOrientation::*;
+ assert_eq!(Rotation::from_interface(Portrait), Some(Rotation::Portrait));
+ assert_eq!(Rotation::from_interface(PortraitUpsideDown), Some(Rotation::UpsideDown));
+ assert_eq!(Rotation::from_interface(LandscapeRight), Some(Rotation::TopToLeft));
+ assert_eq!(Rotation::from_interface(LandscapeLeft), Some(Rotation::TopToRight));
+ assert_eq!(Rotation::from_interface(Unknown), None);
+ }
+
/// 真机:摄像头在左(z=270)时,HID 按竖放发 (265,314) 落在了界面的 (314,165),反过来要换算回 (265,314)
#[test]
fn rotation_maps_screen_points_back_to_portrait() {
diff --git a/crates/ictl-device/src/models.rs b/crates/ictl-device/src/models.rs
new file mode 100644
index 0000000..bb6c361
--- /dev/null
+++ b/crates/ictl-device/src/models.rs
@@ -0,0 +1,150 @@
+//! Offline ProductType labels from DeviceKit at fab82bd988405367c915143e293479f481e93ba0.
+//! See THIRD_PARTY.md for the source and license.
+
+use super::DeviceInfo;
+
+impl DeviceInfo {
+ /// Classify even newly released hardware when lockdown reports a valid ProductType.
+ pub fn family(&self) -> &'static str {
+ let id = self.product_type.as_str();
+ let (family, number) = if let Some(suffix) = id.strip_prefix("iPhone") {
+ ("iphone", suffix)
+ } else if let Some(suffix) = id.strip_prefix("iPad") {
+ ("ipad", suffix)
+ } else {
+ return "unknown";
+ };
+ let numeric = |s: &str| !s.is_empty() && s.bytes().all(|b| b.is_ascii_digit());
+ match number.split_once(',') {
+ Some((major, minor)) if numeric(major) && numeric(minor) => family,
+ _ => "unknown",
+ }
+ }
+
+ /// A known marketing name. Callers keep the original ProductType for diagnostics.
+ pub fn model_name(&self) -> Option<&'static str> {
+ Some(match self.product_type.as_str() {
+ "iPhone3,1" | "iPhone3,2" | "iPhone3,3" => "iPhone 4",
+ "iPhone4,1" => "iPhone 4s",
+ "iPhone5,1" | "iPhone5,2" => "iPhone 5",
+ "iPhone5,3" | "iPhone5,4" => "iPhone 5c",
+ "iPhone6,1" | "iPhone6,2" => "iPhone 5s",
+ "iPhone7,2" => "iPhone 6",
+ "iPhone7,1" => "iPhone 6 Plus",
+ "iPhone8,1" => "iPhone 6s",
+ "iPhone8,2" => "iPhone 6s Plus",
+ "iPhone9,1" | "iPhone9,3" => "iPhone 7",
+ "iPhone9,2" | "iPhone9,4" => "iPhone 7 Plus",
+ "iPhone8,4" => "iPhone SE",
+ "iPhone10,1" | "iPhone10,4" => "iPhone 8",
+ "iPhone10,2" | "iPhone10,5" => "iPhone 8 Plus",
+ "iPhone10,3" | "iPhone10,6" => "iPhone X",
+ "iPhone11,2" => "iPhone Xs",
+ "iPhone11,4" | "iPhone11,6" => "iPhone Xs Max",
+ "iPhone11,8" => "iPhone Xʀ",
+ "iPhone12,1" => "iPhone 11",
+ "iPhone12,3" => "iPhone 11 Pro",
+ "iPhone12,5" => "iPhone 11 Pro Max",
+ "iPhone12,8" => "iPhone SE (2nd generation)",
+ "iPhone13,2" => "iPhone 12",
+ "iPhone13,1" => "iPhone 12 mini",
+ "iPhone13,3" => "iPhone 12 Pro",
+ "iPhone13,4" => "iPhone 12 Pro Max",
+ "iPhone14,5" => "iPhone 13",
+ "iPhone14,4" => "iPhone 13 mini",
+ "iPhone14,2" => "iPhone 13 Pro",
+ "iPhone14,3" => "iPhone 13 Pro Max",
+ "iPhone14,6" => "iPhone SE (3rd generation)",
+ "iPhone14,7" => "iPhone 14",
+ "iPhone14,8" => "iPhone 14 Plus",
+ "iPhone15,2" => "iPhone 14 Pro",
+ "iPhone15,3" => "iPhone 14 Pro Max",
+ "iPhone15,4" => "iPhone 15",
+ "iPhone15,5" => "iPhone 15 Plus",
+ "iPhone16,1" => "iPhone 15 Pro",
+ "iPhone16,2" => "iPhone 15 Pro Max",
+ "iPhone17,3" => "iPhone 16",
+ "iPhone17,4" => "iPhone 16 Plus",
+ "iPhone17,1" => "iPhone 16 Pro",
+ "iPhone17,2" => "iPhone 16 Pro Max",
+ "iPhone17,5" => "iPhone 16e",
+ "iPhone18,3" => "iPhone 17",
+ "iPhone18,1" => "iPhone 17 Pro",
+ "iPhone18,2" => "iPhone 17 Pro Max",
+ "iPhone18,4" => "iPhone Air",
+ "iPhone18,5" => "iPhone 17e",
+ "iPhone19,2" => "iPhone 18 Pro",
+ "iPhone19,3" | "iPhone19,7" => "iPhone 18 Pro Max",
+ "iPhone19,4" => "iPhone Duo",
+ "iPad2,1" | "iPad2,2" | "iPad2,3" | "iPad2,4" => "iPad 2",
+ "iPad3,1" | "iPad3,2" | "iPad3,3" => "iPad (3rd generation)",
+ "iPad3,4" | "iPad3,5" | "iPad3,6" => "iPad (4th generation)",
+ "iPad4,1" | "iPad4,2" | "iPad4,3" => "iPad Air",
+ "iPad5,3" | "iPad5,4" => "iPad Air 2",
+ "iPad6,11" | "iPad6,12" => "iPad (5th generation)",
+ "iPad7,5" | "iPad7,6" => "iPad (6th generation)",
+ "iPad11,3" | "iPad11,4" => "iPad Air (3rd generation)",
+ "iPad7,11" | "iPad7,12" => "iPad (7th generation)",
+ "iPad11,6" | "iPad11,7" => "iPad (8th generation)",
+ "iPad12,1" | "iPad12,2" => "iPad (9th generation)",
+ "iPad13,18" | "iPad13,19" => "iPad (10th generation)",
+ "iPad15,7" | "iPad15,8" => "iPad (A16)",
+ "iPad13,1" | "iPad13,2" => "iPad Air (4th generation)",
+ "iPad13,16" | "iPad13,17" => "iPad Air (5th generation)",
+ "iPad14,8" | "iPad14,9" => "iPad Air (11-inch) (M2)",
+ "iPad14,10" | "iPad14,11" => "iPad Air (13-inch) (M2)",
+ "iPad15,3" | "iPad15,4" => "iPad Air (11-inch) (M3)",
+ "iPad15,5" | "iPad15,6" => "iPad Air (13-inch) (M3)",
+ "iPad16,8" | "iPad16,9" => "iPad Air (11-inch) (M4)",
+ "iPad16,10" | "iPad16,11" => "iPad Air (13-inch) (M4)",
+ "iPad2,5" | "iPad2,6" | "iPad2,7" => "iPad mini",
+ "iPad4,4" | "iPad4,5" | "iPad4,6" => "iPad mini 2",
+ "iPad4,7" | "iPad4,8" | "iPad4,9" => "iPad mini 3",
+ "iPad5,1" | "iPad5,2" => "iPad mini 4",
+ "iPad11,1" | "iPad11,2" => "iPad mini (5th generation)",
+ "iPad14,1" | "iPad14,2" => "iPad mini (6th generation)",
+ "iPad16,1" | "iPad16,2" => "iPad mini (A17 Pro)",
+ "iPad6,3" | "iPad6,4" => "iPad Pro (9.7-inch)",
+ "iPad6,7" | "iPad6,8" => "iPad Pro (12.9-inch)",
+ "iPad7,1" | "iPad7,2" => "iPad Pro (12.9-inch) (2nd generation)",
+ "iPad7,3" | "iPad7,4" => "iPad Pro (10.5-inch)",
+ "iPad8,1" | "iPad8,2" | "iPad8,3" | "iPad8,4" => "iPad Pro (11-inch)",
+ "iPad8,5" | "iPad8,6" | "iPad8,7" | "iPad8,8" => "iPad Pro (12.9-inch) (3rd generation)",
+ "iPad8,9" | "iPad8,10" => "iPad Pro (11-inch) (2nd generation)",
+ "iPad8,11" | "iPad8,12" => "iPad Pro (12.9-inch) (4th generation)",
+ "iPad13,4" | "iPad13,5" | "iPad13,6" | "iPad13,7" => "iPad Pro (11-inch) (3rd generation)",
+ "iPad13,8" | "iPad13,9" | "iPad13,10" | "iPad13,11" => "iPad Pro (12.9-inch) (5th generation)",
+ "iPad14,3" | "iPad14,4" => "iPad Pro (11-inch) (4th generation)",
+ "iPad14,5" | "iPad14,6" => "iPad Pro (12.9-inch) (6th generation)",
+ "iPad16,3" | "iPad16,4" => "iPad Pro (11-inch) (M4)",
+ "iPad16,5" | "iPad16,6" => "iPad Pro (13-inch) (M4)",
+ "iPad17,1" | "iPad17,2" => "iPad Pro (11-inch) (M5)",
+ "iPad17,3" | "iPad17,4" => "iPad Pro (13-inch) (M5)",
+ _ => return None,
+ })
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::DeviceInfo;
+
+ #[test]
+ fn marketing_name_and_family_are_independent() {
+ for (id, family, name) in [
+ ("iPhone16,1", "iphone", Some("iPhone 15 Pro")),
+ ("iPad13,1", "ipad", Some("iPad Air (4th generation)")),
+ ("iPad13,2", "ipad", Some("iPad Air (4th generation)")),
+ ("iPad99,1", "ipad", None),
+ ("iPhone99,1", "iphone", None),
+ ("iPhone", "unknown", None),
+ ("iPhone,12", "unknown", None),
+ ("iPad13,1,2", "unknown", None),
+ ("Mac14,2", "unknown", None),
+ ("", "unknown", None),
+ ] {
+ let device = DeviceInfo { product_type: id.into(), ..Default::default() };
+ assert_eq!((device.family(), device.model_name()), (family, name), "{id}");
+ }
+ }
+}
diff --git a/crates/ictl-mcp/src/lib.rs b/crates/ictl-mcp/src/lib.rs
index 565fd97..76f80de 100644
--- a/crates/ictl-mcp/src/lib.rs
+++ b/crates/ictl-mcp/src/lib.rs
@@ -858,7 +858,7 @@ pub fn to_result(r: Response) -> CallToolResult {
Response::Image { jpeg_base64, caption } => {
CallToolResult::success(vec![ContentBlock::image(jpeg_base64, "image/jpeg"), ContentBlock::text(caption)])
}
- Response::Error { message } => CallToolResult::error(vec![ContentBlock::text(message)]),
+ Response::Error { message, .. } => CallToolResult::error(vec![ContentBlock::text(message)]),
}
}
@@ -1005,7 +1005,7 @@ impl McpServer {
}
match self.call(&Request::Settle { max_ms: opts.settle_ms }).await {
Response::Text { text: t, .. } => text += &format!("\n{t}"),
- Response::Error { message } => {
+ Response::Error { message, .. } => {
text += &ictl_l10n::trf!(
"\n(等界面稳定失败:{message})",
"\n(waiting for the screen to settle failed: {message})"
@@ -1022,7 +1022,7 @@ impl McpServer {
text +=
&ictl_l10n::trf!("\n--- 操作后的界面 ---\n{t}", "\n--- Screen after the action ---\n{t}")
}
- Response::Error { message } => {
+ Response::Error { message, .. } => {
text += &ictl_l10n::trf!("\n(读界面失败:{message})", "\n(reading the screen failed: {message})")
}
Response::Image { .. } => {}
@@ -1035,7 +1035,7 @@ impl McpServer {
ContentBlock::image(jpeg_base64, "image/jpeg"),
ContentBlock::text(caption),
]),
- Response::Error { message } => done(vec![ContentBlock::text(ictl_l10n::trf!(
+ Response::Error { message, .. } => done(vec![ContentBlock::text(ictl_l10n::trf!(
"{text}\n(截图失败:{message})",
"{text}\n(screenshot failed: {message})"
))]),
@@ -1089,7 +1089,7 @@ impl McpServer {
lines.push(format!("{n}. {tool} → {text}"));
}
Response::Image { caption, .. } => lines.push(format!("{n}. {tool} → {caption}")),
- Response::Error { message } => {
+ Response::Error { message, .. } => {
lines.push(ictl_l10n::trf!("{n}. {tool} → 出错:{message}", "{n}. {tool} → error: {message}"));
if n < total {
lines.push(ictl_l10n::trf!(
diff --git a/crates/ictl-protocol/src/lib.rs b/crates/ictl-protocol/src/lib.rs
index a15c0bb..24db5fb 100644
--- a/crates/ictl-protocol/src/lib.rs
+++ b/crates/ictl-protocol/src/lib.rs
@@ -196,12 +196,12 @@ pub enum Response {
outcome: Option<Outcome>,
},
/// JPEG base64 + 说明文字(尺寸、放大倍数、坐标换算式)
- Image {
- jpeg_base64: String,
- caption: String,
- },
+ Image { jpeg_base64: String, caption: String },
Error {
message: String,
+ /// The touch Down could not open a HID session and sent no contact report.
+ #[serde(default, skip_serializing_if = "std::ops::Not::not")]
+ retry_as_gesture: bool,
},
}
@@ -225,7 +225,7 @@ impl Response {
Self::Text { text: s.into(), outcome: Some(outcome) }
}
pub fn error(s: impl Into<String>) -> Self {
- Self::Error { message: s.into() }
+ Self::Error { message: s.into(), retry_as_gesture: false }
}
}
@@ -334,7 +334,7 @@ pub async fn open_screen_stream(
.await
.map_err(|_| std::io::Error::new(std::io::ErrorKind::TimedOut, "screen stream: no answer"))??;
Ok(match serde_json::from_str::<Response>(&first).map_err(std::io::Error::other)? {
- Response::Error { message } => Err(message),
+ Response::Error { message, .. } => Err(message),
_ => Ok((r, w)),
})
}
@@ -371,6 +371,8 @@ pub const CANCEL_ON_CLOSE: &str = "cancel_on_close";
/// 请求里带上这个键(值为 UDID):守护进程正在控制的不是这台就不执行。`iphone_batch` 用它防止中途换了设备
/// (自动选设备时拔掉正在控制的那台,会改控另一台)后,剩下的步骤落到另一台上
pub const EXPECT_UDID: &str = "expect_udid";
+/// The live view whose geometry was used to calculate a coordinate.
+pub const EXPECT_VIEW: &str = "expect_view";
/// Request key carrying the client's language (`zh` / `en`). The daemon answers in it; requests without it
/// (older clients) get Chinese, as before. Older daemons ignore the extra key
@@ -392,6 +394,27 @@ pub async fn call_expecting(
req: &Request,
timeout: Option<std::time::Duration>,
expect_udid: Option<&str>,
+) -> std::io::Result<Response> {
+ exchange_on(socket, req, timeout, expect_udid, None).await
+}
+
+/// Send a coordinate action only if this device and its measured geometry still match.
+pub async fn call_in_view(
+ socket: &std::path::Path,
+ req: &Request,
+ timeout: Option<std::time::Duration>,
+ udid: &str,
+ view: &str,
+) -> std::io::Result<Response> {
+ exchange_on(socket, req, timeout, Some(udid), Some(view)).await
+}
+
+async fn exchange_on(
+ socket: &std::path::Path,
+ req: &Request,
+ timeout: Option<std::time::Duration>,
+ expect_udid: Option<&str>,
+ expect_view: Option<&str>,
) -> std::io::Result<Response> {
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
let exchange = async {
@@ -401,6 +424,9 @@ pub async fn call_expecting(
if let Some(o) = v.as_object_mut() {
o.insert(CANCEL_ON_CLOSE.into(), true.into());
o.insert(LANG.into(), ictl_l10n::lang().code().into());
+ if let Some(view) = expect_view {
+ o.insert(EXPECT_VIEW.into(), view.into());
+ }
if let Some(u) = expect_udid {
o.insert(EXPECT_UDID.into(), u.into());
}
diff --git a/crates/ictl-wda/src/client.rs b/crates/ictl-wda/src/client.rs
index 352d3a7..04d0b83 100644
--- a/crates/ictl-wda/src/client.rs
+++ b/crates/ictl-wda/src/client.rs
@@ -3,7 +3,7 @@
use std::time::Duration;
use base64::Engine;
-use ictl_device::ScreenSize;
+use ictl_device::{Rotation, ScreenSize};
use serde_json::{Value, json};
use crate::http::Transport;
@@ -112,6 +112,7 @@ pub struct WdaClient<T> {
session: Option<String>,
/// `/wda/screen` 第一次给的尺寸(当时的方向)。当前方向下的宽高见 [`Self::view`]
screen: Option<ScreenSize>,
+ rotation_unsupported: bool,
/// 本客户端(对应一次 WDA 启动)是否确认过一次「确实没锁屏」,确认后 `/wda/locked` 就可信了
lock_state_trusted: bool,
/// 点击前后要恢复的等待设置(第一次点击时读一次)
@@ -129,6 +130,7 @@ impl<T: Transport> WdaClient<T> {
transport,
session: None,
screen: None,
+ rotation_unsupported: false,
lock_state_trusted: false,
idle_baseline: None,
idle_current: None,
@@ -160,6 +162,10 @@ impl<T: Transport> WdaClient<T> {
message: msg.lines().next().unwrap_or_default().to_owned(),
});
}
+ // Older runners may return a JSON 404 without a W3C value.error.
+ if status >= 400 {
+ return Err(WdaError::Remote { kind: "http".into(), message: status.to_string() });
+ }
Ok(v)
}
@@ -228,6 +234,28 @@ impl<T: Transport> WdaClient<T> {
Ok(self.call("GET", "/status", None, Duration::from_secs(5)).await?["value"]["ready"] == true)
}
+ /// Read the WDA screen size again, including changes to Display Zoom.
+ pub async fn measure_screen(&mut self) -> Result<ScreenSize> {
+ let v = self.get("/wda/screen").await?;
+ let s = &v["screenSize"];
+ let positive = |key: &str| s[key].as_f64().filter(|n| n.is_finite() && *n > 0.0);
+ let size = positive("width")
+ .zip(positive("height"))
+ .map(|(width, height)| ScreenSize { width, height })
+ .ok_or_else(|| {
+ WdaError::Unavailable(ictl_l10n::tr!("/wda/screen 尺寸无效", "Invalid /wda/screen dimensions").into())
+ })?;
+ self.screen = Some(size);
+ Ok(size)
+ }
+
+ pub async fn base_screen_size(&mut self) -> Result<ScreenSize> {
+ match self.screen {
+ Some(s) => Ok(s),
+ None => self.measure_screen().await,
+ }
+ }
+
/// 当前方向下的屏幕点尺寸(转屏后宽高跟着变)
pub async fn screen_size(&mut self) -> Result<ScreenSize> {
Ok(self.view().await?.screen)
@@ -237,23 +265,7 @@ impl<T: Transport> WdaClient<T> {
/// 尺寸缓存的是问的那一刻的方向,转屏后不换算的话截图会被压扁、屏幕下半截的元素被当成屏幕外。
/// 问不到方向(旧版 WDA 等)就按缓存的尺寸、方向未知(不换算元素坐标)
pub async fn view(&mut self) -> Result<elements::View> {
- let base = match self.screen {
- Some(s) => s,
- None => {
- let v = self.get("/wda/screen").await?;
- let s = &v["screenSize"];
- let size = match (s["width"].as_f64(), s["height"].as_f64()) {
- (Some(width), Some(height)) => ScreenSize { width, height },
- _ => {
- return Err(WdaError::Unavailable(
- ictl_l10n::tr!("/wda/screen 没有 screenSize", "/wda/screen has no screenSize").into(),
- ));
- }
- };
- self.screen = Some(size);
- size
- }
- };
+ let base = self.base_screen_size().await?;
Ok(match self.orientation().await {
Ok(o) => elements::View { screen: o.orient(base), orientation: Some(o) },
Err(e) => {
@@ -280,6 +292,41 @@ impl<T: Transport> WdaClient<T> {
})
}
+ /// Older WDA versions lack /rotation. Remember an unsupported route for this runner;
+ /// the regular /orientation endpoint folds opposite directions into the same string.
+ async fn interface_rotation(&mut self, fallback: impl Future<Output = Option<Rotation>>) -> Option<Rotation> {
+ if !self.rotation_unsupported {
+ match self.rotation().await {
+ Ok(r) => return Some(r),
+ Err(WdaError::Remote { kind, message })
+ if matches!(kind.as_str(), "unknown command" | "unknown method" | "unsupported operation")
+ || (kind == "http" && matches!(message.as_str(), "404" | "405")) =>
+ {
+ self.rotation_unsupported = true;
+ }
+ Err(_) => return None,
+ }
+ }
+ 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.
+ pub async fn display_sample(
+ &mut self,
+ previous: Option<u16>,
+ gesture_start: bool,
+ 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) {
+ self.measure_screen().await
+ } else {
+ self.base_screen_size().await
+ };
+ (size.ok().map(ScreenSize::portrait), rotation)
+ }
+
/// 前台界面的方向
pub async fn orientation(&mut self) -> Result<elements::Orientation> {
let v = self.in_session("GET", "/orientation", None, Duration::from_secs(10)).await?;
@@ -741,6 +788,70 @@ mod tests {
}
}
+ #[tokio::test]
+ async fn display_poll_remeasures_size_only_when_needed() {
+ let session = (200, r#"{"sessionId":"A"}"#);
+ 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 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),
+ ] {
+ let (size, rotation) = w.display_sample(previous, start, async { panic!("unexpected fallback") }).await;
+ assert_eq!(rotation, Some(expected));
+ assert_eq!(size.unwrap().width, 393.);
+ }
+ let paths: Vec<_> = m.seen.lock().unwrap().iter().map(|s| s.1.clone()).collect();
+ assert_eq!(
+ paths,
+ [
+ "/session",
+ "/session/A/rotation",
+ "/wda/screen",
+ "/session/A/rotation",
+ "/session/A/rotation",
+ "/wda/screen",
+ "/session/A/rotation",
+ "/wda/screen"
+ ]
+ );
+ }
+
+ #[tokio::test]
+ async fn legacy_http_404_is_distinct_from_a_transient_rotation_failure() {
+ let m = Mock::with(&[
+ (200, r#"{"sessionId":"A"}"#),
+ (500, r#"{"value":"runner busy"}"#),
+ (200, r#"{"value":{"z":90}}"#),
+ (404, r#"{"value":{"message":"Unhandled endpoint"}}"#),
+ ]);
+ let mut w = WdaClient::new(&m);
+ assert_eq!(w.interface_rotation(async { panic!("500 is not a missing route") }).await, None);
+ assert_eq!(w.interface_rotation(async { panic!("supported route") }).await, Some(Rotation::TopToRight));
+ assert_eq!(w.interface_rotation(async { Some(Rotation::UpsideDown) }).await, Some(Rotation::UpsideDown));
+ }
+
+ #[tokio::test]
+ async fn legacy_wda_uses_a_fresh_interface_rotation_without_retrying_the_missing_route() {
+ let m = Mock::with(&[
+ (200, r#"{"sessionId":"A"}"#),
+ (404, r#"{"value":{"error":"unknown command"}}"#),
+ (200, r#"{"value":{"screenSize":{"width":393,"height":852}}}"#),
+ ]);
+ let mut w = WdaClient::new(&m);
+ let (size, rotation) = w.display_sample(None, false, async { Some(Rotation::UpsideDown) }).await;
+ assert_eq!(size.unwrap().width, 393.);
+ assert_eq!(rotation, Some(Rotation::UpsideDown));
+ assert_eq!(w.interface_rotation(async { Some(Rotation::TopToLeft) }).await, Some(Rotation::TopToLeft));
+ assert_eq!(w.interface_rotation(async { None }).await, None);
+ assert_eq!(m.seen.lock().unwrap().len(), 3);
+ }
+
#[tokio::test]
async fn session_is_recreated_once_after_invalid_session() {
let m = Mock::with(&[
diff --git a/tests/viewer/actions.test.mjs b/tests/viewer/actions.test.mjs
new file mode 100644
index 0000000..8079fc0
--- /dev/null
+++ b/tests/viewer/actions.test.mjs
@@ -0,0 +1,111 @@
+import assert from 'node:assert/strict';
+import { readFileSync } from 'node:fs';
+import { test } from 'node:test';
+import { runInNewContext } from 'node:vm';
+
+const html = readFileSync(new URL('../../apps/iphone-control/src/viewer.html', import.meta.url), 'utf8');
+
+// Exercise the embedded page's handlers with their network and DOM boundaries replaced.
+function handlers(names, context) {
+ const functions = names.map(name => {
+ const match = html.match(new RegExp(`^(?:async )?function ${name}\\([^]*?^}`, 'm'));
+ assert.ok(match, name);
+ return match[0];
+ });
+ return runInNewContext(functions.join('\n') + '\n({' + names.join(', ') + '})', context);
+}
+
+const noop = () => {};
+const common = { performance, tr: String, show: noop, renderFeed: noop, refreshStatusSoon: noop, feedEpoch: 1 };
+
+test('two rejected stale downs keep live touch available for the next gesture', async () => {
+ for (const reply of [new Error('HTTP 409'), { ok: false }, { ok: false, retry_as_gesture: false }]) {
+ const S = { liveTouch: true };
+ const T = { q: [], busy: false, fails: 0, gesture: 0 };
+ const context = {
+ ...common, S, T, W: { on: false }, down: null, loadInfo: noop, fingerUp: noop, hideHoverDot: noop,
+ async api() { if (reply instanceof Error) throw reply; return reply; },
+ };
+ const { touchPump } = handlers(['touchPump'], context);
+ for (let i = 0; i < 2; i++) {
+ context.down = { legacy: false, gesture: T.gesture + 1 };
+ T.q.push({ phase: 'down', device: 'phone', view: 'old', epoch: 1, gesture: ++T.gesture });
+ await touchPump();
+ assert.equal(T.fails, 0);
+ assert.equal(context.down, null, 'do not replay a rejected press');
+ }
+ assert.equal(S.liveTouch, true);
+ context.api = async (url, body) => { assert.equal(body.view, 'new'); return { ok: true }; };
+ T.q.push({ phase: 'down', device: 'phone', view: 'new', epoch: 1, gesture: ++T.gesture });
+ await touchPump();
+ assert.equal(S.liveTouch, true);
+ }
+});
+
+test('two confirmed HID connection failures still enable whole-gesture fallback', async () => {
+ const S = { liveTouch: true };
+ const T = { q: [], busy: false, fails: 0, gesture: 0 };
+ const context = { ...common, S, T, down: null, fingerUp: noop, api: async () => ({ ok: false, retry_as_gesture: true }) };
+ const { touchPump } = handlers(['touchPump'], context);
+ for (let i = 0; i < 2; i++) {
+ context.down = { legacy: false, gesture: T.gesture + 1 };
+ T.q.push({ phase: 'down', device: 'phone', view: 'same', epoch: 1, gesture: ++T.gesture });
+ await touchPump();
+ assert.equal(context.down.legacy, true);
+ }
+ assert.equal(S.liveTouch, false);
+});
+
+test('a late transport error drops only moves from the original gesture', async () => {
+ let rejectFirst;
+ const pending = new Promise((_, reject) => { rejectFirst = reject; });
+ const T = { q: [], busy: false, fails: 0, gesture: 1 };
+ const sent = [];
+ const context = {
+ ...common, T, S: { liveTouch: true }, down: { gesture: 1 },
+ async api(_url, event) {
+ sent.push([event.phase, event.view]);
+ if (sent.length === 1) await pending;
+ return { ok: true };
+ },
+ };
+ const { touchPump } = handlers(['touchPump'], context);
+ const first = { device: 'phone', epoch: 1, gesture: 1, view: 'first' };
+ const next = { ...first, gesture: 2, view: 'next' };
+ T.q.push({ ...first, phase: 'down' });
+ const draining = touchPump();
+ T.q.push({ ...first, phase: 'move' }, { ...first, phase: 'up' }, { ...next, phase: 'down' }, { ...next, phase: 'move' });
+ T.gesture = 2;
+ context.down = { gesture: 2, legacy: false };
+ rejectFirst(new Error('connection lost'));
+ await draining;
+ assert.deepEqual(sent, [['down', 'first'], ['up', 'first'], ['down', 'next'], ['move', 'next']]);
+ assert.equal(context.down.legacy, false);
+ assert.equal(T.fails, 0);
+});
+
+test('a named element can be tapped without a rendered frame and targets its device', async () => {
+ const row = { label: 'Settings', type: 'Button', x: 5, y: 10, width: 20, height: 20 };
+ const S = { mode: 'live', udid: 'phone', display: null, elements: [row, row], elState: 'ok' };
+ const list = {}, count = {};
+ const requests = [], marks = [];
+ let geometry = null;
+ const { tapElement, renderElements } = handlers(['renderElements', 'tapElement', 'api', 'act'], {
+ ...common, S, LANG: 'en', dims: () => geometry, guarded: () => false, highlight: noop, esc: String,
+ drawMark: (kind, who, point) => marks.push([kind, who, point.x, point.y]), round1: n => n,
+ $: id => ({ '#el-q': { value: '' }, '#elements': list, '#el-count': count })[id],
+ fetch: async (url, opts) => {
+ requests.push([url, opts.headers['X-Ictl-Device'], JSON.parse(opts.body)]);
+ return { ok: true, json: async () => ({ ok: true }) };
+ },
+ });
+ renderElements();
+ assert.match(list.innerHTML, /data-action="tap-el"/);
+ assert.doesNotMatch(list.innerHTML, / disabled/);
+ await tapElement(1);
+ assert.deepEqual(requests, [['/api/tap_element', 'phone', { text: 'Settings', index: 1 }]]);
+ assert.deepEqual(marks, []);
+ geometry = { W: 390, H: 844 };
+ await tapElement(0);
+ assert.deepEqual(marks, [['tap', 'user', 15, 20]]);
+});
diff --git a/website/en/guide/cli.md b/website/en/guide/cli.md
index 6adc9a1..7a0ce6c 100644
--- a/website/en/guide/cli.md
+++ b/website/en/guide/cli.md
@@ -23,7 +23,7 @@ These go before the command, for example `iphone-control --socket /path/ctl.sock
## Host software updates
-`iphone-control update check [--json]` and **About & updates** in Viewer share the local release cache. A source build without a publisher makes no network request. A failed check keeps the previous successful result. A red dot on **About & updates** indicates a newer stable release. Open the panel to see its version and copy the command for your installation. For Homebrew, the tap determines when the upgrade is available. For Debian or Ubuntu, download the listed package before running the command.
+`iphone-control update check [--json]` and **About & updates** in Viewer share the local release cache. A source build without a publisher makes no network request. A failed check keeps the previous successful result. A red dot on the ⓘ button next to **Settings** indicates a newer stable release. Open it to read the version and release excerpt in the selected language and copy the command for your installation. For Homebrew, the tap determines when the upgrade is available. For Debian or Ubuntu, download the listed package before running the command.
Viewer listens on loopback. Other users on the same host can see installation information and request a version check. Installation, rollback and policy changes use the local CLI.
@@ -90,7 +90,7 @@ See [Auto-unlock](./auto-unlock). `--device` takes a UDID or name, and the devic
|---|---|
| `notify-test [event]` | Send test notifications: one per event type, or one type (`resign`, `session`, `pin`, `pin-recovered`, `unlock`, `offline`, `online`) |
| `wda-bridge [--port <port>]` | Expose WDA on `127.0.0.1` (default port 8100) for other tools. WDA has no authentication and every local user can reach it, so stop it when done |
-| `viewer [--port <port>]` | Control page in the browser at `http://127.0.0.1:8200/` (default port), in English or Chinese (follows `IPHONE_CONTROL_LANG`, switchable on the page). **Screen:** the live picture works like a touchscreen: click to tap, drag to swipe, hold to long-press, scroll with the mouse wheel or trackpad, plus a text field and the hardware buttons. On iOS 27 and later the finger follows the pointer as it moves (over CoreDevice HID, which keeps the phone awake until 30 seconds after the last touch); older versions get the whole gesture on release. Everything goes through the daemon like an MCP call, so it queues with the agent and unlocks the phone first. On iOS 27 and later the picture is the phone's own video; otherwise it comes from WDA (none until WDA is ready), as H.264 or MJPEG; see [Picture](#viewer-picture) below. **Device panel:** state and readiness checks, installed apps, on-screen elements. The page follows the device the daemon controls: switch on the page or anywhere else, and the picture and panels move over; see [Several Devices](./multi-device#control-page). **AI tasks:** type a task and a local agent carries it out (Claude Code or Codex, whichever is on `PATH`; picked on the page). You can pause, take over and hand back, or stop it, and it asks on the page before paying, deleting or sending messages. Every local user can reach the port, so stop it when done |
+| `viewer [--port <port>]` | Control page in the browser at `http://127.0.0.1:8200/` (default port), in English or Chinese (follows `IPHONE_CONTROL_LANG`, switchable on the page). **Screen:** the live picture works like a touchscreen: click to tap, drag to swipe, hold to long-press, scroll with the mouse wheel or trackpad, plus a text field and the hardware buttons. On iOS 27 and later the finger follows the pointer as it moves (over CoreDevice HID, which keeps the phone awake until 30 seconds after the last touch); older versions get the whole gesture on release. Everything goes through the daemon like an MCP call, so it queues with the agent and unlocks the phone first. On iOS 27 and later the picture is the phone's own video; otherwise it comes from WDA (none until WDA is ready), as H.264 or MJPEG; see [Picture](#viewer-picture) below. Touch is available when the frame matches the measured size and orientation. After rotating or switching devices, start a new gesture on the updated picture. Settings at the bottom of the sidebar controls the theme and text size. The picture has its own zoom controls. **Device panel:** state and readiness checks, installed apps, on-screen elements. The page follows the device the daemon controls: switch on the page or anywhere else, and the picture and panels move over; see [Several Devices](./multi-device#control-page). **AI tasks:** type a task and a local agent carries it out (Claude Code or Codex, whichever is on `PATH`; picked on the page). You can pause, take over and hand back, or stop it, and it asks on the page before paying, deleting or sending messages. Every local user can reach the port, so stop it when done |
The `debug` subcommand for diagnostics isn't compiled by default; see the [contributing guide](https://github.com/Derrors/iphone-control/blob/main/CONTRIBUTING.md#testing-on-a-real-phone).
diff --git a/website/guide/cli.md b/website/guide/cli.md
index aa42e45..de47f20 100644
--- a/website/guide/cli.md
+++ b/website/guide/cli.md
@@ -23,7 +23,7 @@
## 主机软件更新
-`iphone-control update check [--json]` 和 Viewer 的「关于与更新」读取同一份本地缓存。未绑定发布者的源码构建不会联网;网络检查失败会保留上次成功的结果。有更新时,「关于与更新」按钮会显示红点,打开即可查看版本号,复制适合当前安装方式的升级命令。Homebrew 以对应 tap 提供的版本为准。Debian 或 Ubuntu 用户先下载面板指定的安装包,再运行命令。
+`iphone-control update check [--json]` 和 Viewer 的「关于与更新」读取同一份本地缓存。未绑定发布者的源码构建不会联网;网络检查失败会保留上次成功的结果。有更新时,侧栏底部「设置」旁的 ⓘ 会显示红点。点开可查看版本号和当前界面语言的发行说明摘录,复制适合当前安装方式的升级命令。Homebrew 以对应 tap 提供的版本为准。Debian 或 Ubuntu 用户先下载面板指定的安装包,再运行命令。
Viewer 只监听本机回环地址。同机其他用户也能查看安装信息、触发版本检查。安装、回滚和更改策略都通过本机 CLI 执行。
@@ -90,7 +90,7 @@ Viewer 只监听本机回环地址。同机其他用户也能查看安装信息
|---|---|
| `notify-test [事件]` | 发测试通知:每类事件各一条,或只发一类(`resign`、`session`、`pin`、`pin-recovered`、`unlock`、`offline`、`online`) |
| `wda-bridge [--port <端口>]` | 把 WDA 桥接到 `127.0.0.1`,端口默认 8100,给别的工具用。WDA 没有认证,本机任何用户都能连上,用完就停 |
-| `viewer [--port <端口>]` | 浏览器里的控制台,地址 `http://127.0.0.1:8200/`(默认端口),中英文(默认跟着 `IPHONE_CONTROL_LANG`,页面上可切换)。**画面:** 实时画面像触摸屏一样用:点一下是点击,拖动是滑动,按住是长按,滚动鼠标滚轮或触控板也能滚动页面,另有输入框和硬件键。iOS 27 起手指跟着鼠标实时移动(经 CoreDevice HID,最后一次触摸后 30 秒内手机保持亮屏);更低的版本在松开后发整段手势。操作都和 MCP 调用一样经守护进程,和 agent 的操作排队,并先自动解锁。iOS 27 及以上画面直接用手机自己的视频;其余来自 WDA(WDA 没就绪时没有画面),是 H.264 或 MJPEG,见下面的[画面编码](#viewer-picture)。**设备面板:** 状态和就绪检查、已安装的 App、屏幕上的元素。页面跟着守护进程控制的设备走,在页面上或别处切换设备,画面和面板都会跟过去,见[多台设备](./multi-device#control-page)。**AI 任务:** 写下任务,交给本机的 agent 执行(PATH 里有的 Claude Code 或 Codex,在页面上选)。可以暂停、接管后交还、停止;付款、删除、发消息之前它会在页面上请你确认。本机任何用户都能连上这个端口,用完就停 |
+| `viewer [--port <端口>]` | 浏览器里的控制台,地址 `http://127.0.0.1:8200/`(默认端口),中英文(默认跟着 `IPHONE_CONTROL_LANG`,页面上可切换)。**画面:** 实时画面像触摸屏一样用:点一下是点击,拖动是滑动,按住是长按,滚动鼠标滚轮或触控板也能滚动页面,另有输入框和硬件键。iOS 27 起手指跟着鼠标实时移动(经 CoreDevice HID,最后一次触摸后 30 秒内手机保持亮屏);更低的版本在松开后发整段手势。操作都和 MCP 调用一样经守护进程,和 agent 的操作排队,并先自动解锁。iOS 27 及以上画面直接用手机自己的视频;其余来自 WDA(WDA 没就绪时没有画面),是 H.264 或 MJPEG,见下面的[画面编码](#viewer-picture)。画面与设备实测的尺寸、方向一致时可以点按。转屏或换机后,请在新画面上重新操作。侧栏底部的「设置」可调整主题和字号,画面缩放单独调整。**设备面板:** 状态和就绪检查、已安装的 App、屏幕上的元素。页面跟着守护进程控制的设备走,在页面上或别处切换设备,画面和面板都会跟过去,见[多台设备](./multi-device#control-page)。**AI 任务:** 写下任务,交给本机的 agent 执行(PATH 里有的 Claude Code 或 Codex,在页面上选)。可以暂停、接管后交还、停止;付款、删除、发消息之前它会在页面上请你确认。本机任何用户都能连上这个端口,用完就停 |
调试用的 `debug` 子命令默认不编译,见[贡献指南](https://github.com/Derrors/iphone-control/blob/main/CONTRIBUTING.md#testing-on-a-real-phone)。