From 5e0a7d55568893f64e01c7a04fa2abc314a29bf7 Mon Sep 17 00:00:00 2001 From: butubb <1422726308@qq.com> Date: Tue, 15 Sep 2026 13:24:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E5=B1=8F=E5=B9=95):=20=E4=B8=80=E9=94=AE?= =?UTF-8?q?=E6=81=AF=E5=B1=8F=E4=B8=8D=E5=86=8D=E5=94=A4=E9=86=92=E5=B7=B2?= =?UTF-8?q?=E7=9C=A0=E8=AE=BE=E5=A4=87=20+=20=E3=80=8C=E4=BF=9D=E6=8C=81?= =?UTF-8?q?=E4=BA=AE=E5=B1=8F=E3=80=8D=E5=AF=B9=E4=B8=8D=E5=85=85=E7=94=B5?= =?UTF-8?q?=E7=9A=84=E8=AE=BE=E5=A4=87=E7=94=9F=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 用户反馈两条: 1. 监控页「一键息屏」像是把设备**唤醒**了(按钮行为"反"); 2. 任务里的「保持亮屏」没用。 根因: 1. `POST /api/device/screen_all` 的 off 分支发 `input keyevent 26`(KEYCODE_POWER)—— 那是电源键**开关**:对亮着的设备是熄屏,对**已经息屏的设备反而是唤醒**。 2. `keep_screen` 只发 `svc power stayon true`,它管的是「**充电时**屏幕常亮」 (stay_on_while_plugged_in)。设备走 WiFi 跑任务、没插充电器 → 完全不生效。 修法: - 息屏改用 `KEYCODE_SLEEP(223)`(单向:只熄不亮)。 - 保持亮屏改成把系统**息屏超时**顶到最大(`settings put system screen_off_timeout 2147483647`)+ 顺带 `svc power stayon true` + 立刻 `KEYCODE_WAKEUP` 唤醒一次; `mode=off` 时写回原值(进入时读一次记在内存;进程重启丢了记录就写回 10 分钟兜底, `settings get` 返回 "null" 的机型也走兜底)。 - 文案/文档同步:编辑器里的步骤说明、TASK_DEV 步骤表、API.md 的接口行为。 自测(按用户要求不动机器):py_compile / node --check 通过;用假设备对象断言命令序列—— 保持亮屏发 `settings get` → `stayon true` → `put …2147483647` → `keyevent 224` 并记住原值; 恢复写回原值 60000 且清空备份;原值为 null 时兜底 600000。 --- doc/API.md | 2 +- doc/TASK_DEV.md | 2 +- static/admin/editor.js | 2 +- tasks/generic/task.py | 35 ++++++++++++++++++++++++++++++----- web/monitor.py | 7 +++++-- 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/doc/API.md b/doc/API.md index 193bfd4..8e57a71 100644 --- a/doc/API.md +++ b/doc/API.md @@ -321,7 +321,7 @@ | `POST /api/stop_all` | — | 停止全部 | | `POST /api/device/clear_error` | `{"serial":"…"}` | 运行中/重试等待中拒绝清理 | | `POST /api/device/clear_all_errors` | — | 跳过 running/connecting | -| `POST /api/device/screen_all` | `{"mode":"on"\|"off", "serials":[…]}` | 不传 serials 则对全部在线设备 | +| `POST /api/device/screen_all` | `{"mode":"on"\|"off", "serials":[…]}` | 不传 serials 则对全部在线设备。**熄屏是单向的**(`KEYCODE_SLEEP`),不会把已息屏的设备唤醒;亮屏用 `KEYCODE_WAKEUP` + `dismiss-keyguard` | | `POST /api/scan_foreground` | — | 已扫描中时返回 `{"ok":false}`(**HTTP 200**) | | `POST /api/device/locate` | `{"serial":"…","show":true}` | `show=true` 时在设备上打开 `/locate` | | `POST /api/device/locate/stop` | `{"serial":"…"}` | 结束定位 | diff --git a/doc/TASK_DEV.md b/doc/TASK_DEV.md index b7fc697..106d8ea 100644 --- a/doc/TASK_DEV.md +++ b/doc/TASK_DEV.md @@ -118,7 +118,7 @@ from .generic import task # 触发 @register_task(当前唯一任务类型) | 2 | `stop_app` | 结束 App | `package` | — | — | `app_stop`(`am force-stop`,下次打开是冷启动) | | 3 | `screen_on` | 亮屏 | — | — | — | `d.unlock()`(息屏时唤醒并滑动解锁) | | 4 | `screen_off` | 息屏 | — | — | — | `d.screen_off()` | -| 5 | `keep_screen` | 保持亮屏 | `mode`("on") | — | — | `mode="off"` → 恢复自动息屏;否则 `svc power stayon true`(充电时常亮,适合长任务) | +| 5 | `keep_screen` | 保持亮屏 | `mode`("on") | — | — | `mode="off"` → 恢复自动息屏;否则**把系统息屏超时顶到最大**(`screen_off_timeout=2147483647`)+ `svc power stayon true` + 唤醒一次。⚠️ 只发 `svc power stayon true` 对**没插充电器**的设备(走 WiFi 的那些)**完全无效**——它管的是"充电时屏幕常亮",2026-09-14 就是因此被反馈"保持亮屏没用" | | 6 | `key_event` | 按键 | `key`("back") | — | — | `d.press(key)`;**值直传,无白名单校验** | | 7 | `swipe` | 滑动 | `direction`("up") | `duration_min`(0.25)、`duration_max`(0.50) | — | 时长取随机值;up = 中轴从 0.8h → 0.2h(down 反向,left/right 同理);**非法 direction 静默不滑** | | 8 | `swipe_until` | 滑动直到元素 | `selector_type`、`selector_value` | `direction`("up")、`max_swipes`(8)、`click_when_found`(True) | — | 每轮滑动后 sleep 0.5s;命中即(可选)点击并返回 True;**只有 `direction="down"` 才是向下滑**,其余按上滑 | diff --git a/static/admin/editor.js b/static/admin/editor.js index 2b6b057..257df75 100644 --- a/static/admin/editor.js +++ b/static/admin/editor.js @@ -291,7 +291,7 @@ var _stepEditor={ h+='