UNPKG

multi-automator

Version:
100 lines (99 loc) 3.71 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DEVICE_TMP_DIR = exports.checkEnv = void 0; /** * @desc: env * @author: john_chen * @date: 2025.03.05 */ const config_1 = require("../config"); const adb = __importStar(require("./adb")); const DEVICE_TMP_DIR = '/data/local/tmp'; exports.DEVICE_TMP_DIR = DEVICE_TMP_DIR; const REQUIRED_JARS = ['bundle.jar', 'uiautomator-stub.jar']; const REQUIRED_BINS = ['atx-agent']; // const REQUIRED_BINS = ['atx-agent', 'minicap', 'minitouch']; const dependAppMap = { uiautomator: { packageName: 'com.github.uiautomator', apkName: 'app-uiautomator.apk' }, uiautomatorTest: { packageName: 'com.github.uiautomator.test', apkName: 'app-uiautomator-test.apk' }, adbkeyboard: { packageName: 'com.android.adbkeyboard', apkName: 'ADBKeyboard.apk' } }; /** * 检查环境 */ async function checkEnv(deviceId) { config_1.logger.info('[android.env.checkEnv]'); try { // 串行检查设备连接状态 await adb.checkConnect(deviceId); await adb.checkDeviceSet(deviceId); // 并行检查依赖项 await Promise.all([ checkApp(deviceId).catch(err => { throw new Error(`App check failed: ${err.message}`); }), checkJar(deviceId).catch(err => { throw new Error(`Jar check failed: ${err.message}`); }), checkBin(deviceId).catch(err => { throw new Error(`Bin check failed: ${err.message}`); }) ]); } catch (err) { throw new Error(`Environment check failed: ${err.message}`); } } exports.checkEnv = checkEnv; async function checkApp(deviceId) { config_1.logger.info('[android.env.checkApp]'); await Promise.all(Object.values(dependAppMap).map(async ({ packageName }) => { if (!await adb.isInstalled(deviceId, packageName)) { throw new Error(`[android.checkDependApp] app ${packageName} is not installed`); } })); } async function checkJar(deviceId) { config_1.logger.info('[android.env.checkJar]'); await Promise.all(REQUIRED_JARS.map(async (jarName) => { const jarPath = `${DEVICE_TMP_DIR}/${jarName}`; if (!await adb.fileExist(deviceId, jarPath)) { throw new Error(`atx 依赖文件 ${jarName} 不存在`); } })); } async function checkBin(deviceId) { config_1.logger.info('[android.env.checkBin]'); await Promise.all(REQUIRED_BINS.map(async (binName) => { const binPath = `${DEVICE_TMP_DIR}/${binName}`; if (!await adb.fileExist(deviceId, binPath)) { throw new Error(`${binName} 不存在`); } })); }