@aiot-toolkit/emulator 2.0.5-beta.11 → 2.0.5-beta.12

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 CHANGED
@@ -17,101 +17,134 @@ Vela 模拟器 SDK
17
17
  ## 安装
18
18
 
19
19
  ```bash
20
- npm install @aiot/emulator
20
+ npm install @aiot-toolkit/emulator
21
21
  ```
22
22
 
23
23
  ## 使用
24
24
 
25
- ### 创建 VVD
25
+ ### 初始化环境
26
26
 
27
27
  ```ts
28
28
  import os from 'os'
29
29
  import path from 'path'
30
- import { IAvdArchType, VelaAvdCls, VelaImageType } from '@aiot/emulator'
30
+ import { VvdManager } from '@aiot-toolkit/emulator'
31
31
 
32
- const sdkHome = path.resolve(os.homedir(), '.export_dev')
33
- const velaAvdCls = new VelaAvdCls({ sdkHome })
32
+ async function main() {
33
+ const sdkHome = path.resolve(os.homedir(), '.export_dev')
34
+ const velaAvdCls = new VvdManager({ sdkHome })
34
35
 
35
- /** 创建一个 466 × 466 带 miwear 的模拟器 */
36
- export async function createVVd() {
37
- velaAvdCls.createVvd({
38
- avdName: 'test',
39
- avdArch: IAvdArchType.arm64,
40
- avdHeight: '466',
41
- avdWidth: '466',
42
- imageType: VelaImageType.REL
36
+ const downloder = await velaAvdCls.downloadSDK({
37
+ force: true,
38
+ cliProgress: false,
39
+ parallelDownloads: 6
43
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')
44
51
  }
52
+
53
+ main()
45
54
  ```
46
55
 
47
- ### 启动 VVD
56
+ ### 创建 VVD
48
57
 
49
58
  ```ts
50
59
  import os from 'os'
51
60
  import path from 'path'
52
- import { IAvdArchType, VelaAvdCls, VelaImageType } from '../src'
61
+ import { IAvdArchType, VvdManager, VelaImageType, getDefaultImage } from '@aiot-toolkit/emulator'
53
62
 
54
- const sdkHome = path.resolve(os.homedir(), '.export_dev')
55
- const velaAvdCls = new VelaAvdCls({ sdkHome })
63
+ const velaAvdCls = new VvdManager({
64
+ sdkHome: path.resolve(os.homedir(), '.export_dev')
65
+ })
56
66
 
57
- export async function startVvd(vvdName: string) {
58
- velaAvdCls.startVvd({
59
- avdName: vvdName
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'
60
77
  })
61
78
  }
62
79
  ```
63
80
 
64
- ### 初始化环境
81
+ ### 启动 VVD
65
82
 
66
83
  ```ts
67
84
  import os from 'os'
68
85
  import path from 'path'
69
- import { VelaAvdCls } from '@aiot/emulator'
86
+ import { IAvdArchType, VvdManager, VelaImageType } from '@aiot-toolkit/emulator'
70
87
 
71
- async function main() {
72
- const sdkHome = path.resolve(os.homedir(), '.export_dev')
73
- const velaAvdCls = new VelaAvdCls({ sdkHome })
88
+ const velaAvdCls = new VvdManager({
89
+ sdkHome: path.resolve(os.homedir(), '.export_dev')
90
+ })
74
91
 
75
- const downloder = await velaAvdCls.downloadSDK({
76
- force: true,
77
- cliProgress: false,
78
- parallelDownloads: 6
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
79
100
  })
80
101
 
81
- downloder.on('progress', (progress) => {
82
- console.log(
83
- `progress: ${progress.formattedSpeed} ${progress.formattedPercentage} ${progress.formatTotal} ${progress.formatTimeLeft}`
84
- )
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
85
120
  })
86
-
87
- await downloder.downlodPromise
88
-
89
- console.log('download success')
90
121
  }
91
-
92
- main()
93
122
  ```
94
123
 
95
124
  ### 完整示例
96
125
 
97
126
  ```ts
98
127
  // 安装 npm install @aiot/emulator
99
- import { IAvdArchType, VelaAvdCls, VelaImageType } from '@aiot/emulator'
128
+ import os from 'os'
129
+ import path from 'path'
130
+ import { IAvdArchType, VvdManager, VelaImageType } from '@aiot-toolkit/emulator'
100
131
 
101
- const velaAvdCls = new VelaAvdCls({})
132
+ const velaAvdCls = new VvdManager({
133
+ sdkHome: path.resolve(os.homedir(), '.export_dev')
134
+ })
102
135
 
103
136
  /** 创建一个 466 × 466 带 miwear 的模拟器 */
104
137
  velaAvdCls.createVvd({
105
- avdName: 'O62',
106
- avdArch: IAvdArchType.arm64,
107
- avdHeight: '466',
108
- avdWidth: '466',
138
+ name: 'O62',
139
+ arch: IAvdArchType.arm64,
140
+ height: '466',
141
+ width: '466',
109
142
  imageType: VelaImageType.REL
110
143
  })
111
144
 
112
145
  /** 启动名为 'O62' 的模拟器 */
113
146
  velaAvdCls.startVvd({
114
- avdName: 'O62'
147
+ vvdName: 'O62'
115
148
  })
116
149
 
117
150
  export async function startVvd(vvdName: string) {}
@@ -0,0 +1,2 @@
1
+ This contains all the protobuf files that are shipped with the emulator.
2
+ These were taken at sha b5705ca57ad61b81413aca46d82baf5ceeaeed8c