rust-rpa 0.2.5 → 0.2.6-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 +13 -2
- package/index.d.ts +30 -28
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -205,7 +205,7 @@ main();
|
|
|
205
205
|
- `setBounds(bounds)` - 设置窗口边界
|
|
206
206
|
- `toJSON()` - 转为 JSON 对象
|
|
207
207
|
- `captureImage(options?)` - 截图
|
|
208
|
-
- `watchChanges(options?, callback)` - 监听窗口内容变化;返回 `WindowWatcher`(`stop()` / `isRunning()
|
|
208
|
+
- `watchChanges(options?, callback)` - 监听窗口内容变化;返回 `WindowWatcher`(`stop()` / `isRunning()`),回调无参数;`stableFrames` 选项可过滤光标闪烁等瞬态变化
|
|
209
209
|
- `recognizeText(options?)` - OCR 识别文字
|
|
210
210
|
- `findText(text, options?)` - 查找文字
|
|
211
211
|
- `findIcon(template, options?)` - 查找图标
|
|
@@ -591,6 +591,17 @@ if (targetWindow) {
|
|
|
591
591
|
|
|
592
592
|
## 更新日志
|
|
593
593
|
|
|
594
|
+
### 0.2.6
|
|
595
|
+
|
|
596
|
+
#### 新功能
|
|
597
|
+
|
|
598
|
+
- **Window.watchChanges 新增 `stableFrames` 选项**: 支持过滤光标闪烁等瞬态变化,仅检测真实内容变化
|
|
599
|
+
- `stableFrames: 0`(默认)- 检测到变化即触发回调,最快响应
|
|
600
|
+
- `stableFrames: N` - 需连续 N 帧与上一帧相比均有变化才触发回调
|
|
601
|
+
- 过滤光标闪烁原理:光标闪烁 ON→OFF 一次变化、OFF→OFF 无变化则计数重置,无法连续 N 帧;而真实内容变化(新消息出现)会持续与旧基线不同,连续 N 帧均有变化
|
|
602
|
+
- 推荐 `stableFrames: 2` 可过滤大多数光标闪烁
|
|
603
|
+
- 示例:`window.watchChanges({ threshold: 0.02, stableFrames: 2 }, callback)`
|
|
604
|
+
|
|
594
605
|
### 0.2.5
|
|
595
606
|
|
|
596
607
|
#### 改进
|
|
@@ -625,7 +636,7 @@ if (targetWindow) {
|
|
|
625
636
|
|
|
626
637
|
#### 新功能
|
|
627
638
|
|
|
628
|
-
- **Window.watchChanges(窗口内容变化监听)**: 后台线程降采样对比相邻帧,超过阈值才截取完整窗口图并回调;支持 `threshold`、`from`(`window`/`screen`)、`region`、`captureSize
|
|
639
|
+
- **Window.watchChanges(窗口内容变化监听)**: 后台线程降采样对比相邻帧,超过阈值才截取完整窗口图并回调;支持 `threshold`、`from`(`window`/`screen`)、`region`、`captureSize`;返回 `WindowWatcher` 可 `stop()`。
|
|
629
640
|
|
|
630
641
|
### 0.2.3
|
|
631
642
|
|
package/index.d.ts
CHANGED
|
@@ -271,11 +271,22 @@ export interface WindowWatchOptionsJs {
|
|
|
271
271
|
region?: CaptureRegion | null
|
|
272
272
|
/** 检测到变化后传递给回调的截图目标尺寸 */
|
|
273
273
|
captureSize?: CaptureSizeJs | null
|
|
274
|
-
/**
|
|
275
|
-
|
|
274
|
+
/**
|
|
275
|
+
* 变化确认帧数,默认 0
|
|
276
|
+
*
|
|
277
|
+
* - 0 表示检测到变化即触发回调(最快响应)
|
|
278
|
+
* - 大于 0 时,需连续 N 帧与上一帧相比均有变化才触发回调
|
|
279
|
+
*
|
|
280
|
+
* 适用于过滤光标闪烁等瞬态变化:光标闪烁在 ON/OFF 间交替,
|
|
281
|
+
* ON→OFF 一次变化、OFF→OFF 无变化则计数重置,无法连续 N 帧;
|
|
282
|
+
* 而真实内容变化(如新消息出现)会持续与旧基线不同,
|
|
283
|
+
* 连续 N 帧均有变化,通过确认。
|
|
284
|
+
* 推荐 stableFrames=2 可过滤大多数光标闪烁。
|
|
285
|
+
*/
|
|
286
|
+
stableFrames?: number
|
|
276
287
|
}
|
|
277
288
|
/** 窗口内容变化监听的回调函数签名 */
|
|
278
|
-
export type WindowChangeCallback = (
|
|
289
|
+
export type WindowChangeCallback = () => void
|
|
279
290
|
/** 窗口变化监听器句柄,用于停止监听 */
|
|
280
291
|
export interface WindowWatcher {
|
|
281
292
|
/** 停止监听,释放底层资源 */
|
|
@@ -1295,57 +1306,48 @@ export declare class Window {
|
|
|
1295
1306
|
*/
|
|
1296
1307
|
clickIcon(template: ImageData, options?: WindowWaitOptions | null): Promise<ClickResult>
|
|
1297
1308
|
/**
|
|
1298
|
-
*
|
|
1309
|
+
* 监听窗口内容变化,当检测到变化时触发回调函数
|
|
1299
1310
|
*
|
|
1300
|
-
*
|
|
1311
|
+
* 底层使用降采样差异检测,仅在窗口内容发生变化时才触发回调,
|
|
1301
1312
|
* 资源开销远低于定时轮询截图。
|
|
1302
1313
|
*
|
|
1303
1314
|
* @param options 监听选项(可选)
|
|
1304
|
-
* @param callback
|
|
1315
|
+
* @param callback 变化时的回调函数(无参数)
|
|
1305
1316
|
* @returns WindowWatcher 句柄,调用 stop() 可停止监听
|
|
1306
1317
|
*
|
|
1307
1318
|
* @example
|
|
1308
1319
|
* ```javascript
|
|
1309
|
-
* // 场景 1
|
|
1320
|
+
* // 场景 1:监听窗口变化
|
|
1310
1321
|
* const watcher = targetWindow.watchChanges(
|
|
1311
1322
|
* { threshold: 0.02, from: 'window' },
|
|
1312
|
-
* (
|
|
1313
|
-
* console.log(
|
|
1314
|
-
* sendToExternalService(image);
|
|
1323
|
+
* () => {
|
|
1324
|
+
* console.log('窗口内容发生了变化');
|
|
1315
1325
|
* }
|
|
1316
1326
|
* );
|
|
1317
1327
|
* ```
|
|
1318
1328
|
*
|
|
1319
1329
|
* @example
|
|
1320
1330
|
* ```javascript
|
|
1321
|
-
* // 场景 2
|
|
1331
|
+
* // 场景 2:仅监听窗口的特定区域
|
|
1322
1332
|
* const watcher = targetWindow.watchChanges(
|
|
1323
|
-
* {
|
|
1324
|
-
*
|
|
1325
|
-
*
|
|
1326
|
-
*
|
|
1333
|
+
* {
|
|
1334
|
+
* region: { x: 100, y: 200, width: 400, height: 300 },
|
|
1335
|
+
* },
|
|
1336
|
+
* () => {
|
|
1337
|
+
* console.log('指定区域内容发生了变化');
|
|
1327
1338
|
* }
|
|
1328
1339
|
* );
|
|
1329
1340
|
* ```
|
|
1330
1341
|
*
|
|
1331
1342
|
* @example
|
|
1332
1343
|
* ```javascript
|
|
1333
|
-
* // 场景 3
|
|
1344
|
+
* // 场景 3:忽略光标闪烁,仅检测真实内容变化
|
|
1334
1345
|
* const watcher = targetWindow.watchChanges(
|
|
1335
|
-
* {
|
|
1336
|
-
*
|
|
1337
|
-
*
|
|
1338
|
-
* sendImage: true
|
|
1339
|
-
* },
|
|
1340
|
-
* (image) => {
|
|
1341
|
-
* processScreenshot(image);
|
|
1346
|
+
* { threshold: 0.02, stableFrames: 2 },
|
|
1347
|
+
* () => {
|
|
1348
|
+
* console.log('窗口内容发生持久变化');
|
|
1342
1349
|
* }
|
|
1343
1350
|
* );
|
|
1344
|
-
*
|
|
1345
|
-
* // 停止监听
|
|
1346
|
-
* setTimeout(() => {
|
|
1347
|
-
* watcher.stop();
|
|
1348
|
-
* }, 60000);
|
|
1349
1351
|
* ```
|
|
1350
1352
|
*/
|
|
1351
1353
|
watchChanges(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rust-rpa",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6-beta.2",
|
|
4
4
|
"description": "Rust-based RPA automation library for Node.js",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "index.js",
|
|
@@ -67,9 +67,9 @@
|
|
|
67
67
|
"commander": "^14.0.3"
|
|
68
68
|
},
|
|
69
69
|
"optionalDependencies": {
|
|
70
|
-
"@alibot/rust-rpa-win32-x64-msvc": "0.2.
|
|
71
|
-
"@alibot/rust-rpa-win32-ia32-msvc": "0.2.
|
|
72
|
-
"@alibot/rust-rpa-darwin-x64": "0.2.
|
|
73
|
-
"@alibot/rust-rpa-darwin-arm64": "0.2.
|
|
70
|
+
"@alibot/rust-rpa-win32-x64-msvc": "0.2.6-beta.2",
|
|
71
|
+
"@alibot/rust-rpa-win32-ia32-msvc": "0.2.6-beta.2",
|
|
72
|
+
"@alibot/rust-rpa-darwin-x64": "0.2.6-beta.2",
|
|
73
|
+
"@alibot/rust-rpa-darwin-arm64": "0.2.6-beta.2"
|
|
74
74
|
}
|
|
75
75
|
}
|