@aiot-toolkit/emulator 2.0.3-beta.6 → 2.0.3-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +133 -8
- package/lib/emulatorutil/EmulatorLog.js +22 -18
- package/lib/emulatorutil/constants.d.ts +18 -5
- package/lib/emulatorutil/constants.js +94 -53
- package/lib/emulatorutil/index.d.ts +3 -2
- package/lib/emulatorutil/index.js +38 -8
- package/lib/emulatorutil/running.d.ts +24 -0
- package/lib/emulatorutil/running.js +108 -0
- package/lib/emulatorutil/skinLayoutParser.d.ts +14 -0
- package/lib/emulatorutil/skinLayoutParser.js +111 -0
- package/lib/index.d.ts +5 -5
- package/lib/index.js +76 -26
- package/lib/instance/common.d.ts +38 -39
- package/lib/instance/common.js +141 -223
- package/lib/instance/dev.d.ts +7 -42
- package/lib/instance/dev.js +54 -235
- package/lib/instance/index.d.ts +6 -5
- package/lib/instance/index.js +51 -35
- package/lib/instance/miwear.d.ts +14 -75
- package/lib/instance/miwear.js +93 -370
- package/lib/instance/pre.d.ts +11 -3
- package/lib/instance/pre.js +55 -93
- package/lib/instance/pre5.d.ts +11 -0
- package/lib/instance/pre5.js +38 -0
- package/lib/static/avdConfigIni.json +5 -5
- package/lib/typing/Instance.d.ts +30 -15
- package/lib/typing/Instance.js +13 -6
- package/lib/typing/Vvd.d.ts +105 -0
- package/lib/typing/Vvd.js +31 -0
- package/lib/utils/file.d.ts +0 -0
- package/lib/utils/file.js +1 -0
- package/lib/utils/index.js +86 -100
- package/lib/vvd/index.d.ts +107 -0
- package/lib/vvd/index.js +698 -0
- package/lib/vvd/logcat.d.ts +16 -0
- package/lib/vvd/logcat.js +67 -0
- package/package.json +9 -8
- package/lib/avd/index.d.ts +0 -28
- package/lib/avd/index.js +0 -173
- package/lib/emulatorutil/EmulatorCmd.d.ts +0 -9
- package/lib/emulatorutil/EmulatorCmd.js +0 -226
- package/lib/instance/preDev.d.ts +0 -53
- package/lib/instance/preDev.js +0 -249
- package/lib/typing/Avd.d.ts +0 -23
- package/lib/typing/Avd.js +0 -8
package/lib/instance/miwear.js
CHANGED
|
@@ -1,379 +1,102 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
17
5
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
const ColorConsole_1 = __importDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
39
|
-
const adbMiwt = __importStar(require("@miwt/adb"));
|
|
40
|
-
const child_process_1 = require("child_process");
|
|
41
|
-
const readline_1 = __importDefault(require("readline"));
|
|
42
|
-
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
43
|
-
const os_1 = __importDefault(require("os"));
|
|
44
|
-
const path_1 = __importDefault(require("path"));
|
|
45
|
-
const ws_1 = __importStar(require("ws"));
|
|
46
|
-
const Instance_1 = require("../typing/Instance");
|
|
47
|
-
const utils_1 = require("../utils");
|
|
48
|
-
const emulatorutil_1 = require("../emulatorutil");
|
|
49
|
-
const common_1 = __importDefault(require("./common"));
|
|
50
|
-
const MAX_RECONNECT_COUNT = 8;
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _ColorConsole = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
|
|
8
|
+
var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _utils = require("../utils");
|
|
11
|
+
var _common = _interopRequireDefault(require("./common"));
|
|
12
|
+
var _emulatorutil = require("../emulatorutil");
|
|
13
|
+
var _Vvd = require("../typing/Vvd");
|
|
14
|
+
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); }
|
|
15
|
+
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; }
|
|
16
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
51
17
|
/**
|
|
52
18
|
* MiwearInstance
|
|
53
19
|
* 针对 Vela正式版(4.0)的镜像
|
|
54
20
|
*/
|
|
55
|
-
class MiwearInstance extends
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* 启动模拟器
|
|
94
|
-
* 1. 通过options生成模拟器的启动命令
|
|
95
|
-
* 2. 执行启动命令
|
|
96
|
-
* 3. 判断模拟器是否启动成功
|
|
97
|
-
* 3.1 若disableNSH=true,输出流中匹配到/quickapp_rpk_installer_init|rpk installer init done/,认为模拟器启动成功了
|
|
98
|
-
* 3.2 若disableNSH=false,认为8s过后模拟器启动成功了
|
|
99
|
-
* @param options
|
|
100
|
-
* @returns
|
|
101
|
-
*/
|
|
102
|
-
startGoldfish(options) {
|
|
103
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
104
|
-
const { origin = Instance_1.IStartOrigin.Terminal } = options;
|
|
105
|
-
// 启动模拟器的命令和参数
|
|
106
|
-
const cmd = emulatorutil_1.EmulatorCmd.createMiwerCmd(options, this.sdkHome, this.avdHome);
|
|
107
|
-
if (!cmd)
|
|
108
|
-
return;
|
|
109
|
-
const spawnArgs = cmd.split(' ');
|
|
110
|
-
const spawnBin = spawnArgs.shift();
|
|
111
|
-
ColorConsole_1.default.log(`### Emulator ### Start CMD miwear: ${cmd}`);
|
|
112
|
-
const func = this instanceof MiwearInstance ? emulatorutil_1.EmulatorLog.rpkIsStart : emulatorutil_1.EmulatorLog.devIsStart;
|
|
113
|
-
return new Promise((resolve) => {
|
|
114
|
-
var _a, _b;
|
|
115
|
-
this.goldfishProcess = (0, child_process_1.spawn)(spawnBin, spawnArgs, {
|
|
116
|
-
stdio: 'pipe',
|
|
117
|
-
shell: true,
|
|
118
|
-
cwd: this.sdkHome
|
|
119
|
-
});
|
|
120
|
-
if (origin === Instance_1.IStartOrigin.Terminal) {
|
|
121
|
-
process.stdin.pipe(this.goldfishProcess.stdin);
|
|
122
|
-
}
|
|
123
|
-
// 利用 readline 接口可解决子进程日志换行的问题
|
|
124
|
-
this.stdoutReadline = readline_1.default.createInterface({
|
|
125
|
-
input: this.goldfishProcess.stdout
|
|
126
|
-
});
|
|
127
|
-
this.stderrReadline = readline_1.default.createInterface({
|
|
128
|
-
input: this.goldfishProcess.stderr
|
|
129
|
-
});
|
|
130
|
-
// 监听模拟器的退出事件
|
|
131
|
-
this.goldfishProcess.on('exit', (code) => {
|
|
132
|
-
ColorConsole_1.default.error(`### Emulator ### Goldfish emulator exited with code ${code}`);
|
|
133
|
-
if (options.exitCallback) {
|
|
134
|
-
options.exitCallback(code);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
// 监听错误流
|
|
138
|
-
(_a = this.stderrReadline) === null || _a === void 0 ? void 0 : _a.on('line', (data) => {
|
|
139
|
-
const stderrCb = options.stderrCallback || console.log;
|
|
140
|
-
stderrCb(data.toString());
|
|
141
|
-
});
|
|
142
|
-
// 监听输出流
|
|
143
|
-
(_b = this.stdoutReadline) === null || _b === void 0 ? void 0 : _b.on('line', (data) => {
|
|
144
|
-
const msg = data.toString();
|
|
145
|
-
const stdoutCb = options.stdoutCallback || console.log;
|
|
146
|
-
stdoutCb(msg);
|
|
147
|
-
// 应用安装成功,则启动它
|
|
148
|
-
if (emulatorutil_1.EmulatorLog.inStallIsFinshe(msg)) {
|
|
149
|
-
ColorConsole_1.default.info(`### Emulator ### Install quickapp successfully`);
|
|
150
|
-
this.launchQuickapp();
|
|
151
|
-
}
|
|
152
|
-
// 匹配到,则认为模拟器启动成功
|
|
153
|
-
if (func(msg)) {
|
|
154
|
-
ColorConsole_1.default.info(`### Emulator ### Goldfish emulator starts successfully`);
|
|
155
|
-
resolve();
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* 在模拟器中启动快应用
|
|
163
|
-
* 1. 检查release目录是否有打包好的rpk
|
|
164
|
-
* 2. 检查当前是否为调试模式.
|
|
165
|
-
* 若是,将debugger_ip.cfg推到模拟器的/data/目录下
|
|
166
|
-
* 若否,则要删除模拟器中已有的data/debugger_ip.cfg
|
|
167
|
-
* 3. 调用installRpkToAppList将当前快应用安装到模拟器的应用列表中
|
|
168
|
-
* @param options
|
|
169
|
-
*/
|
|
170
|
-
startupQuickApp(options) {
|
|
171
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
-
var _a;
|
|
173
|
-
const { package: appPackageName } = this.projectInfo;
|
|
174
|
-
const releaseDir = this.isRpk
|
|
175
|
-
? path_1.default.resolve(this.projectPath, '../')
|
|
176
|
-
: path_1.default.resolve(this.projectPath, ((_a = this.params.compilerOption) === null || _a === void 0 ? void 0 : _a.releasePath) || 'dist');
|
|
177
|
-
const files = fs_extra_1.default
|
|
178
|
-
.readdirSync(releaseDir)
|
|
179
|
-
.filter((item) => item.includes(appPackageName) && item.endsWith('.rpk'));
|
|
180
|
-
if (files.length === 0) {
|
|
181
|
-
ColorConsole_1.default.error(`### Emulator the rpk does not exist`);
|
|
182
|
-
}
|
|
183
|
-
const rpkPath = path_1.default.resolve(releaseDir, files[0]);
|
|
184
|
-
// 调试模式需要push一个文件至miwear中
|
|
185
|
-
if (options.devtool) {
|
|
186
|
-
const debuggerCfgFile = path_1.default.join(__dirname, '../static/debugger_ip.cfg');
|
|
187
|
-
yield adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} push ${debuggerCfgFile} /data/debugger_ip.cfg`);
|
|
188
|
-
}
|
|
189
|
-
else {
|
|
190
|
-
yield adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} shell rm /data/debugger_ip.cfg`);
|
|
191
|
-
}
|
|
192
|
-
this.pushAndInstall(rpkPath, this.appDir);
|
|
193
|
-
// this.launchQuickapp()
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* 将快应用安装到模拟器的应用列表
|
|
198
|
-
* 1. 使用adb push将打包好的rpk推到模拟器的/data/quickapp/app/
|
|
199
|
-
* 2. nsh中调用pm install命令安装应用
|
|
200
|
-
* @param rpkPath rpk的绝对目录
|
|
201
|
-
* @param targetDir 要将rpk放到模拟器的哪个目录下
|
|
202
|
-
*/
|
|
203
|
-
pushAndInstall(rpkPath, targetDir) {
|
|
204
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
-
const { package: packageName } = this.projectInfo;
|
|
206
|
-
// 1. adb push应用的rpk
|
|
207
|
-
const targetPath = `${targetDir}/${packageName}.rpk`;
|
|
208
|
-
const pushCmd = `adb -s ${this.sn} push "${rpkPath}" ${targetPath}`;
|
|
209
|
-
ColorConsole_1.default.info(`### Emulator ### Excuting cmd: ${pushCmd}`);
|
|
210
|
-
yield adbMiwt.execAdbCmdAsync(pushCmd);
|
|
211
|
-
const installCmd = `adb -s ${this.sn} shell pm install ${targetPath}`;
|
|
212
|
-
ColorConsole_1.default.info(`### Emulator ### Excuting cmd: ${installCmd}`);
|
|
213
|
-
yield adbMiwt.execAdbCmdAsync(installCmd);
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
/** 使用am start启动快应用 */
|
|
217
|
-
launchQuickapp() {
|
|
218
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
219
|
-
const { package: packageName } = this.projectInfo;
|
|
220
|
-
const startCmd = `adb -s ${this.sn} shell am start ${packageName}`;
|
|
221
|
-
ColorConsole_1.default.info(`### Emulator ### Excuting cmd: ${startCmd}`);
|
|
222
|
-
adbMiwt.execAdbCmdAsync(startCmd);
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
/** 连接模拟器中的调试服务,创建debugSocket
|
|
226
|
-
* 主要用于热更新时,通过debugSocket通知调试服务更新页面
|
|
227
|
-
* 设置了重连机制,会重复连接8次
|
|
228
|
-
*/
|
|
229
|
-
initDebugSocket() {
|
|
230
|
-
return new Promise((resolve, reject) => {
|
|
231
|
-
var _a;
|
|
232
|
-
if (this.debugSocket && this.debugSocket.OPEN) {
|
|
233
|
-
return resolve();
|
|
234
|
-
}
|
|
235
|
-
this.debugSocket = new ws_1.default(`ws://localhost:${(_a = this.startOptions) === null || _a === void 0 ? void 0 : _a.debugPort}`);
|
|
236
|
-
this.debugSocket.onopen = () => {
|
|
237
|
-
ColorConsole_1.default.info(`### Emulator debugSocket connect success`);
|
|
238
|
-
return resolve();
|
|
239
|
-
};
|
|
240
|
-
this.debugSocket.onerror = (errorEvent) => {
|
|
241
|
-
var _a;
|
|
242
|
-
// 重连机制
|
|
243
|
-
(_a = this.debugSocket) === null || _a === void 0 ? void 0 : _a.terminate();
|
|
244
|
-
if (this.reconnectCount < MAX_RECONNECT_COUNT) {
|
|
245
|
-
ColorConsole_1.default.info(`### Emulator the ${this.reconnectCount + 1}th time to reconnect debug server`);
|
|
246
|
-
this.reconnectCount++;
|
|
247
|
-
setTimeout(() => this.initDebugSocket(), 2000);
|
|
248
|
-
}
|
|
249
|
-
else {
|
|
250
|
-
this.debugSocket = undefined;
|
|
251
|
-
this.reconnectCount = 0;
|
|
252
|
-
return reject(`### Emulator debugSocket connect failed, ${errorEvent.message}`);
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
this.debugSocket.onclose = (closeEvent) => {
|
|
256
|
-
this.debugSocket = undefined;
|
|
257
|
-
this.reconnectCount = 0;
|
|
258
|
-
ColorConsole_1.default.log(`### Emulator debugSocket connect close: ${closeEvent.reason}`);
|
|
259
|
-
};
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
/** 通知模拟器更新
|
|
263
|
-
* 1. 确保已经成功连接模拟器中的调试服务
|
|
264
|
-
* 2. 使用adb push将build文件下的内容推到/data/quickapp/app/${packageName}
|
|
265
|
-
* 3. 发送Page.reload命令给调试服务,通知更新
|
|
266
|
-
*/
|
|
267
|
-
handleUpdate() {
|
|
268
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
269
|
-
var _a, _b;
|
|
270
|
-
try {
|
|
271
|
-
this.reconnectCount = 0;
|
|
272
|
-
yield this.initDebugSocket();
|
|
273
|
-
// 1. 将整包重新推到miwear中(TODO:增量更新)
|
|
274
|
-
yield this.pushBuild();
|
|
275
|
-
// 2. 下发CDP命令给调试服务告知刷新
|
|
276
|
-
if (((_a = this.debugSocket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN) {
|
|
277
|
-
(_b = this.debugSocket) === null || _b === void 0 ? void 0 : _b.send(JSON.stringify({ id: 10000, method: 'Page.reload', params: {} }));
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
catch (e) {
|
|
281
|
-
ColorConsole_1.default.error(`${e}`);
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
/** 热更新时push目录 */
|
|
286
|
-
pushBuild() {
|
|
287
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
288
|
-
const { package: appPackageName } = this.projectInfo;
|
|
289
|
-
// windows平台adb push时无法使用通配符,需另外处理;
|
|
290
|
-
// 项目路径包含空格时,无法通过加引号来使用 * 通配符
|
|
291
|
-
if (os_1.default.platform() === 'win32' || this.projectPath.indexOf(' ') > 0) {
|
|
292
|
-
const rmCmd = `adb -s ${this.sn} shell rm -r ${this.appDir}/${appPackageName}`;
|
|
293
|
-
yield adbMiwt.execAdbCmdAsync(rmCmd);
|
|
294
|
-
const sourcePath = path_1.default.resolve(this.projectPath, './build');
|
|
295
|
-
const pushCmd = `adb -s ${this.sn} push "${sourcePath}" ${this.appDir}/${appPackageName}`;
|
|
296
|
-
yield adbMiwt.execAdbCmdAsync(pushCmd);
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
const sourcePath = path_1.default.resolve(this.projectPath, './build/*');
|
|
300
|
-
yield adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} push ${sourcePath} ${this.appDir}/${appPackageName}`);
|
|
301
|
-
}
|
|
302
|
-
ColorConsole_1.default.info(`### Emulator push to ${this.appDir}/${appPackageName} successfully`);
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
/** 通过命令行启动时,在watich模式下监听websocket消息,
|
|
306
|
-
* 在文件发生变动时,重新启动应用
|
|
307
|
-
*/
|
|
308
|
-
restart() {
|
|
309
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
310
|
-
this.pushAndReloadApp();
|
|
311
|
-
});
|
|
312
|
-
}
|
|
313
|
-
/** 在模拟器中重启快应用(基于am命令,需要保证镜像中已经有am功能)
|
|
314
|
-
* 1. 使用adb push将build文件下的内容推到/data/quickapp/app/${packageName}
|
|
315
|
-
* 2. nsh中执行am stop命令退出快应用
|
|
316
|
-
* 3. nsh中执行am start命令启动快应用
|
|
317
|
-
*/
|
|
318
|
-
pushAndReloadApp() {
|
|
319
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
-
// 1. 将整包重新推到miwear中(TODO:增量更新)
|
|
321
|
-
yield this.pushBuild();
|
|
322
|
-
yield this.reloadApp();
|
|
323
|
-
});
|
|
324
|
-
}
|
|
325
|
-
reloadApp() {
|
|
326
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
327
|
-
try {
|
|
328
|
-
const { package: appPackageName } = this.projectInfo;
|
|
329
|
-
// 2. 执行am stop和am start命令
|
|
330
|
-
const stopCmd = `adb -s ${this.sn} shell am stop ${appPackageName}`;
|
|
331
|
-
yield adbMiwt.execAdbCmdAsync(stopCmd);
|
|
332
|
-
ColorConsole_1.default.info(`### Emulator stop ${appPackageName} successfully`);
|
|
333
|
-
// 这里是为了等am stop命令清除资源等
|
|
334
|
-
yield (0, utils_1.sleep)(500);
|
|
335
|
-
const startCmd = `adb -s ${this.sn} shell am start ${appPackageName}`;
|
|
336
|
-
yield adbMiwt.execAdbCmdAsync(startCmd);
|
|
337
|
-
ColorConsole_1.default.info(`### Emulator start ${appPackageName} successfully`);
|
|
338
|
-
}
|
|
339
|
-
catch (e) {
|
|
340
|
-
ColorConsole_1.default.error(`${e}`);
|
|
341
|
-
}
|
|
342
|
-
});
|
|
21
|
+
class MiwearInstance extends _common.default {
|
|
22
|
+
imageType = (() => _Vvd.VelaImageType.REL)();
|
|
23
|
+
appDir = '/data/quickapp/app';
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 使用 pm 安装快应用
|
|
27
|
+
* @param targeRpk 快应用的rpk文件路径
|
|
28
|
+
*/
|
|
29
|
+
async install(targeRpk) {
|
|
30
|
+
adbMiwt.execAdbCmd(`adb -s ${this.sn} shell pm install ${targeRpk}`);
|
|
31
|
+
return new Promise((resolve, reject) => {
|
|
32
|
+
const func = msg => {
|
|
33
|
+
if (_emulatorutil.EmulatorLog.inStallIsFinshe(msg)) {
|
|
34
|
+
clearTimeout(timer);
|
|
35
|
+
_ColorConsole.default.info(`### Emulator ### Install ${targeRpk} successfully`);
|
|
36
|
+
resolve();
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
let timer = setTimeout(() => {
|
|
40
|
+
this.stdoutReadline.off('line', func);
|
|
41
|
+
_ColorConsole.default.error(`### Emulator ### Install ${targeRpk} timeout`);
|
|
42
|
+
reject('Install timeout');
|
|
43
|
+
}, 2 * 60 * 1000);
|
|
44
|
+
this.stdoutReadline.on('line', func);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** 使用 am start 启动快应用 */
|
|
49
|
+
async startApp(packageName) {
|
|
50
|
+
let debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
51
|
+
// 调试模式需要push一个文件至miwear中
|
|
52
|
+
if (debug) {
|
|
53
|
+
const debuggerCfgFile = _path.default.join(__dirname, '../static/debugger_ip.cfg');
|
|
54
|
+
await adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} push ${debuggerCfgFile} /data/debugger_ip.cfg`);
|
|
55
|
+
} else {
|
|
56
|
+
await adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} shell rm /data/debugger_ip.cfg`);
|
|
343
57
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
58
|
+
const startCmd = `adb -s ${this.sn} shell am start ${packageName}`;
|
|
59
|
+
_ColorConsole.default.info(`### Emulator ### Excuting cmd: ${startCmd}`);
|
|
60
|
+
await adbMiwt.execAdbCmdAsync(startCmd);
|
|
61
|
+
}
|
|
62
|
+
async closeApp(appName) {
|
|
63
|
+
const stopCmd = `adb -s ${this.sn} shell am stop ${appName}`;
|
|
64
|
+
await adbMiwt.execAdbCmdAsync(stopCmd);
|
|
65
|
+
_ColorConsole.default.info(`### Emulator stop ${appName} successfully`);
|
|
66
|
+
// 这里是为了等am stop命令清除资源等
|
|
67
|
+
}
|
|
68
|
+
async reboot() {
|
|
69
|
+
await super.reboot();
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
const func = msg => {
|
|
72
|
+
if (_emulatorutil.EmulatorLog.rpkIsStart(msg)) {
|
|
73
|
+
clearTimeout(timer);
|
|
74
|
+
resolve();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
let timer = setTimeout(() => {
|
|
78
|
+
this.stdoutReadline.off('line', func);
|
|
79
|
+
_ColorConsole.default.error(`### Emulator ### reboot timeout`);
|
|
80
|
+
reject('reboot timeout');
|
|
81
|
+
}, 2 * 60 * 1000);
|
|
82
|
+
this.stdoutReadline.on('line', func);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async reloadApp(appPackageName) {
|
|
86
|
+
let _debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
87
|
+
try {
|
|
88
|
+
// 2. 执行am stop和am start命令
|
|
89
|
+
const stopCmd = `adb -s ${this.sn} shell am stop ${appPackageName}`;
|
|
90
|
+
await adbMiwt.execAdbCmdAsync(stopCmd);
|
|
91
|
+
_ColorConsole.default.info(`### Emulator stop ${appPackageName} successfully`);
|
|
92
|
+
// 这里是为了等am stop命令清除资源等
|
|
93
|
+
await (0, _utils.sleep)(500);
|
|
94
|
+
const startCmd = `adb -s ${this.sn} shell am start ${appPackageName}`;
|
|
95
|
+
await adbMiwt.execAdbCmdAsync(startCmd);
|
|
96
|
+
_ColorConsole.default.info(`### Emulator start ${appPackageName} successfully`);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
_ColorConsole.default.error(`${e}`);
|
|
377
99
|
}
|
|
100
|
+
}
|
|
378
101
|
}
|
|
379
|
-
exports.default = MiwearInstance;
|
|
102
|
+
var _default = exports.default = MiwearInstance;
|
package/lib/instance/pre.d.ts
CHANGED
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import GoldfishInstance from './dev';
|
|
2
|
+
import { VelaImageType } from '../typing/Vvd';
|
|
2
3
|
/**
|
|
3
4
|
* 不带 miwear 的 4.0 镜像
|
|
4
5
|
*/
|
|
5
6
|
declare class PreInstance extends GoldfishInstance {
|
|
7
|
+
imageType: VelaImageType;
|
|
6
8
|
appDir: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
install(rpkPath: string, appPackageName?: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* 在模拟器中启动快应用
|
|
12
|
+
* 通过vapp命令启动,调试时需额外配置--jsdebugger参数
|
|
13
|
+
* @param options
|
|
14
|
+
*/
|
|
15
|
+
startApp(packageName: string, debug?: boolean): Promise<void>;
|
|
16
|
+
closeApp(_appName: string): Promise<void>;
|
|
17
|
+
reloadApp(appName: string, debug?: boolean): Promise<void>;
|
|
10
18
|
}
|
|
11
19
|
export default PreInstance;
|