42 lines
2.5 KiB
TypeScript
42 lines
2.5 KiB
TypeScript
import { createDriver } from '../drivers/factory';
|
|
|
|
(async () => {
|
|
const d = createDriver();
|
|
await d.createSession();
|
|
const KW = process.env.LIGHT_CARD || 'Color Bulb 7E';
|
|
const W = 1080, H = 2400;
|
|
const sleep = (m: number) => new Promise((r) => setTimeout(r, m));
|
|
const sub = async (): Promise<string> => {
|
|
const s = await d.getSource();
|
|
const t = Array.from(s.matchAll(/text="([^"]+)"/g)).map((m) => m[1]);
|
|
const i = t.findIndex((x) => x.includes(KW));
|
|
return i >= 0 ? t[i + 1] || '' : '';
|
|
};
|
|
// dump y1650-1825 区间所有节点(class + bounds),找会随拖动移动的子节点
|
|
const dumpTrack = async (y1lo: number, y1hi: number): Promise<string[]> => {
|
|
const s = await d.getSource();
|
|
return Array.from(s.matchAll(/<[^>]*class="([^"]+)"[^>]*bounds="\[(\d+),(\d+)\]\[(\d+),(\d+)\]"[^>]*>/g))
|
|
.map((m) => ({ cls: m[1].split('.').pop(), x1: +m[2], y1: +m[3], x2: +m[4], y2: +m[5] }))
|
|
.filter((b) => b.y1 >= y1lo && b.y2 <= y1hi)
|
|
.map((b) => `${b.cls} [${b.x1},${b.y1}][${b.x2},${b.y2}] w${b.x2 - b.x1}`);
|
|
};
|
|
try {
|
|
await d.dismissPopupIfPresent(); await d.goBackToHomepage(); await sleep(800);
|
|
let el: string | null = null;
|
|
for (let i = 0; i < 10; i++) { el = await d.findElementRaw('-android uiautomator', `new UiSelector().textContains("${KW}")`).catch(() => null); if (el) break; await d.swipe(540, 1500, 540, 700, 0.4).catch(() => {}); await sleep(800); }
|
|
const r = await d.getElementRect(el!); await d.tap(r.x + r.width / 2, r.y + r.height / 2); await sleep(2500);
|
|
const src = await d.getSource();
|
|
const pw = Array.from(src.matchAll(/clickable="true"[^>]*?bounds="\[(\d+),(\d+)\]\[(\d+),(\d+)\]"/g))
|
|
.map((m) => { const x1 = +m[1], y1 = +m[2], x2 = +m[3], y2 = +m[4]; return { w: x2 - x1, h: y2 - y1, cx: (x1 + x2) / 2, cy: (y1 + y2) / 2 }; })
|
|
.filter((b) => b.w >= 150 && b.w <= 320 && b.h >= 150 && b.h <= 320 && Math.abs(b.cx - W / 2) < W * 0.15 && b.cy > H * 0.4);
|
|
if (!/\d+\s*%/.test(await sub()) && pw.length) { await d.tap(Math.round(pw[0].cx), Math.round(pw[0].cy)); await sleep(3500); }
|
|
|
|
const left = 58, right = 1022, y = 1737;
|
|
await d.swipe(540, y, left, y, 0.8); await sleep(1800);
|
|
console.log('色温拖最左, track节点=' + JSON.stringify(await dumpTrack(1620, 1860)));
|
|
await d.swipe(left, y, right, y, 0.8); await sleep(1800);
|
|
console.log('色温拖最右, track节点=' + JSON.stringify(await dumpTrack(1620, 1860)));
|
|
} catch (e: any) { console.error('FAIL:', e.message); }
|
|
finally { await d.destroySession(); }
|
|
})();
|