@aiot-toolkit/emulator 2.0.5-beta.9 → 2.0.5-widget-provider-beta.2
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 +173 -140
- package/lib/emulatorutil/constants.js +24 -24
- package/lib/emulatorutil/running.js +5 -5
- package/lib/instance/common.d.ts +3 -1
- package/lib/instance/common.js +9 -8
- package/lib/instance/dev.js +6 -6
- package/lib/instance/index.js +6 -6
- package/lib/instance/minisound.js +6 -6
- package/lib/instance/miwear.d.ts +1 -0
- package/lib/instance/miwear.js +25 -10
- package/lib/instance/pre.js +6 -6
- package/lib/instance/vela5.js +3 -3
- package/lib/shared/index.js +3 -3
- package/lib/static/advancedFeatures.ini +1 -1
- package/lib/static/avdConfigIni.json +39 -39
- package/lib/static/debugger_ip.cfg +1 -1
- package/lib/static/proto/README.MD +2 -0
- package/lib/static/proto/emulator_controller.proto +1321 -0
- package/lib/static/proto/rtc_service.proto +117 -0
- package/lib/typing/Instance.js +3 -3
- package/lib/utils/index.js +19 -19
- package/lib/vvd/grpc/grpcError.d.ts +1 -0
- package/lib/vvd/grpc/grpcError.js +10 -0
- package/lib/vvd/grpc/index.d.ts +27 -0
- package/lib/vvd/grpc/index.js +117 -0
- package/lib/vvd/grpc/types/GrpcClient.d.ts +4 -0
- package/lib/vvd/grpc/types/GrpcClient.js +5 -0
- package/lib/vvd/grpc/types/KeyEvent.d.ts +19 -0
- package/lib/vvd/grpc/types/KeyEvent.js +20 -0
- package/lib/vvd/grpc/types/MouseEvent.d.ts +30 -0
- package/lib/vvd/grpc/types/MouseEvent.js +5 -0
- package/lib/vvd/index.d.ts +2 -0
- package/lib/vvd/index.js +43 -36
- package/lib/vvd/logcat.js +3 -0
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -1,140 +1,173 @@
|
|
|
1
|
-
## emulator
|
|
2
|
-
|
|
3
|
-
Vela 模拟器 SDK
|
|
4
|
-
|
|
5
|
-
模拟器的介绍可参考[开发帮助文档](https://xiaomi.f.mioffice.cn/docx/doxk4Rk6x67GanHlzQ8bEOrxtEe)里的「模拟器」章节
|
|
6
|
-
|
|
7
|
-
## 目录结构
|
|
8
|
-
|
|
9
|
-
| 目录 | 描述 |
|
|
10
|
-
| -------- | ------------------------------------------------------------------------ |
|
|
11
|
-
| avd | 模拟器的AVD,配置统一放置$HOME/.vela/vvd 目录下 |
|
|
12
|
-
| instance | 模拟器实例,不同的Vela镜像版本会使用不同的instance,通过findInstance确定 |
|
|
13
|
-
| static | 创建AVD时需要用到的静态资源,常量配置文件 |
|
|
14
|
-
| typing | 接口定义 |
|
|
15
|
-
| utils | 工具函数 |
|
|
16
|
-
|
|
17
|
-
## 安装
|
|
18
|
-
|
|
19
|
-
```bash
|
|
20
|
-
npm install @aiot/emulator
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## 使用
|
|
24
|
-
|
|
25
|
-
###
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
import os from 'os'
|
|
29
|
-
import path from 'path'
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
1
|
+
## emulator
|
|
2
|
+
|
|
3
|
+
Vela 模拟器 SDK
|
|
4
|
+
|
|
5
|
+
模拟器的介绍可参考[开发帮助文档](https://xiaomi.f.mioffice.cn/docx/doxk4Rk6x67GanHlzQ8bEOrxtEe)里的「模拟器」章节
|
|
6
|
+
|
|
7
|
+
## 目录结构
|
|
8
|
+
|
|
9
|
+
| 目录 | 描述 |
|
|
10
|
+
| -------- | ------------------------------------------------------------------------ |
|
|
11
|
+
| avd | 模拟器的AVD,配置统一放置$HOME/.vela/vvd 目录下 |
|
|
12
|
+
| instance | 模拟器实例,不同的Vela镜像版本会使用不同的instance,通过findInstance确定 |
|
|
13
|
+
| static | 创建AVD时需要用到的静态资源,常量配置文件 |
|
|
14
|
+
| typing | 接口定义 |
|
|
15
|
+
| utils | 工具函数 |
|
|
16
|
+
|
|
17
|
+
## 安装
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @aiot-toolkit/emulator
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## 使用
|
|
24
|
+
|
|
25
|
+
### 初始化环境
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import os from 'os'
|
|
29
|
+
import path from 'path'
|
|
30
|
+
import { VvdManager } from '@aiot-toolkit/emulator'
|
|
31
|
+
|
|
32
|
+
async function main() {
|
|
33
|
+
const sdkHome = path.resolve(os.homedir(), '.export_dev')
|
|
34
|
+
const velaAvdCls = new VvdManager({ sdkHome })
|
|
35
|
+
|
|
36
|
+
const downloder = await velaAvdCls.downloadSDK({
|
|
37
|
+
force: true,
|
|
38
|
+
cliProgress: false,
|
|
39
|
+
parallelDownloads: 6
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
downloder.on('progress', (progress) => {
|
|
43
|
+
console.log(
|
|
44
|
+
`progress: ${progress.formattedSpeed} ${progress.formattedPercentage} ${progress.formatTotal} ${progress.formatTimeLeft}`
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
await downloder.downlodPromise
|
|
49
|
+
|
|
50
|
+
console.log('download success')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
main()
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 创建 VVD
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import os from 'os'
|
|
60
|
+
import path from 'path'
|
|
61
|
+
import { IAvdArchType, VvdManager, VelaImageType, getDefaultImage } from '@aiot-toolkit/emulator'
|
|
62
|
+
|
|
63
|
+
const velaAvdCls = new VvdManager({
|
|
64
|
+
sdkHome: path.resolve(os.homedir(), '.export_dev')
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
/** 创建一个 466 × 466 带 miwear 的模拟器 */
|
|
68
|
+
export async function createVVd() {
|
|
69
|
+
const defaultImage = getDefaultImage()
|
|
70
|
+
velaAvdCls.createVvd({
|
|
71
|
+
name: avdName,
|
|
72
|
+
imageType: defaultImage,
|
|
73
|
+
arch: IVvdArchType.arm,
|
|
74
|
+
imageDir: path.dirname(velaAvdCls.getLocalSystemPath(defaultImage)),
|
|
75
|
+
width: '466',
|
|
76
|
+
height: '466'
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### 启动 VVD
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import os from 'os'
|
|
85
|
+
import path from 'path'
|
|
86
|
+
import { IAvdArchType, VvdManager, VelaImageType } from '@aiot-toolkit/emulator'
|
|
87
|
+
|
|
88
|
+
const velaAvdCls = new VvdManager({
|
|
89
|
+
sdkHome: path.resolve(os.homedir(), '.export_dev')
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
export async function startVvd(vvdName: string) {
|
|
93
|
+
/**
|
|
94
|
+
* coldBoot:boolean 是否冷启动
|
|
95
|
+
* emulatorInstance: EmulatorInstance 模拟器实例, 可以通过它与模拟器进行命令交互
|
|
96
|
+
* getAgent: () => Promise<GrpcEmulator> 获取模拟器的Agent,可以通过它与模拟器进行屏幕交互
|
|
97
|
+
*/
|
|
98
|
+
const { coldBoot, emulatorInstance, getAgent } = await velaAvdCls.startVvd({
|
|
99
|
+
vvdName
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
// 启动应用
|
|
103
|
+
emulatorInstance.startApp('com.xiaomi.mipicks')
|
|
104
|
+
|
|
105
|
+
const velaAgent = await getAgent()
|
|
106
|
+
// 获取模拟器截图
|
|
107
|
+
const imgBuffer = await velaAgent.getScreenshot()
|
|
108
|
+
// 点击模拟器指定位置,
|
|
109
|
+
await velaAgent.sendMouse({
|
|
110
|
+
x: 100,
|
|
111
|
+
y: 100,
|
|
112
|
+
// 按下
|
|
113
|
+
buttons: 1
|
|
114
|
+
})
|
|
115
|
+
await velaAgent.sendMouse({
|
|
116
|
+
x: 100,
|
|
117
|
+
y: 100,
|
|
118
|
+
// 松开
|
|
119
|
+
buttons: 0
|
|
120
|
+
})
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### 完整示例
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
// 安装 npm install @aiot/emulator
|
|
128
|
+
import os from 'os'
|
|
129
|
+
import path from 'path'
|
|
130
|
+
import { IAvdArchType, VvdManager, VelaImageType } from '@aiot-toolkit/emulator'
|
|
131
|
+
|
|
132
|
+
const velaAvdCls = new VvdManager({
|
|
133
|
+
sdkHome: path.resolve(os.homedir(), '.export_dev')
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
/** 创建一个 466 × 466 带 miwear 的模拟器 */
|
|
137
|
+
velaAvdCls.createVvd({
|
|
138
|
+
name: 'O62',
|
|
139
|
+
arch: IAvdArchType.arm64,
|
|
140
|
+
height: '466',
|
|
141
|
+
width: '466',
|
|
142
|
+
imageType: VelaImageType.REL
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
/** 启动名为 'O62' 的模拟器 */
|
|
146
|
+
velaAvdCls.startVvd({
|
|
147
|
+
vvdName: 'O62'
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
export async function startVvd(vvdName: string) {}
|
|
151
|
+
|
|
152
|
+
export async function createVVd() {}
|
|
153
|
+
|
|
154
|
+
async function main() {
|
|
155
|
+
const downloder = await velaAvdCls.downloadSDK({
|
|
156
|
+
force: true,
|
|
157
|
+
cliProgress: false,
|
|
158
|
+
parallelDownloads: 6
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
downloder.on('progress', (progress) => {
|
|
162
|
+
console.log(
|
|
163
|
+
`progress: ${progress.formattedSpeed} ${progress.formattedPercentage} ${progress.formatTotal} ${progress.formatTimeLeft}`
|
|
164
|
+
)
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
await downloder.downlodPromise
|
|
168
|
+
|
|
169
|
+
console.log('download success')
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
main()
|
|
173
|
+
```
|
|
@@ -48,36 +48,36 @@ const systemImageBaseUrl = exports.systemImageBaseUrl = 'https://vela-ide.cnbj3-
|
|
|
48
48
|
|
|
49
49
|
// 不确定vela镜像的发布策略,暂时需要手动更新此列表
|
|
50
50
|
// 0.0.2和0.0.3版本比较特殊,线上是一个nuttx文件。其他版本都是一个zip包,包含nuttx data.img和vela_source.img
|
|
51
|
-
/**
|
|
52
|
-
* vela-release-4.0 : vela 4.0 带 miwear
|
|
53
|
-
* vela-pre-4.0 : vela 4.0 不带 miwear
|
|
54
|
-
* vela-dev-0.0.4 : vela 4.0 dev 分支
|
|
51
|
+
/**
|
|
52
|
+
* vela-release-4.0 : vela 4.0 带 miwear
|
|
53
|
+
* vela-pre-4.0 : vela 4.0 不带 miwear
|
|
54
|
+
* vela-dev-0.0.4 : vela 4.0 dev 分支
|
|
55
55
|
*/
|
|
56
56
|
const VelaImageVersionList = exports.VelaImageVersionList = [{
|
|
57
|
-
label: 'vela-miwear-watch-4.0',
|
|
58
|
-
description: '原 vela-release-4.0 版本,适用于手表/手环的,带表盘的 vela 4.0 镜像,不可自定义模拟器尺寸',
|
|
59
|
-
value: _Vvd.VelaImageType.REL,
|
|
60
|
-
time: '20250225',
|
|
61
|
-
hide: false,
|
|
62
|
-
icon: ''
|
|
63
|
-
}, {
|
|
64
|
-
label: 'vela-watch-4.0',
|
|
65
|
-
description: '原 vela-pre-4.0 版本,适用于手表/手环的,不带表盘的 vela 4.0 镜像,可自定义模拟器尺寸',
|
|
66
|
-
value: _Vvd.VelaImageType.PRE,
|
|
67
|
-
time: '20250225',
|
|
68
|
-
hide: false,
|
|
69
|
-
icon: ''
|
|
70
|
-
}, {
|
|
71
57
|
label: 'vela-miwear-watch-5.0',
|
|
72
58
|
description: '适用于手表/手环的,带表盘的 vela 5.0 镜像,不可自定义模拟器尺寸',
|
|
73
59
|
value: _Vvd.VelaImageType.VELA_MIWEAR_WATCH_5,
|
|
74
|
-
time: '
|
|
60
|
+
time: '20250605',
|
|
75
61
|
hide: false,
|
|
76
62
|
icon: ''
|
|
77
63
|
}, {
|
|
78
64
|
label: 'vela-watch-5.0',
|
|
79
65
|
description: '适用于手表/手环的,不带表盘的 vela 5.0 镜像,可自定义模拟器尺寸',
|
|
80
66
|
value: _Vvd.VelaImageType.VELA_WATCH_5,
|
|
67
|
+
time: '20250605',
|
|
68
|
+
hide: false,
|
|
69
|
+
icon: ''
|
|
70
|
+
}, {
|
|
71
|
+
label: 'vela-miwear-watch-4.0',
|
|
72
|
+
description: '原 vela-release-4.0 版本,适用于手表/手环的,带表盘的 vela 4.0 镜像,不可自定义模拟器尺寸',
|
|
73
|
+
value: _Vvd.VelaImageType.REL,
|
|
74
|
+
time: '20250526',
|
|
75
|
+
hide: false,
|
|
76
|
+
icon: ''
|
|
77
|
+
}, {
|
|
78
|
+
label: 'vela-watch-4.0',
|
|
79
|
+
description: '原 vela-pre-4.0 版本,适用于手表/手环的,不带表盘的 vela 4.0 镜像,可自定义模拟器尺寸',
|
|
80
|
+
value: _Vvd.VelaImageType.PRE,
|
|
81
81
|
time: '20250225',
|
|
82
82
|
hide: false,
|
|
83
83
|
icon: ''
|
|
@@ -86,7 +86,7 @@ const VelaImageVersionList = exports.VelaImageVersionList = [{
|
|
|
86
86
|
description: '适用于音响的 vela-miwear 5.0 镜像,不可自定义模拟器尺寸',
|
|
87
87
|
value: _Vvd.VelaImageType.VELA_MIWEAR_MINISOUND_5,
|
|
88
88
|
time: '20250318',
|
|
89
|
-
hide:
|
|
89
|
+
hide: true,
|
|
90
90
|
icon: ''
|
|
91
91
|
}];
|
|
92
92
|
const EmulatorEnvVersion = exports.EmulatorEnvVersion = {
|
|
@@ -106,10 +106,10 @@ function getImageDownloadUrl() {
|
|
|
106
106
|
}, {});
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
/**
|
|
110
|
-
* 获取各种 SKD 最新版本的下载地址;
|
|
111
|
-
* 镜像地址默认返回 REL 版本的地址,如果需要获取其他版本,请使用
|
|
112
|
-
* {@link getImageDownloadUrl}
|
|
109
|
+
/**
|
|
110
|
+
* 获取各种 SKD 最新版本的下载地址;
|
|
111
|
+
* 镜像地址默认返回 REL 版本的地址,如果需要获取其他版本,请使用
|
|
112
|
+
* {@link getImageDownloadUrl}
|
|
113
113
|
*/
|
|
114
114
|
function getSDKPartDownloadUrl(type) {
|
|
115
115
|
switch (type) {
|
|
@@ -24,8 +24,8 @@ function getPlatform() {
|
|
|
24
24
|
return platform === 'darwin' ? 'darwin' : platform === 'win32' ? 'win32' : 'linux';
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
/**
|
|
28
|
-
* Returns the Emulator registration directory.
|
|
27
|
+
/**
|
|
28
|
+
* Returns the Emulator registration directory.
|
|
29
29
|
*/
|
|
30
30
|
function computeRegistrationDirectoryContainer() {
|
|
31
31
|
const platform = getPlatform();
|
|
@@ -39,8 +39,8 @@ function computeRegistrationDirectoryContainer() {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
/**
|
|
43
|
-
* @returns 获取模拟器配置文件目录
|
|
42
|
+
/**
|
|
43
|
+
* @returns 获取模拟器配置文件目录
|
|
44
44
|
*/
|
|
45
45
|
function getEmulatorDefaultConfigDir() {
|
|
46
46
|
const dir = computeRegistrationDirectoryContainer();
|
|
@@ -72,8 +72,8 @@ function resolvePath(filePath) {
|
|
|
72
72
|
return _path.default.resolve(filePath);
|
|
73
73
|
}
|
|
74
74
|
function getRunningAvdConfigFiles() {
|
|
75
|
-
const dir = getEmulatorDefaultConfigDir();
|
|
76
75
|
try {
|
|
76
|
+
const dir = getEmulatorDefaultConfigDir();
|
|
77
77
|
const files = _fs.default.readdirSync(dir);
|
|
78
78
|
return files.filter(t => fileNamePattern.test(t)).map(t => _path.default.join(dir, t));
|
|
79
79
|
} catch (error) {
|
package/lib/instance/common.d.ts
CHANGED
|
@@ -7,9 +7,11 @@ declare abstract class CommonEmulatorInstance {
|
|
|
7
7
|
appDir: string;
|
|
8
8
|
static emulatorStartedFlag: RegExp;
|
|
9
9
|
static appInstalledFlag: RegExp;
|
|
10
|
+
static appInstallFailedFlag: RegExp;
|
|
10
11
|
static appUninstalledFlag: RegExp;
|
|
11
12
|
static appStartedFlag: RegExp;
|
|
12
13
|
static isAppInstalled(log: string): boolean;
|
|
14
|
+
static isAppInstallFailed(log: string): boolean;
|
|
13
15
|
static isAppUninstalled(log: string, packageName: string): boolean;
|
|
14
16
|
static isEmulatorStarted(log: string): boolean;
|
|
15
17
|
sn: string;
|
|
@@ -33,7 +35,7 @@ declare abstract class CommonEmulatorInstance {
|
|
|
33
35
|
abstract closeApp(appName: string): Promise<void>;
|
|
34
36
|
/** 启动应用,留给子类实现 */
|
|
35
37
|
abstract startApp(packageName: string, debug: boolean): Promise<void>;
|
|
36
|
-
/**
|
|
38
|
+
/** 推送指定文件,返回推送结果 */
|
|
37
39
|
push(sourcePath: string, targetPath: string): Promise<string>;
|
|
38
40
|
unzip(zipPath: string, targetPath: string): Promise<void>;
|
|
39
41
|
/** 推送指定 rpk */
|
package/lib/instance/common.js
CHANGED
|
@@ -18,11 +18,15 @@ class CommonEmulatorInstance {
|
|
|
18
18
|
appDir = '/data/quickapp/app';
|
|
19
19
|
static emulatorStartedFlag = /quickapp_rpk_installer_init|rpk installer init done|booting completed|Boot completed/;
|
|
20
20
|
static appInstalledFlag = /InstallState_Finished|install finished/;
|
|
21
|
+
static appInstallFailedFlag = /uv_mq_read_cb: install prepare failed/;
|
|
21
22
|
static appUninstalledFlag = /uninstalled app/;
|
|
22
23
|
static appStartedFlag = /Start App loop/;
|
|
23
24
|
static isAppInstalled(log) {
|
|
24
25
|
return this.appInstalledFlag.test(log);
|
|
25
26
|
}
|
|
27
|
+
static isAppInstallFailed(log) {
|
|
28
|
+
return this.appInstallFailedFlag.test(log);
|
|
29
|
+
}
|
|
26
30
|
static isAppUninstalled(log, packageName) {
|
|
27
31
|
return new RegExp(this.appUninstalledFlag + ':\\s+' + packageName).test(log);
|
|
28
32
|
}
|
|
@@ -76,14 +80,14 @@ class CommonEmulatorInstance {
|
|
|
76
80
|
|
|
77
81
|
/** 启动应用,留给子类实现 */
|
|
78
82
|
|
|
79
|
-
/**
|
|
83
|
+
/** 推送指定文件,返回推送结果 */
|
|
80
84
|
async push(sourcePath, targetPath) {
|
|
81
85
|
// 1. adb push应用的rpk
|
|
82
86
|
const pushCmd = `adb -s ${this.sn} push "${sourcePath}" ${targetPath}`;
|
|
83
87
|
this.logger(`Excuting: ${pushCmd}`);
|
|
84
88
|
const res = await adbMiwt.execAdbCmdAsync(pushCmd);
|
|
85
89
|
this.logger(`Push result: ${res}`);
|
|
86
|
-
return
|
|
90
|
+
return res;
|
|
87
91
|
}
|
|
88
92
|
async unzip(zipPath, targetPath) {
|
|
89
93
|
const unzipCmd = `adb -s ${this.sn} shell unzip -o ${zipPath} -d ${targetPath}`;
|
|
@@ -96,15 +100,12 @@ class CommonEmulatorInstance {
|
|
|
96
100
|
async pushRpk(rpkPath, appPackageName) {
|
|
97
101
|
// 1. adb push应用的rpk
|
|
98
102
|
const targetPath = `${this.appDir}/${appPackageName}.rpk`;
|
|
99
|
-
|
|
100
|
-
this.logger(`Excuting: ${pushCmd}`);
|
|
101
|
-
const res = await adbMiwt.execAdbCmdAsync(pushCmd);
|
|
102
|
-
this.logger(`Push ${this.vvdName} rpk result: ${res}`);
|
|
103
|
+
await this.push(rpkPath, targetPath);
|
|
103
104
|
return targetPath;
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
/**
|
|
107
|
-
* 判断模拟器是否 ready
|
|
107
|
+
/**
|
|
108
|
+
* 判断模拟器是否 ready
|
|
108
109
|
*/
|
|
109
110
|
async isConnected() {
|
|
110
111
|
return (0, _utils.tryRun)(async () => {
|
package/lib/instance/dev.js
CHANGED
|
@@ -10,8 +10,8 @@ var _Vvd = require("../typing/Vvd");
|
|
|
10
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
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
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; }
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated 不在使用
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated 不在使用
|
|
15
15
|
*/
|
|
16
16
|
class GoldfishInstance extends _common.default {
|
|
17
17
|
uninstall() {
|
|
@@ -35,10 +35,10 @@ class GoldfishInstance extends _common.default {
|
|
|
35
35
|
await adbMiwt.execAdbCmdAsync(unzipCmd);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
/**
|
|
39
|
-
* 在模拟器中启动快应用
|
|
40
|
-
* 通过vapp命令启动,调试时需额外配置--jsdebugger参数
|
|
41
|
-
* @param options
|
|
38
|
+
/**
|
|
39
|
+
* 在模拟器中启动快应用
|
|
40
|
+
* 通过vapp命令启动,调试时需额外配置--jsdebugger参数
|
|
41
|
+
* @param options
|
|
42
42
|
*/
|
|
43
43
|
async startApp(packageName) {
|
|
44
44
|
let debug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
package/lib/instance/index.js
CHANGED
|
@@ -56,12 +56,12 @@ function getInstanceClass(imageType) {
|
|
|
56
56
|
return map[imageType] || _dev.default;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
/**
|
|
60
|
-
* 根据镜像决定使用哪个instance
|
|
61
|
-
* Vela正式版(4.0) -> MiwearInstance
|
|
62
|
-
* Vela正式版(不带 miwear 版本) -> PreInstance
|
|
63
|
-
* Vela开发版(dev, 0.0.2) -> OldGoldfishInstance
|
|
64
|
-
* Vela开发版(dev),除0.0.2的其他版本 -> GoldfishInstance
|
|
59
|
+
/**
|
|
60
|
+
* 根据镜像决定使用哪个instance
|
|
61
|
+
* Vela正式版(4.0) -> MiwearInstance
|
|
62
|
+
* Vela正式版(不带 miwear 版本) -> PreInstance
|
|
63
|
+
* Vela开发版(dev, 0.0.2) -> OldGoldfishInstance
|
|
64
|
+
* Vela开发版(dev),除0.0.2的其他版本 -> GoldfishInstance
|
|
65
65
|
*/
|
|
66
66
|
function findInstance(imageType, params) {
|
|
67
67
|
const Instance = getInstanceClass(imageType);
|
|
@@ -13,9 +13,9 @@ class MiniSound5 extends _miwear.VelaMiwear5 {
|
|
|
13
13
|
static emulatorStartedFlag = /\[launchQuickApp.*\] Start main loop/;
|
|
14
14
|
static appStartedFlag = /Start main loop/;
|
|
15
15
|
|
|
16
|
-
/**
|
|
17
|
-
* 使用 pm 安装快应用
|
|
18
|
-
* @param targeRpk 快应用的rpk文件路径
|
|
16
|
+
/**
|
|
17
|
+
* 使用 pm 安装快应用
|
|
18
|
+
* @param targeRpk 快应用的rpk文件路径
|
|
19
19
|
*/
|
|
20
20
|
install(targeRpk) {
|
|
21
21
|
const installCmd = `adb -s ${this.sn} shell pm install ${targeRpk}`;
|
|
@@ -29,9 +29,9 @@ class MiniSound5 extends _miwear.VelaMiwear5 {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
/**
|
|
33
|
-
* 使用 pm 卸载快应用
|
|
34
|
-
* @param packageName 快应用的包名
|
|
32
|
+
/**
|
|
33
|
+
* 使用 pm 卸载快应用
|
|
34
|
+
* @param packageName 快应用的包名
|
|
35
35
|
*/
|
|
36
36
|
uninstall(packageName) {
|
|
37
37
|
const res = (0, _adb.execAdbCmdSync)(`adb -s ${this.sn} shell pm uninstall ${packageName}`);
|
package/lib/instance/miwear.d.ts
CHANGED
package/lib/instance/miwear.js
CHANGED
|
@@ -12,28 +12,38 @@ var _Vvd = require("../typing/Vvd");
|
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
13
|
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); }
|
|
14
14
|
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; }
|
|
15
|
-
/**
|
|
16
|
-
* MiwearInstance
|
|
17
|
-
* 针对 Vela正式版(4.0)的镜像
|
|
15
|
+
/**
|
|
16
|
+
* MiwearInstance
|
|
17
|
+
* 针对 Vela正式版(4.0)的镜像
|
|
18
18
|
*/
|
|
19
19
|
class MiwearInstance extends _common.default {
|
|
20
|
+
static emulatorStartedFlag = /quickapp_rpk_installer_init|rpk installer init done/;
|
|
20
21
|
static appInstalledFlag = /InstallState_Finished|install finished/;
|
|
21
22
|
imageType = (() => _Vvd.VelaImageType.REL)();
|
|
22
23
|
appDir = '/data/quickapp/app';
|
|
23
24
|
|
|
24
|
-
/**
|
|
25
|
-
* 使用 pm 安装快应用
|
|
26
|
-
* @param targeRpk 快应用的rpk文件路径
|
|
25
|
+
/**
|
|
26
|
+
* 使用 pm 安装快应用
|
|
27
|
+
* @param targeRpk 快应用的rpk文件路径
|
|
27
28
|
*/
|
|
28
29
|
async install(targeRpk) {
|
|
29
|
-
|
|
30
|
+
const installCmd = `adb -s ${this.sn} shell pm install ${targeRpk}`;
|
|
31
|
+
this.logger(`Excuting: ${installCmd}`);
|
|
32
|
+
adbMiwt.execAdbCmd(installCmd);
|
|
30
33
|
return new Promise((resolve, reject) => {
|
|
31
34
|
const func = msg => {
|
|
32
35
|
if (MiwearInstance.isAppInstalled(msg)) {
|
|
33
36
|
clearTimeout(timer);
|
|
34
37
|
this.logger(`Install to ${this.vvdName} ${targeRpk} successfully`);
|
|
38
|
+
this.stdoutReadline.off('line', func);
|
|
35
39
|
resolve();
|
|
36
40
|
}
|
|
41
|
+
if (MiwearInstance.isAppInstallFailed(msg)) {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
this.stdoutReadline.off('line', func);
|
|
44
|
+
this.logger(`Failed Install to ${this.vvdName} ${targeRpk}`);
|
|
45
|
+
reject(msg);
|
|
46
|
+
}
|
|
37
47
|
};
|
|
38
48
|
let timer = setTimeout(() => {
|
|
39
49
|
this.stdoutReadline.off('line', func);
|
|
@@ -41,12 +51,17 @@ class MiwearInstance extends _common.default {
|
|
|
41
51
|
reject('Install timeout');
|
|
42
52
|
}, 2 * 60 * 1000);
|
|
43
53
|
this.stdoutReadline.on('line', func);
|
|
54
|
+
this.stdoutReadline.on('close', () => {
|
|
55
|
+
this.stdoutReadline.removeAllListeners();
|
|
56
|
+
clearTimeout(timer);
|
|
57
|
+
reject('Device poweroff');
|
|
58
|
+
});
|
|
44
59
|
});
|
|
45
60
|
}
|
|
46
61
|
|
|
47
|
-
/**
|
|
48
|
-
* 使用 pm 卸载快应用
|
|
49
|
-
* @param packageName 快应用的包名
|
|
62
|
+
/**
|
|
63
|
+
* 使用 pm 卸载快应用
|
|
64
|
+
* @param packageName 快应用的包名
|
|
50
65
|
*/
|
|
51
66
|
uninstall(packageName) {
|
|
52
67
|
adbMiwt.execAdbCmd(`adb -s ${this.sn} shell pm uninstall ${packageName}`);
|