UNPKG

@aiot-toolkit/emulator

Version:

vela emulator tool.

65 lines (63 loc) 2.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var adbMiwt = _interopRequireWildcard(require("@miwt/adb")); var _common = _interopRequireDefault(require("./common")); var _Vvd = require("../typing/Vvd"); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /** * @deprecated 不在使用 */ class GoldfishInstance extends _common.default { uninstall() { throw new Error('Method not implemented.'); } closeApp() { throw new Error('Method not implemented.'); } imageType = (() => _Vvd.VelaImageType.DEV)(); static appDir = '/data/app'; static emulatorStartedFlag = /(NSH)/; async install(rpkPath, opt) { // 基于 vapp 启动的应用只需要将 rpk 解压到指定的目录下 rpkPath = rpkPath || `${this.appDir}/${opt.packageName}.rpk`; const targetPath = `${this.appDir}/${opt.packageName}`; const mkdirCmd = `adb -s ${this.sn} shell mkdir ${targetPath}`; this.logger(`Excuting: ${mkdirCmd}`); await adbMiwt.execAdbCmdAsync(mkdirCmd); const unzipCmd = `adb -s ${this.sn} shell unzip -o ${rpkPath} -d ${targetPath}`; this.logger(`Excuting: ${unzipCmd}`); await adbMiwt.execAdbCmdAsync(unzipCmd); } /** * 在模拟器中启动快应用 * 通过vapp命令启动,调试时需额外配置--jsdebugger参数 * @param options */ async startApp(packageName) { let debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; try { let vappCmd = `adb -s ${this.sn} shell vapp app/${packageName} &`; if (debug) { vappCmd = `adb -s ${this.sn} shell vapp --jsdebugger=10.0.2.15:101 app/${packageName} &`; } this.logger(`Excuting: ${vappCmd}`); adbMiwt.execAdbCmd(vappCmd, { stdio: 'ignore', encoding: 'utf-8' }); } catch (e) { this.logger(`Failed to startup quickapp: ${e.message}`); } } async reloadApp(appName) { let debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; await this.reboot(); await this.startApp(appName, debug); } } var _default = exports.default = GoldfishInstance;