25 lines
1.3 KiB
TypeScript
25 lines
1.3 KiB
TypeScript
import { createDriver } from '../drivers/factory';
|
|
import { enterPairingMode } from '../utils/common/relay.helper';
|
|
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
const dump = async (d: any): Promise<string[]> => [...new Set((Array.from((await d.getSource()).matchAll(/text="([^"]+)"/g)) as any[]).map((m) => m[1]).filter((t: string) => t.trim()))] as string[];
|
|
(async () => {
|
|
const d = createDriver();
|
|
await d.createSession();
|
|
try {
|
|
await enterPairingMode('hub3').catch((e) => console.log('relay 失败:', e.message));
|
|
console.log('已按 ch9+10 3s');
|
|
await sleep(2000);
|
|
for (const t of ['Connect device', 'Connect Device', 'Connect Devices']) {
|
|
const b = await d.findElementRaw('-android uiautomator', `new UiSelector().text("${t}")`).catch(() => null);
|
|
if (b) { await d.tapElement(b); console.log(`已点 ${t}`); break; }
|
|
}
|
|
for (let i = 0; i < 12; i++) {
|
|
await sleep(5000);
|
|
const texts = await dump(d);
|
|
console.log(`+${(i + 1) * 5}s: ${JSON.stringify(texts)}`);
|
|
if (/Configure Wi-?Fi|SSID|Select Device|Pick a room|added successfully/i.test(texts.join(' '))) { console.log('==关键页=='); break; }
|
|
}
|
|
} catch (e: any) { console.error('FAIL:', e.message); }
|
|
finally { await d.destroySession(); }
|
|
})();
|