@aiot-toolkit/emulator 2.0.2-beta.12 → 2.0.2-beta.13

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.
@@ -241,7 +241,8 @@ class GoldfishInstance extends common_1.default {
241
241
  const basename = path_1.default.basename(sourceRoot);
242
242
  if (os_1.default.platform() === 'win32' || this.projectPath.indexOf(' ') > 0) {
243
243
  // windows系统或者项目路径有空格:1. adb push目录;2. 在模拟器中使用mv命令重命名
244
- yield adbMiwt.execAdbCmdAsync(`adb -s ${sn} push ${sourceRoot} ${this.appRunDir}`);
244
+ // 注意 sourceRoot 中可能会有空格
245
+ yield adbMiwt.execAdbCmdAsync(`adb -s ${sn} push "${sourceRoot}" ${this.appRunDir}`);
245
246
  yield adbMiwt.execAdbCmdAsync(`adb -s ${sn} shell mv ${this.appRunDir}/${basename} ${this.appRunDir}/${appPackageName}`);
246
247
  }
247
248
  else {
@@ -11,6 +11,7 @@ declare class MiwearInstance extends CommonInstance {
11
11
  private debugSocket?;
12
12
  private reconnectCount;
13
13
  emulatorStartedFlag: RegExp;
14
+ installBol: boolean;
14
15
  constructor(params: INewGoldfishInstanceParams);
15
16
  /**
16
17
  * 1. 启动模拟器
@@ -49,6 +50,10 @@ declare class MiwearInstance extends CommonInstance {
49
50
  installRpkToAppList(rpkPath: string, targetDir: string): Promise<void>;
50
51
  /** 使用am start启动快应用 */
51
52
  launchQuickapp(): Promise<void>;
53
+ /** 命令行模式下添加重复调用防止app无法拉起
54
+ * 主要用将子进程的流输出到主进程后,由于流写入的过多可能会影响事件循环
55
+ */
56
+ pmInstallApp(maxRepeats: number, count?: number): void;
52
57
  /** 连接模拟器中的调试服务,创建debugSocket
53
58
  * 主要用于热更新时,通过debugSocket通知调试服务更新页面
54
59
  * 设置了重连机制,会重复连接8次
@@ -58,6 +58,7 @@ class MiwearInstance extends common_1.default {
58
58
  this.appPathInEmulator = '/data/quickapp/app';
59
59
  this.reconnectCount = 0;
60
60
  this.emulatorStartedFlag = /quickapp_rpk_installer_init|rpk installer init done/;
61
+ this.installBol = false;
61
62
  }
62
63
  /**
63
64
  * 1. 启动模拟器
@@ -165,6 +166,26 @@ class MiwearInstance extends common_1.default {
165
166
  shell: true,
166
167
  cwd: this.sdkHome
167
168
  });
169
+ // 处理origin为terminal
170
+ if (origin === 'terminal') {
171
+ process.stdout.pipe(this.goldfishProcess.stdin);
172
+ //setTimeout是为了解决window环境报错
173
+ const stdoutPipe = () => {
174
+ var _a, _b, _c, _d;
175
+ (_b = (_a = this.goldfishProcess) === null || _a === void 0 ? void 0 : _a.stdout) === null || _b === void 0 ? void 0 : _b.pipe(process.stdout);
176
+ (_d = (_c = this.goldfishProcess) === null || _c === void 0 ? void 0 : _c.stderr) === null || _d === void 0 ? void 0 : _d.pipe(process.stderr);
177
+ };
178
+ if (this.goldfishProcess.connected) {
179
+ stdoutPipe();
180
+ }
181
+ else {
182
+ setTimeout(stdoutPipe, 0);
183
+ }
184
+ //setTimeout加一层保险防止app无法拉起
185
+ setTimeout(() => {
186
+ this.pmInstallApp && this.pmInstallApp(10);
187
+ }, 10000);
188
+ }
168
189
  // 监听模拟器的退出事件
169
190
  this.goldfishProcess.on('exit', (code) => {
170
191
  shared_utils_1.ColorConsole.error(`### Emulator ### Goldfish emulator exited with code ${code}`);
@@ -180,10 +201,14 @@ class MiwearInstance extends common_1.default {
180
201
  // 监听输出流
181
202
  (_c = (_b = this.goldfishProcess) === null || _b === void 0 ? void 0 : _b.stdout) === null || _c === void 0 ? void 0 : _c.on('data', (data) => {
182
203
  const msg = data.toString();
183
- const stdoutCb = options.stdoutCallback || console.log;
184
- stdoutCb(msg);
204
+ if (origin === 'ide') {
205
+ const stdoutCb = options.stdoutCallback || console.log;
206
+ stdoutCb(msg);
207
+ }
185
208
  // 应用安装成功,则启动它
186
209
  if (msg.match(/InstallState_Finished|install finished/)) {
210
+ if (origin === 'terminal')
211
+ this.installBol = true;
187
212
  shared_utils_1.ColorConsole.info(`### Emulator ### Install quickapp successfully`);
188
213
  this.launchQuickapp();
189
214
  }
@@ -259,6 +284,33 @@ class MiwearInstance extends common_1.default {
259
284
  adbMiwt.execAdbCmdAsync(startCmd);
260
285
  });
261
286
  }
287
+ /** 命令行模式下添加重复调用防止app无法拉起
288
+ * 主要用将子进程的流输出到主进程后,由于流写入的过多可能会影响事件循环
289
+ */
290
+ pmInstallApp(maxRepeats, count = 0) {
291
+ var _a;
292
+ const releaseDir = this.isRpk
293
+ ? path_1.default.resolve(this.projectPath, '../')
294
+ : path_1.default.resolve(this.projectPath, ((_a = this.params.compilerOption) === null || _a === void 0 ? void 0 : _a.releasePath) || 'dist');
295
+ const { package: packageName } = this.projectInfo;
296
+ const files = fs_extra_1.default
297
+ .readdirSync(releaseDir)
298
+ .filter((item) => item.includes(packageName) && item.endsWith('.rpk'));
299
+ const targetDir = path_1.default.resolve(releaseDir, files[0]);
300
+ const targetPath = `${targetDir}/${packageName}.rpk`;
301
+ const installCmd = `adb -s ${this.sn} shell pm install ${targetPath}`;
302
+ if (count < maxRepeats - 1 && !this.installBol) {
303
+ count++;
304
+ shared_utils_1.ColorConsole.info(`### Emulator ### Excuting cmd: terminalr ${installCmd}`);
305
+ adbMiwt.execAdbCmdAsync(installCmd);
306
+ setTimeout(() => {
307
+ this.pmInstallApp(maxRepeats, count);
308
+ }, 6000);
309
+ }
310
+ else {
311
+ return;
312
+ }
313
+ }
262
314
  /** 连接模拟器中的调试服务,创建debugSocket
263
315
  * 主要用于热更新时,通过debugSocket通知调试服务更新页面
264
316
  * 设置了重连机制,会重复连接8次
@@ -17,7 +17,7 @@
17
17
  "hw.dPad": "no",
18
18
  "hw.gps": "yes",
19
19
  "hw.gpu.enabled": "no",
20
- "hw.gpu.mode ": "off",
20
+ "hw.gpu.mode": "off",
21
21
  "hw.initialOrientation": "Portrait",
22
22
  "hw.keyboard": "yes",
23
23
  "hw.lcd.density": 420,
@@ -34,7 +34,7 @@ exports.VelaImageVersionList = [
34
34
  {
35
35
  label: 'vela-4.0-测试版',
36
36
  value: 'vela-pre-4.0',
37
- time: '2024-07-151T07:07:00',
37
+ time: '2024-07-15T07:07:00',
38
38
  hide: false,
39
39
  icon: null
40
40
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiot-toolkit/emulator",
3
- "version": "2.0.2-beta.12",
3
+ "version": "2.0.2-beta.13",
4
4
  "description": "vela emulator tool.",
5
5
  "homepage": "",
6
6
  "license": "ISC",
@@ -35,8 +35,8 @@
35
35
  "emulator"
36
36
  ],
37
37
  "dependencies": {
38
- "@aiot-toolkit/aiotpack": "2.0.2-beta.12",
39
- "@aiot-toolkit/shared-utils": "2.0.2-beta.12",
38
+ "@aiot-toolkit/aiotpack": "2.0.2-beta.13",
39
+ "@aiot-toolkit/shared-utils": "2.0.2-beta.13",
40
40
  "find-process": "^1.4.7",
41
41
  "fs-extra": "^11.2.0",
42
42
  "ini": "^4.1.3",
@@ -46,5 +46,5 @@
46
46
  "@types/fs-extra": "^11.0.4",
47
47
  "@types/ini": "^4.1.1"
48
48
  },
49
- "gitHead": "3d2f9f8f48bb88492013d867f6eff27cb33365a0"
49
+ "gitHead": "30bf14ae958b66937da1b79dcfcd7c436e08af50"
50
50
  }