@aiot-toolkit/emulator 2.0.6-beta.28 → 2.0.6-beta.29

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.
@@ -46,29 +46,15 @@ const defaultDebugPort = exports.defaultDebugPort = 10055;
46
46
  * 获取 Vela Emulator SDK 相关下载地址
47
47
  */
48
48
  async function getSdkUrl() {
49
- const externalBaseUrl = 'https://vela-ide.cnbj3-fusion.mi-fds.com/vela-ide';
49
+ // 外网走 CDN:源站 vela-ide.cnbj3-fusion.mi-fds.com 是单 IP 直连,实测 0.6MB/s,
50
+ // 几百 MB 的镜像下不完;CDN 同对象实测 2.2MB/s
51
+ const externalBaseUrl = 'https://cdn.cnbj3-fusion.fds.api.mi-img.com/vela-ide';
50
52
  const internalBaseUrl = 'https://cnbj3-fusion-fds.api.xiaomi.net/vela-ide';
51
-
52
- // 带超时的 fetch 探测,避免在网络黑洞场景下永远 hang
53
- const probeWithTimeout = async function (url) {
54
- let timeoutMs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 3000;
55
- const ctrl = new AbortController();
56
- const timer = setTimeout(() => ctrl.abort(), timeoutMs);
57
- try {
58
- const res = await fetch(url, {
59
- signal: ctrl.signal
60
- });
61
- return res.ok;
62
- } catch {
63
- return false;
64
- } finally {
65
- clearTimeout(timer);
66
- }
67
- };
68
-
69
- // 优先使用内网域名,失败则降级到外网
70
- const internalOk = await probeWithTimeout(`${internalBaseUrl}/versions.json`);
71
- const base = internalOk ? internalBaseUrl : externalBaseUrl;
53
+ // 优先使用内网域名,因为云上工程没有外网环境
54
+ let base = internalBaseUrl;
55
+ await fetch(`${base}/versions.json`).catch(() => {
56
+ base = externalBaseUrl;
57
+ });
72
58
  return {
73
59
  baseUrl: base,
74
60
  versionUrl: `${base}/versions.json`,
@@ -85,50 +71,50 @@ async function getSdkUrl() {
85
71
  * vela-dev-0.0.4 : vela 4.0 dev 分支
86
72
  */
87
73
  const VelaImageVersionList = exports.VelaImageVersionList = [{
88
- label: 'vela-miwear-watch-5',
89
- description: '适用于手表/手环的,带表盘的 vela 5.0 镜像,不可自定义模拟器尺寸',
74
+ label: 'miwear-watch-5',
75
+ description: '适用于手表/手环的,带表盘的 vela miwear 5.x 镜像,不可自定义模拟器尺寸',
90
76
  value: _Vvd.VelaImageType.VELA_MIWEAR_WATCH_5,
91
- time: '20250716',
77
+ time: '20261106',
92
78
  hide: false,
93
79
  icon: ''
94
80
  }, {
95
- label: 'vela-miwear-watch-5.0(开发者大赛)',
96
- description: '2026 openvela AI 硬件开发者大赛专供,部分 API 为实验性接口,不适合日常开发使用',
97
- value: _Vvd.VelaImageType.VELA_MIWEAR_WATCH_5_BETA,
98
- time: '20260717',
99
- hide: false,
81
+ label: 'vela-watch-6',
82
+ description: '适用于手表/手环的,不带表盘的 vela 6.x 镜像,可自定义模拟器尺寸',
83
+ value: _Vvd.VelaImageType.VELA_WATCH_6,
84
+ time: '20261203',
85
+ hide: true,
100
86
  icon: ''
101
87
  }, {
102
88
  label: 'vela-watch-5',
103
- description: '适用于手表/手环的,不带表盘的 vela 5.0 镜像,可自定义模拟器尺寸',
89
+ description: '适用于手表/手环的,不带表盘的 vela miwear 5.x 镜像,可自定义模拟器尺寸',
104
90
  value: _Vvd.VelaImageType.VELA_WATCH_5,
105
- time: '20250716',
91
+ time: '20261106',
106
92
  hide: false,
107
93
  icon: ''
108
94
  }, {
109
- label: 'vela-miwear-watch-4',
110
- description: '原 vela-release-4.0 版本,适用于手表/手环的,带表盘的 vela 4.0 镜像,不可自定义模拟器尺寸',
95
+ label: 'miwear-watch-4',
96
+ description: '原 vela-release-4.0 版本,适用于手表/手环的,带表盘的 vela 4.x 镜像,不可自定义模拟器尺寸',
111
97
  value: _Vvd.VelaImageType.REL,
112
98
  time: '20250526',
113
99
  hide: false,
114
100
  icon: ''
115
101
  }, {
116
102
  label: 'vela-watch-4',
117
- description: '原 vela-pre-4.0 版本,适用于手表/手环的,不带表盘的 vela 4.0 镜像,可自定义模拟器尺寸',
103
+ description: '原 vela-pre-4.0 版本,适用于手表/手环的,不带表盘的 vela 4.x 镜像,可自定义模拟器尺寸',
118
104
  value: _Vvd.VelaImageType.PRE,
119
105
  time: '20250225',
120
106
  hide: false,
121
107
  icon: ''
122
108
  }, {
123
- label: 'vela-miwear-minisound-5',
124
- description: '适用于音响的 vela-miwear 5.0 镜像,不可自定义模拟器尺寸',
109
+ label: 'miwear-minisound-5',
110
+ description: '适用于音响的 vela-miwear 5.x 镜像,不可自定义模拟器尺寸',
125
111
  value: _Vvd.VelaImageType.VELA_MIWEAR_MINISOUND_5,
126
112
  time: '20250318',
127
113
  hide: true,
128
114
  icon: ''
129
115
  }, {
130
116
  label: 'openvela-smartspeaker-5',
131
- description: '适用于音响的 vela-miwear 5.0 镜像,不可自定义模拟器尺寸',
117
+ description: '适用于音响的 vela-miwear 5.x 镜像,不可自定义模拟器尺寸',
132
118
  value: _Vvd.VelaImageType.OPENVELA_SMARTSPEAKER_5,
133
119
  time: '20260128',
134
120
  hide: true,
@@ -136,12 +122,12 @@ const VelaImageVersionList = exports.VelaImageVersionList = [{
136
122
  }];
137
123
  const EmulatorEnvVersion = exports.EmulatorEnvVersion = {
138
124
  name: '模拟器资源版本管理',
139
- [_Vvd.SDKParts.EMULATOR]: '0.1.0',
125
+ [_Vvd.SDKParts.EMULATOR]: '0.2.0',
140
126
  [_Vvd.SDKParts.QA]: '0.0.1',
141
- [_Vvd.SDKParts.SKINS]: '0.0.12',
127
+ [_Vvd.SDKParts.SKINS]: '0.0.13',
142
128
  [_Vvd.SDKParts.SYSTEM_IMAGES]: VelaImageVersionList[0].time,
143
129
  [_Vvd.SDKParts.MODEM_SIMULATOR]: '0.0.3',
144
- [_Vvd.SDKParts.TOOLS]: '0.0.3'
130
+ [_Vvd.SDKParts.TOOLS]: '0.0.4'
145
131
  };
146
132
 
147
133
  /** 获取镜像下载地址 */
@@ -18,6 +18,17 @@ export interface EmulatorConfig {
18
18
  'grpc.port': string;
19
19
  [i: string]: string;
20
20
  }
21
+ /**
22
+ * 正在运行的模拟器的注册信息,已去掉残留的注册文件。
23
+ *
24
+ * 残留文件里的端口很可能已经被别的模拟器占用。以前不过滤,B 的残留排在它真正的注册文件前面时(文件名按字典序),
25
+ * B 的实例会连到占着那个端口的 A 上(A 已经在运行时,B 干脆不启动,直接把 A 当成 B 接管),之后对 B 的安装、
26
+ * 启动都发到 A:多台模拟器调试时 A 被同时装两次,其中一次报 Failed to deal with rpkpackage -1 或
27
+ * repeated submission error -17,应用却装好了。
28
+ *
29
+ * 除了进程已退出的,还按修改时间从新到旧,每个端口、每个模拟器名只留最新的一条:
30
+ * Windows 的 pid 会复用,残留文件的 pid 可能正好是别的活进程,但它一定比占着同一端口的模拟器的注册文件旧。
31
+ */
21
32
  export declare function getRunningAvdConfig(): EmulatorConfig[];
22
33
  export declare function getRunningVvds(): Promise<EmulatorConfig[]>;
23
34
  export declare function getRunningAvdConfigByName(name: string): EmulatorConfig | undefined;
@@ -15,7 +15,7 @@ var _os = _interopRequireDefault(require("os"));
15
15
  var _fs = _interopRequireDefault(require("fs"));
16
16
  var _ini = _interopRequireDefault(require("ini"));
17
17
  var _path = _interopRequireDefault(require("path"));
18
- var _adb = require("@miwt/adb");
18
+ var _adb = require("@aiot-toolkit/adb");
19
19
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
20
  const defaultDirRelativePath = exports.defaultDirRelativePath = 'avd/running';
21
21
  const fileNamePattern = exports.fileNamePattern = /pid_\d+\.ini/;
@@ -80,15 +80,63 @@ function getRunningAvdConfigFiles() {
80
80
  return [];
81
81
  }
82
82
  }
83
+ /**
84
+ * 注册文件名 pid_<pid>.ini 里的模拟器进程是否还在。
85
+ *
86
+ * 模拟器只在正常退出时删自己的注册文件,被杀掉(poweroff 超时后 killEmulatorProcess、关窗口、崩溃)
87
+ * 就会留下。Windows 上注册目录在 %LOCALAPPDATA%\Temp 下,重启也不清,残留会一直累积
88
+ */
89
+ function isRegistrantAlive(file) {
90
+ const pid = Number(file.match(/pid_(\d+)\.ini$/)?.[1]);
91
+ if (!pid) return true;
92
+ try {
93
+ process.kill(pid, 0);
94
+ return true;
95
+ } catch (error) {
96
+ // EPERM:进程在,只是没有权限给它发信号
97
+ return error.code === 'EPERM';
98
+ }
99
+ }
100
+ function getMtime(file) {
101
+ try {
102
+ return _fs.default.statSync(file).mtimeMs || 0;
103
+ } catch {
104
+ return 0;
105
+ }
106
+ }
107
+
108
+ /**
109
+ * 正在运行的模拟器的注册信息,已去掉残留的注册文件。
110
+ *
111
+ * 残留文件里的端口很可能已经被别的模拟器占用。以前不过滤,B 的残留排在它真正的注册文件前面时(文件名按字典序),
112
+ * B 的实例会连到占着那个端口的 A 上(A 已经在运行时,B 干脆不启动,直接把 A 当成 B 接管),之后对 B 的安装、
113
+ * 启动都发到 A:多台模拟器调试时 A 被同时装两次,其中一次报 Failed to deal with rpkpackage -1 或
114
+ * repeated submission error -17,应用却装好了。
115
+ *
116
+ * 除了进程已退出的,还按修改时间从新到旧,每个端口、每个模拟器名只留最新的一条:
117
+ * Windows 的 pid 会复用,残留文件的 pid 可能正好是别的活进程,但它一定比占着同一端口的模拟器的注册文件旧。
118
+ */
83
119
  function getRunningAvdConfig() {
84
- const file = getRunningAvdConfigFiles();
85
- const result = [];
86
- file.forEach(f => {
87
- result.push({
120
+ const entries = getRunningAvdConfigFiles().filter(isRegistrantAlive).map(f => ({
121
+ config: {
88
122
  ..._ini.default.parse(_fs.default.readFileSync(f, 'utf-8')),
89
123
  path: f
90
- });
91
- });
124
+ },
125
+ mtime: getMtime(f)
126
+ })).sort((a, b) => b.mtime - a.mtime);
127
+ const ports = new Set();
128
+ const names = new Set();
129
+ const result = [];
130
+ for (const {
131
+ config
132
+ } of entries) {
133
+ const port = config['port.serial'];
134
+ const name = config['avd.name'];
135
+ if (port && ports.has(port) || name && names.has(name)) continue;
136
+ if (port) ports.add(port);
137
+ if (name) names.add(name);
138
+ result.push(config);
139
+ }
92
140
  return result;
93
141
  }
94
142
  async function getRunningVvds() {
@@ -98,16 +146,7 @@ async function getRunningVvds() {
98
146
  return config.filter(c => adbDevices.some(e => e.sn === `emulator-${c['port.serial']}` && e.status === 'device'));
99
147
  }
100
148
  function getRunningAvdConfigByName(name) {
101
- const iniFiles = getRunningAvdConfigFiles();
102
- for (const iniFile of iniFiles) {
103
- const iniConfig = _ini.default.parse(_fs.default.readFileSync(iniFile, 'utf-8'));
104
- if (iniConfig['avd.name'] === name) {
105
- return {
106
- ...iniConfig,
107
- path: iniFile
108
- };
109
- }
110
- }
149
+ return getRunningAvdConfig().find(c => c['avd.name'] === name);
111
150
  }
112
151
  function getRunningVvdDebugPort(name) {
113
152
  const e = getRunningAvdConfigByName(name);
package/lib/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './broker';
2
2
  export * from './vvd';
3
- export { getSystemArch, tryRun } from './utils';
3
+ export { getSystemArch, tryRun, killEmulatorProcess } from './utils';
4
4
  export * from './instance';
5
5
  export * from './typing/Vvd';
6
6
  export * from './typing/Instance';
package/lib/index.js CHANGED
@@ -5,7 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  var _exportNames = {
7
7
  getSystemArch: true,
8
- tryRun: true
8
+ tryRun: true,
9
+ killEmulatorProcess: true
9
10
  };
10
11
  Object.defineProperty(exports, "getSystemArch", {
11
12
  enumerable: true,
@@ -13,6 +14,12 @@ Object.defineProperty(exports, "getSystemArch", {
13
14
  return _utils.getSystemArch;
14
15
  }
15
16
  });
17
+ Object.defineProperty(exports, "killEmulatorProcess", {
18
+ enumerable: true,
19
+ get: function () {
20
+ return _utils.killEmulatorProcess;
21
+ }
22
+ });
16
23
  Object.defineProperty(exports, "tryRun", {
17
24
  enumerable: true,
18
25
  get: function () {
@@ -49,6 +49,13 @@ declare abstract class CommonEmulatorInstance {
49
49
  * 判断模拟器是否 ready
50
50
  */
51
51
  isConnected(): Promise<boolean>;
52
+ /**
53
+ * 推送并安装 rpk。同一台设备(按 sn)上的调用排队执行。
54
+ *
55
+ * 两次安装在同一台设备上重叠时,vela-watch-6 上实测:后一次的 push 在前一次 pm install 读 rpk 时
56
+ * 覆盖了它,前一次报 Failed to deal with rpkpackage -1;两次 pm install 同时提交,后提交的报
57
+ * repeated submission error -17。另一次照常装好,界面上就是「报安装失败,应用却装上了」。
58
+ */
52
59
  pushAndInstall(rpkPath: string, appName: string): Promise<void>;
53
60
  /** 关闭模拟器 */
54
61
  poweroff(timeout?: number): Promise<void>;
@@ -7,16 +7,17 @@ exports.default = void 0;
7
7
  require("core-js/actual/promise/with-resolvers");
8
8
  var _ColorConsole = _interopRequireDefault(require("@aiot-toolkit/shared-utils/lib/ColorConsole"));
9
9
  var _ILog = require("@aiot-toolkit/shared-utils/lib/interface/ILog");
10
- var _adb = _interopRequireWildcard(require("@miwt/adb"));
10
+ var _adb = _interopRequireWildcard(require("@aiot-toolkit/adb"));
11
11
  var adbMiwt = _adb;
12
12
  var _utils = require("../utils");
13
13
  var _logcat = require("../vvd/logcat");
14
14
  var _emulatorutil = require("../emulatorutil");
15
15
  var _shared = require("../shared");
16
16
  var _fs = _interopRequireDefault(require("fs"));
17
- 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); }
18
- 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; }
17
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
19
18
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
19
+ /** 每台设备(sn)上最近一次 pushAndInstall,后来的调用排在它后面 */
20
+ const installQueue = new Map();
20
21
  class CommonEmulatorInstance {
21
22
  appDir = '/data/quickapp/app';
22
23
 
@@ -26,8 +27,8 @@ class CommonEmulatorInstance {
26
27
  static appInstallFailedFlag = /uv_mq_read_cb: install prepare failed/;
27
28
  static appUninstalledFlag = /uninstalled app/;
28
29
  static appStartedFlag = /Start App loop/;
29
- static isAppInstalled() {
30
- const log = arguments.length <= 0 ? undefined : arguments[0];
30
+ static isAppInstalled(...args) {
31
+ const log = args[0];
31
32
  return this.appInstalledFlag.test(log);
32
33
  }
33
34
  static isAppInstallFailed(log) {
@@ -132,35 +133,30 @@ class CommonEmulatorInstance {
132
133
  return curDev?.status === 'device';
133
134
  }, 10, 500);
134
135
  }
135
- async pushAndInstall(rpkPath, appName) {
136
- const targetPath = await this.pushRpk(rpkPath, appName);
137
- try {
138
- await this.install(targetPath, {
139
- packageName: appName,
140
- size: _fs.default.statSync(rpkPath).size
141
- });
142
- } catch (error) {
143
- let timer;
144
- if (error === _shared.RpkInstallFailedReason.Busy) {
145
- this.logger('install process is busy, 3s later retry');
146
- await new Promise((resolve, rejcet) => {
147
- timer = setTimeout(() => {
148
- this.pushAndInstall(rpkPath, appName).then(resolve).catch(rejcet);
149
- }, 3000);
150
- });
151
- } else {
152
- clearTimeout(timer);
153
- throw error;
154
- }
155
- }
136
+
137
+ /**
138
+ * 推送并安装 rpk。同一台设备(按 sn)上的调用排队执行。
139
+ *
140
+ * 两次安装在同一台设备上重叠时,vela-watch-6 上实测:后一次的 push 在前一次 pm install 读 rpk 时
141
+ * 覆盖了它,前一次报 Failed to deal with rpkpackage -1;两次 pm install 同时提交,后提交的报
142
+ * repeated submission error -17。另一次照常装好,界面上就是「报安装失败,应用却装上了」。
143
+ */
144
+ pushAndInstall(rpkPath, appName) {
145
+ const prev = installQueue.get(this.sn) || Promise.resolve();
146
+ const task = prev.catch(() => undefined).then(() => pushAndInstallNow(this, rpkPath, appName));
147
+ installQueue.set(this.sn, task);
148
+ const cleanup = () => {
149
+ if (installQueue.get(this.sn) === task) installQueue.delete(this.sn);
150
+ };
151
+ task.then(cleanup, cleanup);
152
+ return task;
156
153
  }
157
154
 
158
155
  /** 关闭模拟器 */
159
- poweroff() {
160
- let timeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10 * 1000;
156
+ poweroff(timeout = 10 * 1000) {
161
157
  return new Promise((resolve, reject) => {
162
158
  const t = setTimeout(() => {
163
- (0, _utils.killProcessByCmd)(this.vvdName).then(resolve).catch(e => {
159
+ (0, _utils.killEmulatorProcess)(this.vvdName).then(resolve).catch(e => {
164
160
  reject(`poweroff ${this.vvdName} failed ${e}`);
165
161
  });
166
162
  }, timeout);
@@ -168,7 +164,7 @@ class CommonEmulatorInstance {
168
164
  clearTimeout(t);
169
165
  resolve();
170
166
  }).catch(() => {
171
- (0, _utils.killProcessByCmd)(this.vvdName).then(() => {
167
+ (0, _utils.killEmulatorProcess)(this.vvdName).then(() => {
172
168
  clearTimeout(t);
173
169
  resolve();
174
170
  }).catch(e => {
@@ -208,4 +204,30 @@ class CommonEmulatorInstance {
208
204
  }
209
205
  }
210
206
  }
207
+
208
+ // 不做成类的 private 方法:类带 private 成员后按名义类型比较,ide-core 里 reactive 解包过的设备对象
209
+ // 就不能再赋给 SelectedDevice
210
+ async function pushAndInstallNow(inst, rpkPath, appName) {
211
+ const targetPath = await inst.pushRpk(rpkPath, appName);
212
+ try {
213
+ await inst.install(targetPath, {
214
+ packageName: appName,
215
+ size: _fs.default.statSync(rpkPath).size
216
+ });
217
+ } catch (error) {
218
+ let timer;
219
+ if (error === _shared.RpkInstallFailedReason.Busy) {
220
+ inst.logger('install process is busy, 3s later retry');
221
+ await new Promise((resolve, rejcet) => {
222
+ timer = setTimeout(() => {
223
+ // 不能走 pushAndInstall:它会排到当前这次后面,而当前这次正在等它
224
+ pushAndInstallNow(inst, rpkPath, appName).then(resolve).catch(rejcet);
225
+ }, 3000);
226
+ });
227
+ } else {
228
+ clearTimeout(timer);
229
+ throw error;
230
+ }
231
+ }
232
+ }
211
233
  var _default = exports.default = CommonEmulatorInstance;
@@ -4,12 +4,11 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
7
+ var adbMiwt = _interopRequireWildcard(require("@aiot-toolkit/adb"));
8
8
  var _common = _interopRequireDefault(require("./common"));
9
9
  var _Vvd = require("../typing/Vvd");
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- 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); }
12
- 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; }
11
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
13
12
  /**
14
13
  * @deprecated 不在使用
15
14
  */
@@ -20,7 +19,7 @@ class GoldfishInstance extends _common.default {
20
19
  closeApp() {
21
20
  throw new Error('Method not implemented.');
22
21
  }
23
- imageType = (() => _Vvd.VelaImageType.DEV)();
22
+ imageType = _Vvd.VelaImageType.DEV;
24
23
  static appDir = '/data/app';
25
24
  static emulatorStartedFlag = /(NSH)/;
26
25
  async install(rpkPath, opt) {
@@ -40,8 +39,7 @@ class GoldfishInstance extends _common.default {
40
39
  * 通过vapp命令启动,调试时需额外配置--jsdebugger参数
41
40
  * @param options
42
41
  */
43
- async startApp(packageName) {
44
- let debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
42
+ async startApp(packageName, debug = false) {
45
43
  try {
46
44
  let vappCmd = `adb -s ${this.sn} shell vapp app/${packageName} &`;
47
45
  if (debug) {
@@ -56,8 +54,7 @@ class GoldfishInstance extends _common.default {
56
54
  this.logger(`Failed to startup quickapp: ${e.message}`);
57
55
  }
58
56
  }
59
- async reloadApp(appName) {
60
- let debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
57
+ async reloadApp(appName, debug = false) {
61
58
  await this.reboot();
62
59
  await this.startApp(appName, debug);
63
60
  }
@@ -8,8 +8,7 @@ import { Vela5Instance } from './vela5';
8
8
  import { VelaMiwear5 } from './miwear5';
9
9
  import { MiniSound5 } from './minisound';
10
10
  import { OpenSmartspeaker5 } from './openSmartspeaker5';
11
- import { VelaMiwear5Beta } from './miwear5beta';
12
- declare function getInstanceClass(imageType: VelaImageType): typeof GoldfishInstance | typeof MiwearInstance | typeof PreInstance | typeof Vela5Instance | typeof VelaMiwear5 | typeof MiniSound5 | typeof OpenSmartspeaker5 | typeof VelaMiwear5Beta;
11
+ declare function getInstanceClass(imageType: VelaImageType): typeof GoldfishInstance | typeof MiwearInstance | typeof PreInstance | typeof Vela5Instance | typeof VelaMiwear5 | typeof MiniSound5 | typeof OpenSmartspeaker5;
13
12
  /**
14
13
  * 根据镜像决定使用哪个instance
15
14
  * Vela正式版(4.0) -> MiwearInstance
@@ -44,18 +44,17 @@ var _vela = require("./vela5");
44
44
  var _miwear2 = require("./miwear5");
45
45
  var _minisound = require("./minisound");
46
46
  var _openSmartspeaker = require("./openSmartspeaker5");
47
- var _miwear5beta = require("./miwear5beta");
48
47
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
49
48
  function getInstanceClass(imageType) {
50
49
  const map = {
51
50
  [_Vvd.VelaImageType.PRE]: _pre.default,
52
51
  [_Vvd.VelaImageType.REL]: _miwear.default,
53
52
  [_Vvd.VelaImageType.DEV]: _dev.default,
53
+ [_Vvd.VelaImageType.VELA_WATCH_6]: _vela.Vela5Instance,
54
54
  [_Vvd.VelaImageType.VELA_WATCH_5]: _vela.Vela5Instance,
55
55
  [_Vvd.VelaImageType.VELA_MIWEAR_WATCH_5]: _miwear2.VelaMiwear5,
56
56
  [_Vvd.VelaImageType.VELA_MIWEAR_MINISOUND_5]: _minisound.MiniSound5,
57
- [_Vvd.VelaImageType.OPENVELA_SMARTSPEAKER_5]: _openSmartspeaker.OpenSmartspeaker5,
58
- [_Vvd.VelaImageType.VELA_MIWEAR_WATCH_5_BETA]: _miwear5beta.VelaMiwear5Beta
57
+ [_Vvd.VelaImageType.OPENVELA_SMARTSPEAKER_5]: _openSmartspeaker.OpenSmartspeaker5
59
58
  };
60
59
  return map[imageType] || _miwear2.VelaMiwear5;
61
60
  }
@@ -6,12 +6,11 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.MiniSound5 = void 0;
7
7
  var _Vvd = require("../typing/Vvd");
8
8
  var _miwear = require("./miwear5");
9
- var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
9
+ var adbMiwt = _interopRequireWildcard(require("@aiot-toolkit/adb"));
10
10
  var _util = require("util");
11
- 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); }
12
- 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; }
11
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
13
12
  class MiniSound5 extends _miwear.VelaMiwear5 {
14
- imageType = (() => _Vvd.VelaImageType.VELA_MIWEAR_MINISOUND_5)();
13
+ imageType = _Vvd.VelaImageType.VELA_MIWEAR_MINISOUND_5;
15
14
  appDir = '/data/app';
16
15
  xmsInitedFlag = /AMS/;
17
16
  static appStartedFlag = /Start main loop/;
@@ -4,15 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var adbMiwt = _interopRequireWildcard(require("@miwt/adb"));
7
+ var adbMiwt = _interopRequireWildcard(require("@aiot-toolkit/adb"));
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
  var _utils = require("../utils");
10
10
  var _common = _interopRequireDefault(require("./common"));
11
11
  var _Vvd = require("../typing/Vvd");
12
12
  var _shared = require("../shared");
13
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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; }
14
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
15
  /**
17
16
  * MiwearInstance
18
17
  * 针对 Vela正式版(4.0)的镜像
@@ -21,7 +20,7 @@ class MiwearInstance extends _common.default {
21
20
  xmsInitedFlag = /quickapp_rpk_installer_init|rpk installer init done/;
22
21
  static appInstalledFlag = /InstallState_Finished|install finished/;
23
22
  static appInstallFailedFlag = /uv_mq_read_cb: install prepare failed|rpk_install_status: rpk install failed/;
24
- imageType = (() => _Vvd.VelaImageType.REL)();
23
+ imageType = _Vvd.VelaImageType.REL;
25
24
  appDir = '/data/quickapp/app';
26
25
  static isAppInstalled(log, targetRpk) {
27
26
  // 注意:targetRpk 可能包含特殊字符,需要转义
@@ -112,14 +111,13 @@ class MiwearInstance extends _common.default {
112
111
  }
113
112
 
114
113
  /** 使用 am start 启动快应用 */
115
- async startApp(packageName) {
116
- let debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
114
+ async startApp(packageName, debug = false) {
117
115
  // 等待 xms 服务初始化完成之后才能进行安装
118
116
  await this.xmsStatus.promise;
119
117
  // 调试模式需要push一个文件至miwear中
120
118
  if (debug) {
121
119
  const debuggerCfgFile = _path.default.join(__dirname, '../static/debugger_ip.cfg');
122
- await adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} push ${debuggerCfgFile} /data/debugger_ip.cfg`);
120
+ await adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} push "${debuggerCfgFile}" /data/debugger_ip.cfg`);
123
121
  } else {
124
122
  await adbMiwt.execAdbCmdAsync(`adb -s ${this.sn} shell rm /data/debugger_ip.cfg`);
125
123
  }
@@ -3,4 +3,10 @@ import MiwearInstance from './miwear';
3
3
  export declare class VelaMiwear5 extends MiwearInstance {
4
4
  imageType: VelaImageType;
5
5
  appDir: string;
6
+ /**
7
+ * 使用 am start 启动快应用
8
+ *
9
+ * 应用在运行时 am start 不会重新拉起它:重新安装的 rpk 不生效,跑的还是旧包。所以先停掉再启动
10
+ */
11
+ startApp(packageName: string, debug?: boolean): Promise<void>;
6
12
  }
@@ -4,11 +4,82 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.VelaMiwear5 = void 0;
7
+ var adbMiwt = _interopRequireWildcard(require("@aiot-toolkit/adb"));
7
8
  var _Vvd = require("../typing/Vvd");
9
+ var _utils = require("../utils");
8
10
  var _miwear = _interopRequireDefault(require("./miwear"));
9
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
10
13
  class VelaMiwear5 extends _miwear.default {
11
- imageType = (() => _Vvd.VelaImageType.VELA_MIWEAR_WATCH_5)();
14
+ imageType = _Vvd.VelaImageType.VELA_MIWEAR_WATCH_5;
12
15
  appDir = '/data/app';
16
+
17
+ /**
18
+ * 使用 am start 启动快应用
19
+ *
20
+ * 应用在运行时 am start 不会重新拉起它:重新安装的 rpk 不生效,跑的还是旧包。所以先停掉再启动
21
+ */
22
+ async startApp(packageName, debug = false) {
23
+ await this.xmsStatus.promise;
24
+ await stopRunningApp(this, packageName);
25
+ return super.startApp(packageName, debug);
26
+ }
13
27
  }
14
- exports.VelaMiwear5 = VelaMiwear5;
28
+
29
+ /**
30
+ * am stop 并等应用退到 [stopped]
31
+ *
32
+ * 正在运行的应用在 am stop 之后依次经过 [toBG]、[background]、[closing]、[stopped],miwear-watch-5 上约 120ms;
33
+ * 没在运行时 am stop 不会打这些状态。命令返回后 1s 内没看到它开始退出就当没在运行,已经开始退出的最多等 5s。
34
+ * 还在启动中([launching])的应用收到的 am stop 会推迟到启动完成后才执行,这种情况不处理。
35
+ * 放在类外面:私有成员会让类按名义比较类型,ide-core 里响应式的设备条目就不能赋给 SelectedDevice 了
36
+ */
37
+ exports.VelaMiwear5 = VelaMiwear5;
38
+ function stopRunningApp(instance, packageName) {
39
+ const {
40
+ sn,
41
+ vvdName,
42
+ logger,
43
+ stdoutReadline
44
+ } = instance;
45
+ const stateFlag = new RegExp(`quickapp_state_trans: ${(0, _utils.escapeRegExp)(packageName)}: \\[\\w+\\]-->\\[(\\w+)\\]`);
46
+ return new Promise(resolve => {
47
+ let quietTimer;
48
+ let maxTimer;
49
+ let finished = false;
50
+ const done = () => {
51
+ if (finished) return;
52
+ finished = true;
53
+ clearTimeout(quietTimer);
54
+ clearTimeout(maxTimer);
55
+ stdoutReadline.off('line', func);
56
+ resolve();
57
+ };
58
+ const func = msg => {
59
+ const state = msg.match(stateFlag)?.[1];
60
+ if (!state) return;
61
+ if (state === 'stopped') {
62
+ logger(`${packageName} stopped on ${vvdName}`);
63
+ done();
64
+ return;
65
+ }
66
+ // 已经开始退出,等到 [stopped]
67
+ clearTimeout(quietTimer);
68
+ if (!maxTimer) {
69
+ maxTimer = setTimeout(() => {
70
+ logger(`${packageName} not stopped on ${vvdName} in 5s, start it anyway`);
71
+ done();
72
+ }, 5 * 1000);
73
+ }
74
+ };
75
+ stdoutReadline.on('line', func);
76
+ const stopCmd = `adb -s ${sn} shell am stop ${packageName}`;
77
+ logger(`Excuting: ${stopCmd}`);
78
+ adbMiwt.execAdbCmdAsync(stopCmd).then(() => {
79
+ if (!finished && !maxTimer) quietTimer = setTimeout(done, 1000);
80
+ }).catch(e => {
81
+ logger(`${stopCmd} failed: ${e}`);
82
+ done();
83
+ });
84
+ });
85
+ }