ms-vite-plugin 1.4.31 → 1.4.32

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/dist/build.js CHANGED
@@ -220,10 +220,6 @@ const buildAll = async (isDev = true, workspacePath) => {
220
220
  disableConsoleOutput: false,
221
221
  domainLock: [],
222
222
  selfDefending: false,
223
- // 注入到引擎的全局对象与方法(如 paddleOcr.recognizeAbs、ms、ui、http…)
224
- // 由原生侧按“名称字符串”绑定,一旦被改名原生就找不到对应实现。
225
- // 这里强制关闭全局名 / 属性名改写,避免任何 obfuscator.json 误开导致注入 API 被混淆。
226
- // 如确需对自有属性做重命名,请改用 renamePropertiesMode + reservedNames 白名单。
227
223
  renameGlobals: false,
228
224
  renameProperties: false,
229
225
  },
@@ -459,25 +459,32 @@ logi(`CPU 限流延迟: ${delay.minMs}~${delay.maxMs}ms`);
459
459
  设置停止回调函数。此回调注册接口只能在主线程调用,不能在线程脚本中调用。
460
460
 
461
461
  ```typescript
462
- function setStopCallback(callback: () => void): void;
462
+ function setStopCallback(
463
+ callback: (status: "success" | "error" | "stopped") => void,
464
+ ): void;
463
465
  ```
464
466
 
465
467
  **参数:**
466
468
 
467
- | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
468
- | ---------- | ---------- | -------- | ------ | ------------ |
469
- | `callback` | () => void | 是 | - | 停止回调函数 |
469
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
470
+ | ---------- | ------------------------------------------------------ | -------- | ------ | ------------ |
471
+ | `callback` | (status: "success" \| "error" \| "stopped") => void | 是 | - | 停止回调函数 |
470
472
 
471
473
  **说明:**
472
474
 
473
- 脚本执行完成或异常停止时调用,`exit()` 退出不会触发此回调。
475
+ 脚本执行停止时调用,`status` 表示停止状态:`success` 为正常完成,`error` 为异常停止,`stopped` 为手动停止。
474
476
 
475
477
  **示例:**
476
478
 
477
479
  ```javascript
478
- setStopCallback(() => {
479
- logi("脚本执行完成");
480
- // 执行清理工作
480
+ setStopCallback((status) => {
481
+ if (status === "success") {
482
+ logi("脚本执行完成");
483
+ } else if (status === "error") {
484
+ loge("脚本执行异常");
485
+ } else if (status === "stopped") {
486
+ logi("脚本手动停止");
487
+ }
481
488
  });
482
489
  ```
483
490
 
@@ -460,25 +460,32 @@ $打印信息日志(`CPU 限流延迟: ${延迟.minMs}~${延迟.maxMs}ms`);
460
460
  设置停止回调函数。该回调注册接口只能在主线程调用,不能在线程脚本中调用。
461
461
 
462
462
  ```typescript
463
- declare const $设置停止回调: (回调: () => 无返回值) => 无返回值;
463
+ declare const $设置停止回调: (
464
+ 回调: (状态: "success" | "error" | "stopped") => 无返回值,
465
+ ) => 无返回值;
464
466
  ```
465
467
 
466
468
  **参数:**
467
469
 
468
- | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
469
- | ------ | -------------- | -------- | ------ | ------------ |
470
- | `回调` | () => 无返回值 | 是 | - | 停止回调函数 |
470
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
471
+ | ------ | ---------------------------------------------------------- | -------- | ------ | ------------ |
472
+ | `回调` | (状态: "success" \| "error" \| "stopped") => 无返回值 | 是 | - | 停止回调函数 |
471
473
 
472
474
  **说明:**
473
475
 
474
- 脚本执行完成或异常停止时调用,`$退出脚本()` 退出不会触发此回调。
476
+ 脚本执行停止时调用,`状态` 表示停止状态:`success` 为正常完成,`error` 为异常停止,`stopped` 为手动停止。
475
477
 
476
478
  **示例:**
477
479
 
478
480
  ```javascript
479
- $设置停止回调(() => {
480
- $打印信息日志("脚本执行完成");
481
- // 执行清理工作
481
+ $设置停止回调((状态) => {
482
+ if (状态 === "success") {
483
+ $打印信息日志("脚本执行完成");
484
+ } else if (状态 === "error") {
485
+ $打印错误日志("脚本执行异常");
486
+ } else if (状态 === "stopped") {
487
+ $打印信息日志("脚本手动停止");
488
+ }
482
489
  });
483
490
  ```
484
491
 
@@ -7,6 +7,7 @@
7
7
  - 应用信息常量:版本号/构建号/名称/包名
8
8
  - 前台切换:将宿主应用切到前台
9
9
  - Agent 设置:读取和设置 Agent 快速模式
10
+ - 脚本生命周期:设置停止回调和异常停止回调
10
11
 
11
12
  ## 常量
12
13
 
@@ -226,6 +227,69 @@ from kuaijs import g
226
227
  g.restartScript()
227
228
  ```
228
229
 
230
+ #### `setStopCallback` - 设置停止回调
231
+
232
+ 设置脚本停止回调函数。回调只在主脚本结束时调用,不能在线程脚本中分别注册。
233
+
234
+ ```python
235
+ def setStopCallback(callback: Callable[[Literal["success", "error", "stopped"]], None] | None) -> None
236
+ ```
237
+
238
+ **参数:**
239
+
240
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
241
+ | ---------- | --------------------------------------------------------- | -------- | ------ | ---- |
242
+ | `callback` | `Callable[[Literal["success", "error", "stopped"]], None]` 或 `None` | 是 | - | 停止回调函数,传 `None` 取消回调 |
243
+
244
+ **状态值:**
245
+
246
+ | 状态 | 描述 |
247
+ | ---- | ---- |
248
+ | `success` | 脚本正常执行完成 |
249
+ | `error` | 脚本发生未捕获异常 |
250
+ | `stopped` | 脚本被手动停止或主动退出 |
251
+
252
+ **示例:**
253
+
254
+ ```python
255
+ from kuaijs import g
256
+
257
+ def on_stop(status: str) -> None:
258
+ if status == "success":
259
+ print("脚本执行完成")
260
+ elif status == "error":
261
+ print("脚本执行异常")
262
+ elif status == "stopped":
263
+ print("脚本手动停止")
264
+
265
+ g.setStopCallback(on_stop)
266
+ ```
267
+
268
+ #### `setExceptionCallback` - 设置异常停止回调
269
+
270
+ 设置脚本异常停止回调函数。该回调只在主脚本发生未捕获异常时调用,并且会早于 `setStopCallback` 注册的停止回调执行。
271
+
272
+ ```python
273
+ def setExceptionCallback(callback: Callable[[], None] | None) -> None
274
+ ```
275
+
276
+ **参数:**
277
+
278
+ | 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
279
+ | ---------- | ---------------------------- | -------- | ------ | ---- |
280
+ | `callback` | `Callable[[], None]` 或 `None` | 是 | - | 异常停止回调函数,传 `None` 取消回调 |
281
+
282
+ **示例:**
283
+
284
+ ```python
285
+ from kuaijs import g
286
+
287
+ def on_exception() -> None:
288
+ print("脚本异常停止")
289
+
290
+ g.setExceptionCallback(on_exception)
291
+ ```
292
+
229
293
  #### `loadDex` - 加载指定的 dex、apk 文件
230
294
 
231
295
  **注意:**
@@ -299,6 +299,92 @@ GET /api/activeAppInfo
299
299
  | »» bundleId | string | true | none | 应用包名 | none |
300
300
  | »» pid | integer | true | none | | none |
301
301
 
302
+ ## GET 获取锁屏状态
303
+
304
+ GET /api/isLocked
305
+
306
+ > 返回示例
307
+
308
+ > 200 Response
309
+
310
+ ```json
311
+ {
312
+ "success": true,
313
+ "data": false
314
+ }
315
+ ```
316
+
317
+ ### 返回结果
318
+
319
+ | 状态码 | 状态码含义 | 说明 | 数据模型 |
320
+ | ------ | ------------------------------------------------------- | ---- | -------- |
321
+ | 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | none | Inline |
322
+
323
+ ### 返回数据结构
324
+
325
+ 状态码 **200**
326
+
327
+ | 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
328
+ | --------- | ------- | ---- | ---- | -------- | ---- |
329
+ | » success | boolean | true | none | 是否成功 | none |
330
+ | » data | boolean | true | none | 是否锁屏 | `true` 表示已锁屏,`false` 表示未锁屏 |
331
+
332
+ ## GET 锁屏
333
+
334
+ GET /api/lock
335
+
336
+ > 返回示例
337
+
338
+ > 200 Response
339
+
340
+ ```json
341
+ {
342
+ "success": true
343
+ }
344
+ ```
345
+
346
+ ### 返回结果
347
+
348
+ | 状态码 | 状态码含义 | 说明 | 数据模型 |
349
+ | ------ | ------------------------------------------------------- | ---- | -------- |
350
+ | 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | none | Inline |
351
+
352
+ ### 返回数据结构
353
+
354
+ 状态码 **200**
355
+
356
+ | 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
357
+ | --------- | ------- | ---- | ---- | -------- | ---- |
358
+ | » success | boolean | true | none | 是否成功 | none |
359
+
360
+ ## GET 解锁
361
+
362
+ GET /api/unlock
363
+
364
+ > 返回示例
365
+
366
+ > 200 Response
367
+
368
+ ```json
369
+ {
370
+ "success": true
371
+ }
372
+ ```
373
+
374
+ ### 返回结果
375
+
376
+ | 状态码 | 状态码含义 | 说明 | 数据模型 |
377
+ | ------ | ------------------------------------------------------- | ---- | -------- |
378
+ | 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | none | Inline |
379
+
380
+ ### 返回数据结构
381
+
382
+ 状态码 **200**
383
+
384
+ | 名称 | 类型 | 必选 | 约束 | 中文名 | 说明 |
385
+ | --------- | ------- | ---- | ---- | -------- | ---- |
386
+ | » success | boolean | true | none | 是否成功 | none |
387
+
302
388
  ## GET 获取屏幕亮度
303
389
 
304
390
  GET /api/getScreenBrightness
@@ -789,7 +875,7 @@ WebSocket Upgrade /mirror/ws
789
875
 
790
876
  | 名称 | 位置 | 类型 | 必选 | 中文名 | 说明 |
791
877
  | ------------- | ----- | ------- | ---- | ------ | ---------------------------- |
792
- | fps | query | integer | 否 | | 帧率,默认 10,范围 1-30 |
878
+ | fps | query | integer | 否 | | 帧率,默认 10,范围 1-60 |
793
879
  | quality | query | number | 否 | | 质量,默认 0.25,范围 0.1-1.0 |
794
880
  | scalingFactor | query | number | 否 | | 缩放比例,默认 1.0,范围 0.1-1.0 |
795
881
 
@@ -797,6 +883,40 @@ WebSocket Upgrade /mirror/ws
797
883
 
798
884
  连接成功后服务端持续发送 JPEG 二进制 WebSocket frame;客户端不需要发送业务消息。
799
885
 
886
+ ## HTTP-FLV 实时屏幕画面流
887
+
888
+ GET /mirror/flv
889
+
890
+ ### 请求参数
891
+
892
+ | 名称 | 位置 | 类型 | 必选 | 中文名 | 说明 |
893
+ | ------------- | ----- | ------- | ---- | ------ | ----------------------------------- |
894
+ | fps | query | integer | 否 | | 帧率,默认 10,范围 1-60 |
895
+ | quality | query | number | 否 | | JPEG 源质量,默认 0.25,范围 0.1-1.0 |
896
+ | scalingFactor | query | number | 否 | | 缩放比例,默认 1.0,范围 0.1-1.0 |
897
+ | bitrate | query | number | 否 | | H.264 目标码率,单位 Mbps,默认 4 |
898
+
899
+ ### 返回数据
900
+
901
+ 响应类型为 `video/x-flv`,服务端持续输出 FLV 容器内的 H.264 视频 tag。
902
+
903
+ ## WHEP 实时屏幕画面流
904
+
905
+ POST /mirror/whep
906
+
907
+ ### 请求参数
908
+
909
+ | 名称 | 位置 | 类型 | 必选 | 中文名 | 说明 |
910
+ | ------------- | ----- | ------- | ---- | ------ | ----------------------------------- |
911
+ | fps | query | integer | 否 | | 帧率,默认 10,范围 1-60 |
912
+ | quality | query | number | 否 | | JPEG 源质量,默认 0.25,范围 0.1-1.0 |
913
+ | scalingFactor | query | number | 否 | | 缩放比例,默认 1.0,范围 0.1-1.0 |
914
+ | bitrate | query | number | 否 | | WebRTC 发送码率,单位 Mbps,默认 4 |
915
+
916
+ ### 返回数据
917
+
918
+ 请求 body 为 `application/sdp` 的 WebRTC offer;响应类型为 `application/sdp`,内容为 WebRTC answer。
919
+
800
920
  ## POST 执行脚本(仅支持JS脚本)
801
921
 
802
922
  POST /api/runScript
@@ -2937,6 +3057,28 @@ GET /api/file/download
2937
3057
  | 401 | [Unauthorized](https://tools.ietf.org/html/rfc7235#section-3.1) | 设备未授权 | Inline |
2938
3058
  | 404 | [Not Found](https://tools.ietf.org/html/rfc7231#section-6.5.4) | 文件不存在 | Inline |
2939
3059
 
3060
+ ## GET MJPEG 镜像流
3061
+
3062
+ GET /mirror/image
3063
+
3064
+ 返回 `multipart/x-mixed-replace` MJPEG 长连接,每个 part 都是一帧 JPEG。浏览器可直接用 `<img src="/mirror/image">` 预览。
3065
+
3066
+ ### 请求参数
3067
+
3068
+ | 名称 | 位置 | 类型 | 必选 | 说明 |
3069
+ | ------------- | ----- | ------- | ---- | ---- |
3070
+ | fps | query | integer | 否 | 目标帧率,范围 1-60,默认 10 |
3071
+ | quality | query | number | 否 | JPEG 质量,范围 0.1-1.0,默认 0.25 |
3072
+ | scalingFactor | query | number | 否 | 截图缩放因子,范围 0.1-1.0,默认 1.0 |
3073
+
3074
+ ### 返回结果
3075
+
3076
+ | 状态码 | 状态码含义 | 说明 | 数据模型 |
3077
+ | ------ | ---------------------------------------------------------------- | ---- | -------- |
3078
+ | 200 | [OK](https://tools.ietf.org/html/rfc7231#section-6.3.1) | `multipart/x-mixed-replace; boundary=kuaijs-mjpeg-boundary` 流 | file |
3079
+ | 429 | [Too Many Requests](https://tools.ietf.org/html/rfc6585#section-4) | 镜像流客户端数量已满 | Inline |
3080
+ | 503 | [Service Unavailable](https://tools.ietf.org/html/rfc7231#section-6.6.4) | HID 录屏链路未就绪 | Inline |
3081
+
2940
3082
  # 数据模型
2941
3083
 
2942
3084
  <h2 id="tocS_软件状态">软件状态</h2>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ms-vite-plugin",
3
- "version": "1.4.31",
3
+ "version": "1.4.32",
4
4
  "type": "commonjs",
5
5
  "license": "MIT",
6
6
  "publishConfig": {