Files
AutoDY/utils/index.js
2024-09-27 01:26:21 +08:00

55 lines
1.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const exec = require('child_process').exec;
const config = require('../config');
class Utils{
/**
* 运行命令
* @param cmdStr
* @returns {Promise<unknown>}
*/
execShell (cmdStr) {
return new Promise((resolve,reject)=> {
exec(cmdStr, function(err,stdout,stderr) {
if(err) {
console.log('shell is run: '+ stderr);
} else {
resolve(stdout)
}
});
})
}
/**
* 检查是否安装 ADBKeyboard.apk app
* 否则无法输入中文
* @constructor
*/
async CheckAdbKeyboard() {
let res = await this.execShell(config.baseShell.adbkeyboard);
if (res.indexOf("com.android.adbkeyboard") > -1) {
return true
} else {
console.error("请先安装 ADBKeyboard.apk")
return false
}
}
/**
* 检查是否安装adb
* @returns {Promise<void>}
* @constructor
*/
async CheckInstallAdb() {
let res = await this.execShell(config.baseShell.adb)
if (res.indexOf("Android Debug Bridge version") > -1) {
return true
} else {
console.error("请先在PC电脑上安装adb工具")
return false
}
}
}
module.exports = new Utils();