@aiot-toolkit/emulator 2.0.5-widget-provider-beta.2 → 2.0.6-beta.1
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 -173
- package/lib/emulatorutil/constants.js +11 -11
- package/lib/emulatorutil/running.js +14 -6
- package/lib/index.d.ts +2 -2
- package/lib/index.js +12 -0
- package/lib/instance/common.d.ts +5 -2
- package/lib/instance/common.js +26 -5
- package/lib/instance/dev.d.ts +4 -1
- package/lib/instance/dev.js +9 -9
- package/lib/instance/index.js +6 -6
- package/lib/instance/minisound.js +6 -6
- package/lib/instance/miwear.d.ts +5 -1
- package/lib/instance/miwear.js +44 -22
- package/lib/instance/miwear5.d.ts +0 -1
- package/lib/instance/miwear5.js +0 -1
- package/lib/instance/pre.d.ts +4 -1
- package/lib/instance/pre.js +9 -9
- package/lib/instance/vela5.d.ts +5 -0
- package/lib/instance/vela5.js +63 -4
- package/lib/shared/index.d.ts +9 -0
- package/lib/shared/index.js +16 -4
- package/lib/static/advancedFeatures.ini +1 -1
- package/lib/static/avdConfigIni.json +45 -39
- package/lib/static/debugger_ip.cfg +1 -1
- package/lib/static/proto/README.MD +2 -2
- package/lib/static/proto/emulator_controller.proto +1321 -1321
- package/lib/static/proto/rtc_service.proto +117 -117
- package/lib/typing/Instance.js +3 -3
- package/lib/typing/Vvd.d.ts +3 -3
- package/lib/typing/Vvd.js +1 -2
- package/lib/utils/file.d.ts +8 -0
- package/lib/utils/file.js +48 -1
- package/lib/utils/index.js +19 -19
- package/lib/vvd/index.d.ts +5 -1
- package/lib/vvd/index.js +127 -43
- package/lib/vvd/logcat.js +3 -3
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,173 +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-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
|
-
```
|
|
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,23 +48,23 @@ 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
57
|
label: 'vela-miwear-watch-5.0',
|
|
58
58
|
description: '适用于手表/手环的,带表盘的 vela 5.0 镜像,不可自定义模拟器尺寸',
|
|
59
59
|
value: _Vvd.VelaImageType.VELA_MIWEAR_WATCH_5,
|
|
60
|
-
time: '
|
|
60
|
+
time: '20250716',
|
|
61
61
|
hide: false,
|
|
62
62
|
icon: ''
|
|
63
63
|
}, {
|
|
64
64
|
label: 'vela-watch-5.0',
|
|
65
65
|
description: '适用于手表/手环的,不带表盘的 vela 5.0 镜像,可自定义模拟器尺寸',
|
|
66
66
|
value: _Vvd.VelaImageType.VELA_WATCH_5,
|
|
67
|
-
time: '
|
|
67
|
+
time: '20250716',
|
|
68
68
|
hide: false,
|
|
69
69
|
icon: ''
|
|
70
70
|
}, {
|
|
@@ -93,7 +93,7 @@ const EmulatorEnvVersion = exports.EmulatorEnvVersion = {
|
|
|
93
93
|
name: '模拟器资源版本管理',
|
|
94
94
|
[_Vvd.SDKParts.EMULATOR]: '0.1.0',
|
|
95
95
|
[_Vvd.SDKParts.QA]: '0.0.1',
|
|
96
|
-
[_Vvd.SDKParts.SKINS]: '0.0.
|
|
96
|
+
[_Vvd.SDKParts.SKINS]: '0.0.10',
|
|
97
97
|
[_Vvd.SDKParts.SYSTEM_IMAGES]: VelaImageVersionList[0].time,
|
|
98
98
|
[_Vvd.SDKParts.MODEM_SIMULATOR]: '0.0.3'
|
|
99
99
|
};
|
|
@@ -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();
|
|
@@ -98,8 +98,16 @@ async function getRunningVvds() {
|
|
|
98
98
|
return config.filter(c => adbDevices.some(e => e.sn === `emulator-${c['port.serial']}` && e.status === 'device'));
|
|
99
99
|
}
|
|
100
100
|
function getRunningAvdConfigByName(name) {
|
|
101
|
-
const
|
|
102
|
-
|
|
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
|
+
}
|
|
103
111
|
}
|
|
104
112
|
function getRunningVvdDebugPort(name) {
|
|
105
113
|
const e = getRunningAvdConfigByName(name);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { VvdManager } from './vvd';
|
|
2
|
-
|
|
2
|
+
export { getSystemArch, tryRun } from './utils';
|
|
3
3
|
export * from './instance';
|
|
4
4
|
export * from './typing/Vvd';
|
|
5
5
|
export * from './typing/Instance';
|
|
6
6
|
export * from './emulatorutil';
|
|
7
|
-
export
|
|
7
|
+
export * from './shared';
|
package/lib/index.js
CHANGED
|
@@ -75,4 +75,16 @@ Object.keys(_emulatorutil).forEach(function (key) {
|
|
|
75
75
|
return _emulatorutil[key];
|
|
76
76
|
}
|
|
77
77
|
});
|
|
78
|
+
});
|
|
79
|
+
var _shared = require("./shared");
|
|
80
|
+
Object.keys(_shared).forEach(function (key) {
|
|
81
|
+
if (key === "default" || key === "__esModule") return;
|
|
82
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
83
|
+
if (key in exports && exports[key] === _shared[key]) return;
|
|
84
|
+
Object.defineProperty(exports, key, {
|
|
85
|
+
enumerable: true,
|
|
86
|
+
get: function () {
|
|
87
|
+
return _shared[key];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
78
90
|
});
|
package/lib/instance/common.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ declare abstract class CommonEmulatorInstance {
|
|
|
10
10
|
static appInstallFailedFlag: RegExp;
|
|
11
11
|
static appUninstalledFlag: RegExp;
|
|
12
12
|
static appStartedFlag: RegExp;
|
|
13
|
-
static isAppInstalled(
|
|
13
|
+
static isAppInstalled(...args: any[]): boolean;
|
|
14
14
|
static isAppInstallFailed(log: string): boolean;
|
|
15
15
|
static isAppUninstalled(log: string, packageName: string): boolean;
|
|
16
16
|
static isEmulatorStarted(log: string): boolean;
|
|
@@ -26,7 +26,10 @@ declare abstract class CommonEmulatorInstance {
|
|
|
26
26
|
logger: (log: string) => void;
|
|
27
27
|
constructor(params: IEmulatorInstanceParams);
|
|
28
28
|
/** 安装应用,留给子类实现 */
|
|
29
|
-
abstract install(rpkPath: string,
|
|
29
|
+
abstract install(rpkPath: string, options?: {
|
|
30
|
+
packageName?: string;
|
|
31
|
+
size?: number;
|
|
32
|
+
}): Promise<void>;
|
|
30
33
|
/** 卸载应用,留给子类实现 */
|
|
31
34
|
abstract uninstall(packageName: string): Promise<void>;
|
|
32
35
|
/** 重启应用 */
|
package/lib/instance/common.js
CHANGED
|
@@ -11,6 +11,8 @@ var adbMiwt = _adb;
|
|
|
11
11
|
var _utils = require("../utils");
|
|
12
12
|
var _logcat = require("../vvd/logcat");
|
|
13
13
|
var _emulatorutil = require("../emulatorutil");
|
|
14
|
+
var _shared = require("../shared");
|
|
15
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
14
16
|
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
17
|
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
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -21,14 +23,15 @@ class CommonEmulatorInstance {
|
|
|
21
23
|
static appInstallFailedFlag = /uv_mq_read_cb: install prepare failed/;
|
|
22
24
|
static appUninstalledFlag = /uninstalled app/;
|
|
23
25
|
static appStartedFlag = /Start App loop/;
|
|
24
|
-
static isAppInstalled(
|
|
26
|
+
static isAppInstalled() {
|
|
27
|
+
const log = arguments.length <= 0 ? undefined : arguments[0];
|
|
25
28
|
return this.appInstalledFlag.test(log);
|
|
26
29
|
}
|
|
27
30
|
static isAppInstallFailed(log) {
|
|
28
31
|
return this.appInstallFailedFlag.test(log);
|
|
29
32
|
}
|
|
30
33
|
static isAppUninstalled(log, packageName) {
|
|
31
|
-
return new RegExp(this.appUninstalledFlag + ':\\s+' + packageName).test(log);
|
|
34
|
+
return new RegExp(this.appUninstalledFlag.source + ':\\s+' + packageName).test(log);
|
|
32
35
|
}
|
|
33
36
|
static isEmulatorStarted(log) {
|
|
34
37
|
return this.emulatorStartedFlag.test(log);
|
|
@@ -104,8 +107,8 @@ class CommonEmulatorInstance {
|
|
|
104
107
|
return targetPath;
|
|
105
108
|
}
|
|
106
109
|
|
|
107
|
-
/**
|
|
108
|
-
* 判断模拟器是否 ready
|
|
110
|
+
/**
|
|
111
|
+
* 判断模拟器是否 ready
|
|
109
112
|
*/
|
|
110
113
|
async isConnected() {
|
|
111
114
|
return (0, _utils.tryRun)(async () => {
|
|
@@ -117,7 +120,25 @@ class CommonEmulatorInstance {
|
|
|
117
120
|
}
|
|
118
121
|
async pushAndInstall(rpkPath, appName) {
|
|
119
122
|
const targetPath = await this.pushRpk(rpkPath, appName);
|
|
120
|
-
|
|
123
|
+
try {
|
|
124
|
+
await this.install(targetPath, {
|
|
125
|
+
packageName: appName,
|
|
126
|
+
size: _fs.default.statSync(rpkPath).size
|
|
127
|
+
});
|
|
128
|
+
} catch (error) {
|
|
129
|
+
let timer;
|
|
130
|
+
if (error === _shared.RpkInstallFailedReason.Busy) {
|
|
131
|
+
this.logger('install process is busy, 3s later retry');
|
|
132
|
+
await new Promise((resolve, rejcet) => {
|
|
133
|
+
timer = setTimeout(() => {
|
|
134
|
+
this.pushAndInstall(rpkPath, appName).then(resolve).catch(rejcet);
|
|
135
|
+
}, 3000);
|
|
136
|
+
});
|
|
137
|
+
} else {
|
|
138
|
+
clearTimeout(timer);
|
|
139
|
+
throw error;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
121
142
|
}
|
|
122
143
|
|
|
123
144
|
/** 关闭模拟器 */
|
package/lib/instance/dev.d.ts
CHANGED
|
@@ -9,7 +9,10 @@ declare class GoldfishInstance extends CommonEmulatorInstance {
|
|
|
9
9
|
imageType: VelaImageType;
|
|
10
10
|
static appDir: string;
|
|
11
11
|
static emulatorStartedFlag: RegExp;
|
|
12
|
-
install(rpkPath: string,
|
|
12
|
+
install(rpkPath: string, opt: {
|
|
13
|
+
packageName?: string;
|
|
14
|
+
size?: number;
|
|
15
|
+
}): Promise<void>;
|
|
13
16
|
/**
|
|
14
17
|
* 在模拟器中启动快应用
|
|
15
18
|
* 通过vapp命令启动,调试时需额外配置--jsdebugger参数
|
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() {
|
|
@@ -23,10 +23,10 @@ class GoldfishInstance extends _common.default {
|
|
|
23
23
|
imageType = (() => _Vvd.VelaImageType.DEV)();
|
|
24
24
|
static appDir = '/data/app';
|
|
25
25
|
static emulatorStartedFlag = /(NSH)/;
|
|
26
|
-
async install(rpkPath,
|
|
26
|
+
async install(rpkPath, opt) {
|
|
27
27
|
// 基于 vapp 启动的应用只需要将 rpk 解压到指定的目录下
|
|
28
|
-
rpkPath = rpkPath || `${this.appDir}/${
|
|
29
|
-
const targetPath = `${this.appDir}/${
|
|
28
|
+
rpkPath = rpkPath || `${this.appDir}/${opt.packageName}.rpk`;
|
|
29
|
+
const targetPath = `${this.appDir}/${opt.packageName}`;
|
|
30
30
|
const mkdirCmd = `adb -s ${this.sn} shell mkdir ${targetPath}`;
|
|
31
31
|
this.logger(`Excuting: ${mkdirCmd}`);
|
|
32
32
|
await adbMiwt.execAdbCmdAsync(mkdirCmd);
|
|
@@ -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
|
@@ -9,11 +9,15 @@ declare class MiwearInstance extends CommonEmulatorInstance {
|
|
|
9
9
|
static appInstalledFlag: RegExp;
|
|
10
10
|
imageType: VelaImageType;
|
|
11
11
|
appDir: string;
|
|
12
|
+
static isAppInstalled(log: string, targetRpk: string): boolean;
|
|
12
13
|
/**
|
|
13
14
|
* 使用 pm 安装快应用
|
|
14
15
|
* @param targeRpk 快应用的rpk文件路径
|
|
15
16
|
*/
|
|
16
|
-
install(targeRpk: string
|
|
17
|
+
install(targeRpk: string, options?: {
|
|
18
|
+
packageName?: string;
|
|
19
|
+
size?: number;
|
|
20
|
+
}): Promise<void>;
|
|
17
21
|
/**
|
|
18
22
|
* 使用 pm 卸载快应用
|
|
19
23
|
* @param packageName 快应用的包名
|