From fbdc5ad73c834d9ec8d5be72b2d6d2efa2b81684 Mon Sep 17 00:00:00 2001 From: Lei PAN Date: Wed, 25 Oct 2023 16:03:23 +0200 Subject: [PATCH] use adb to start browser --- src/workers/CommandorPage.js | 49 ++++++++++++++++++++--------- src/workers/SlidingCaptchaSolver.js | 5 --- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/src/workers/CommandorPage.js b/src/workers/CommandorPage.js index 0fafa91..b8ab9d5 100644 --- a/src/workers/CommandorPage.js +++ b/src/workers/CommandorPage.js @@ -55,6 +55,18 @@ function log(message) { appointmentLogger.log({level: "info", message: message}) } +async function clearApp(device, packageName) { + let cmd = `adb -s ${device.serial()} shell pm clear ${packageName}` + logWithDevice("cmd is " + cmd, device) + await exec(cmd); +} + +async function exceutShellCmd(device, cmdToExecut) { + let cmd = `adb -s ${device.serial()} shell ${cmdToExecut}` + logWithDevice("cmd is " + cmd, device) + await exec(cmd); +} + function logWithDevice(message, device) { appointmentLogger.log({level: "info", message: device.model() + ":" + device.serial() + ":" + message}) } @@ -146,8 +158,11 @@ class CommandorPage { async loadPage() { logWithDevice(this.device.serial() + ":loadPage() called, with port:" + this.port, this.device); try { + // let cmd = 'adb -s ' + device.serial() + " forward tcp:" + attributedPort + " localabstract:chrome_devtools_remote"; + await exceutShellCmd(this.device, " forward tcp:" + this.port + " localabstract:chrome_devtools_remote") + await delay(1 * 1000); await this.startPage(this.device, this.browserPackageName + "/com.google.android.apps.chrome.Main") - await delay(5 * 1000); + await delay(4 * 1000); } catch (e) { console.log(e) this.isTerminated = true; @@ -810,7 +825,8 @@ class CommandorPage { this.isPhoneInput = false; this.isPasspordInput = false; // this.disconnectBrowser(); - await this.device.shell("pm clear " + this.browserPackageName) + await clearApp(this.device, this.browserPackageName) + // await this.device.shell("pm clear " + this.browserPackageName) await delay(1000) this.isTerminated = true; // await this.checkResultWithOcr(); @@ -986,9 +1002,10 @@ class CommandorPage { // await this.device.shell("input tap " + 530 + " " + 970) } else if (this.device.model() === "ONEPLUS A6000") await this.device.shell("input tap " + 530 + " " + 1064) - else if (this.device.model() === "KB2003") + else if (this.device.model() === "KB2003" || this.device.model() === "DE2117") { await this.tapForDevice(this.device, 500, 1200) - else + await this.tapForDevice(this.device, 500, 1120) + } else try { await this.tapForDevice(this.device, 500, 1120) // await this.device.shell("input tap " + 500 + " " + 1120) @@ -1008,11 +1025,11 @@ class CommandorPage { break; case OCRResult.BRAVE_NOTIFICATION: logWithDevice("BRAVE_NOTIFICATION", this.device) - if (this.device.model() === "21091116C") - await this.device.shell("input tap " + 540 + " " + 1611) - else if (this.device.model() === "22041219PG") - await this.device.shell("input tap " + 530 + " " + 1600) - else + if (this.device.model() === "21091116C") { + await this.tapForDevice(this.device, 540, 1611) + } else if (this.device.model() === "22041219PG") { + await this.tapForDevice(this.device, 530, 1600) + } else await this.tapForDevice(this.device, 500, 1680) // await this.device.shell("input tap " + 500 + " " + 1680) await delay(2000); @@ -1210,11 +1227,11 @@ class CommandorPage { async enableDisableAirPlanMode() { logWithDevice("will enable/disable airplane mode", this.device) try { - await this.device.shell("cmd connectivity airplane-mode enable") - // await this.device.shell("adb shell settings put global airplane_mode_on 1") + // await this.device.shell("cmd connectivity airplane-mode enable") + await exceutShellCmd(this.device, "cmd connectivity airplane-mode enable") await delay(1000) - // await this.device.shell("adb shell settings put global airplane_mode_on 0") - await this.device.shell("cmd connectivity airplane-mode disable") + await exceutShellCmd(this.device, "cmd connectivity airplane-mode disable") + // await this.device.shell("cmd connectivity airplane-mode disable") await delay(2000) } catch (e) { try { @@ -1239,8 +1256,12 @@ class CommandorPage { await this.device.shell("input tap " + 411 + " " + 1977) } else if (this.browserPackageName.includes("brave") && this.device.model() === "ONEPLUS A6000") { await this.device.shell("input tap " + 411 + " " + 1970) + } else if (this.browserPackageName.includes("brave") && this.device.model() === "ASUS_X00QD") { + await this.device.shell("input tap " + 411 + " " + 1970) } else if (this.browserPackageName.includes("brave") && this.device.model() === "22041219PG") { - await this.device.shell("input tap " + 411 + " " + 2020) + await this.tapForDevice(this.device, 411, 2020) + } else if (this.browserPackageName.includes("brave") && this.device.model() === "21091116C") { + await this.tapForDevice(this.device, 411, 2020) } else { await this.tapForDevice(this.device, 411, 2100) } diff --git a/src/workers/SlidingCaptchaSolver.js b/src/workers/SlidingCaptchaSolver.js index 31b402f..1988579 100644 --- a/src/workers/SlidingCaptchaSolver.js +++ b/src/workers/SlidingCaptchaSolver.js @@ -102,11 +102,6 @@ class SlidingCaptchaSolver { let result = response.data; console.log(result); await callback(result); - // console.log("will delete png file: " + fileName); - // await fs.unlink(fileName, (err) => { - // if (err) throw err; - // console.log(fileName + ' was deleted'); - // }) } else { console.log("error"); await callback([]);