/** * 验证"一指拖节点 / 两指平移画布"。 * * ★ 每次跑之前先**删掉所有旧会议、新建一个**。 * 原因:旧会议的节点坐标是历史遗留(可能被拖到画布角落、跑出屏幕), * 测试点就会落在空白处 —— 上一轮我就是这么得出"节点拖不动"的错误结论的。 * 新建的会议用的是当前默认坐标,位置可预测。 * * adb 模拟不了真两指,所以两指那项只做说明性检查(代码里已按手指数分支)。 * * 用法: node scripts/device-meeting-drag.mjs */ import { spawnSync } from 'node:child_process'; import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; const SERIAL = process.argv[2] || 'emulator-5556'; const ADB = process.env.ADB || 'C:\\Android\\Sdk\\platform-tools\\adb.exe'; const OUT = path.join(os.tmpdir(), 'meeting-shots'); fs.mkdirSync(OUT, { recursive: true }); const sh = (...a) => spawnSync(ADB, ['-s', SERIAL, ...a], { encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 }); const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); async function shot(n) { sh('shell', 'screencap', '-p', '/sdcard/_s.png'); const dst = path.join(OUT, `${n}.png`); sh('pull', '/sdcard/_s.png', dst); return dst; } /** 去掉状态栏(时钟会变),只比较下面的内容区,避免"时钟变了"被误判成"画面变了" */ const bodyHash = (p) => { const b = fs.readFileSync(p); // PNG 没法简单裁,就按字节采样并跳过前 8KB(状态栏在图像顶部, // PNG 是逐行压缩的,跳过开头基本能避开它) let h = 0; for (let i = 8192; i < b.length; i += 53) h = (h * 31 + b[i]) >>> 0; return h.toString(16); }; async function tap(x, y, w = 1400) { sh('shell', 'input', 'tap', String(x), String(y)); await sleep(w); } const api = (p, opt) => sh('shell', `curl -s --max-time 10 ${opt || ''} http://127.0.0.1:5199${p}`).stdout || ''; console.log('清掉旧会议,建一个新的(坐标可预测)…'); const list = api('/api/meetings'); try { for (const m of JSON.parse(list).meetings || []) { api(`/api/meetings/${m.id}`, `-X DELETE`); } } catch { /* 没有就没有 */ } api('/api/meetings', `-X POST -H 'Content-Type: application/json' -d '{"name":"DragTest"}'`); await sleep(800); console.log('导航到会议编辑器…'); sh('shell', 'input', 'keyevent', 'KEYCODE_WAKEUP'); sh('shell', 'svc', 'power', 'stayon', 'true'); sh('shell', 'am', 'start', '-n', 'com.doubao.lynxclone/.MainActivity'); await sleep(6000); await tap(45, 105); // 抽屉 await tap(250, 561, 2500); // 会议模式 await tap(300, 300, 3500); // 打开会议 const before = await shot('40-before'); console.log(' 拖动前已截图'); // 新默认:n_start 在 (12,120)dp。密度 2.0、画布区从屏幕 y≈150px 开始。 // 所以节点大致在屏幕 (24..256, 390..566),取中心 (140, 470)。 console.log('① 一指拖「初始输入」节点'); sh('shell', 'input', 'swipe', '140', '470', '420', '700', '900'); await sleep(2500); const afterDrag = await shot('41-after-node-drag'); console.log('② 一指拖空白处(应什么都不发生)'); sh('shell', 'input', 'swipe', '600', '250', '380', '420', '900'); await sleep(2000); const afterEmpty = await shot('42-after-empty-drag'); const h0 = bodyHash(before); const h1 = bodyHash(afterDrag); const h2 = bodyHash(afterEmpty); console.log(''); console.log(` 拖动前 : ${h0}`); console.log(` 拖节点后 : ${h1} ${h0 === h1 ? '❌ 没变 → 节点没拖动' : '✅ 变了 → 节点动了'}`); console.log(` 拖空白后 : ${h2} ${h1 === h2 ? '✅ 没变 → 空白处不动作(正确)' : '❌ 变了 → 空白处也动了'}`); console.log('截图在', OUT);