@midscene/android 0.29.5 → 0.29.7-beta-20250930025459.0
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/es/index.mjs +13 -19
- package/dist/lib/index.js +12 -18
- package/dist/types/index.d.ts +2 -1
- package/package.json +4 -4
package/dist/es/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { getMidsceneLocationSchema, z } from "@midscene/core";
|
|
|
6
6
|
import { defineAction, defineActionDoubleClick, defineActionDragAndDrop, defineActionKeyboardPress, defineActionScroll, defineActionTap } from "@midscene/core/device";
|
|
7
7
|
import { getTmpFile, sleep } from "@midscene/core/utils";
|
|
8
8
|
import { MIDSCENE_ADB_PATH, MIDSCENE_ADB_REMOTE_HOST, MIDSCENE_ADB_REMOTE_PORT, MIDSCENE_ANDROID_IME_STRATEGY, globalConfigManager, overrideAIConfig } from "@midscene/shared/env";
|
|
9
|
-
import { createImgBase64ByFormat, isValidPNGImageBuffer
|
|
9
|
+
import { createImgBase64ByFormat, isValidPNGImageBuffer } from "@midscene/shared/img";
|
|
10
10
|
import { getDebug } from "@midscene/shared/logger";
|
|
11
11
|
import { repeat, uuid } from "@midscene/shared/utils";
|
|
12
12
|
import { ADB } from "appium-adb";
|
|
@@ -353,6 +353,13 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
353
353
|
};
|
|
354
354
|
throw new Error(`Failed to get screen size, output: ${stdout}`);
|
|
355
355
|
}
|
|
356
|
+
async initializeDevicePixelRatio() {
|
|
357
|
+
if (this.devicePixelRatioInitialized) return;
|
|
358
|
+
const densityNum = await this.getDisplayDensity();
|
|
359
|
+
this.devicePixelRatio = Number(densityNum) / 160;
|
|
360
|
+
debugDevice(`Initialized device pixel ratio: ${this.devicePixelRatio}`);
|
|
361
|
+
this.devicePixelRatioInitialized = true;
|
|
362
|
+
}
|
|
356
363
|
async getDisplayDensity() {
|
|
357
364
|
var _this_options;
|
|
358
365
|
const adb = await this.getAdb();
|
|
@@ -415,15 +422,15 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
415
422
|
return orientation;
|
|
416
423
|
}
|
|
417
424
|
async size() {
|
|
425
|
+
await this.initializeDevicePixelRatio();
|
|
418
426
|
const screenSize = await this.getScreenSize();
|
|
419
427
|
const match = (screenSize.override || screenSize.physical).match(/(\d+)x(\d+)/);
|
|
420
428
|
if (!match || match.length < 3) throw new Error(`Unable to parse screen size: ${screenSize}`);
|
|
421
429
|
const isLandscape = 1 === screenSize.orientation || 3 === screenSize.orientation;
|
|
422
430
|
const width = Number.parseInt(match[isLandscape ? 2 : 1], 10);
|
|
423
431
|
const height = Number.parseInt(match[isLandscape ? 1 : 2], 10);
|
|
424
|
-
const
|
|
425
|
-
|
|
426
|
-
const { x: logicalWidth, y: logicalHeight } = this.reverseAdjustCoordinates(width, height);
|
|
432
|
+
const logicalWidth = Math.round(width / this.devicePixelRatio);
|
|
433
|
+
const logicalHeight = Math.round(height / this.devicePixelRatio);
|
|
427
434
|
return {
|
|
428
435
|
width: logicalWidth,
|
|
429
436
|
height: logicalHeight,
|
|
@@ -437,13 +444,6 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
437
444
|
y: Math.round(y * ratio)
|
|
438
445
|
};
|
|
439
446
|
}
|
|
440
|
-
reverseAdjustCoordinates(x, y) {
|
|
441
|
-
const ratio = this.devicePixelRatio;
|
|
442
|
-
return {
|
|
443
|
-
x: Math.round(x / ratio),
|
|
444
|
-
y: Math.round(y / ratio)
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
447
|
calculateScrollEndPoint(start, deltaX, deltaY, maxWidth, maxHeight) {
|
|
448
448
|
const minScrollDistance = 50;
|
|
449
449
|
let actualScrollDistanceX = 0;
|
|
@@ -470,7 +470,6 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
470
470
|
async screenshotBase64() {
|
|
471
471
|
var _this_options;
|
|
472
472
|
debugDevice('screenshotBase64 begin');
|
|
473
|
-
const { width, height } = await this.size();
|
|
474
473
|
const adb = await this.getAdb();
|
|
475
474
|
let screenshotBuffer;
|
|
476
475
|
const androidScreenshotPath = `/data/local/tmp/midscene_screenshot_${uuid()}.png`;
|
|
@@ -512,14 +511,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
512
511
|
await adb.shell(`rm ${androidScreenshotPath}`);
|
|
513
512
|
}
|
|
514
513
|
}
|
|
515
|
-
debugDevice('Resizing screenshot image');
|
|
516
|
-
const { buffer, format } = await resizeAndConvertImgBuffer('png', screenshotBuffer, {
|
|
517
|
-
width,
|
|
518
|
-
height
|
|
519
|
-
});
|
|
520
|
-
debugDevice('Image resize completed');
|
|
521
514
|
debugDevice('Converting to base64');
|
|
522
|
-
const result = createImgBase64ByFormat(
|
|
515
|
+
const result = createImgBase64ByFormat('png', screenshotBuffer.toString('base64'));
|
|
523
516
|
debugDevice('screenshotBase64 end');
|
|
524
517
|
return result;
|
|
525
518
|
}
|
|
@@ -905,6 +898,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
905
898
|
_define_property(this, "deviceId", void 0);
|
|
906
899
|
_define_property(this, "yadbPushed", false);
|
|
907
900
|
_define_property(this, "devicePixelRatio", 1);
|
|
901
|
+
_define_property(this, "devicePixelRatioInitialized", false);
|
|
908
902
|
_define_property(this, "adb", null);
|
|
909
903
|
_define_property(this, "connectingAdb", null);
|
|
910
904
|
_define_property(this, "destroyed", false);
|
package/dist/lib/index.js
CHANGED
|
@@ -399,6 +399,13 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
399
399
|
};
|
|
400
400
|
throw new Error(`Failed to get screen size, output: ${stdout}`);
|
|
401
401
|
}
|
|
402
|
+
async initializeDevicePixelRatio() {
|
|
403
|
+
if (this.devicePixelRatioInitialized) return;
|
|
404
|
+
const densityNum = await this.getDisplayDensity();
|
|
405
|
+
this.devicePixelRatio = Number(densityNum) / 160;
|
|
406
|
+
debugDevice(`Initialized device pixel ratio: ${this.devicePixelRatio}`);
|
|
407
|
+
this.devicePixelRatioInitialized = true;
|
|
408
|
+
}
|
|
402
409
|
async getDisplayDensity() {
|
|
403
410
|
var _this_options;
|
|
404
411
|
const adb = await this.getAdb();
|
|
@@ -461,15 +468,15 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
461
468
|
return orientation;
|
|
462
469
|
}
|
|
463
470
|
async size() {
|
|
471
|
+
await this.initializeDevicePixelRatio();
|
|
464
472
|
const screenSize = await this.getScreenSize();
|
|
465
473
|
const match = (screenSize.override || screenSize.physical).match(/(\d+)x(\d+)/);
|
|
466
474
|
if (!match || match.length < 3) throw new Error(`Unable to parse screen size: ${screenSize}`);
|
|
467
475
|
const isLandscape = 1 === screenSize.orientation || 3 === screenSize.orientation;
|
|
468
476
|
const width = Number.parseInt(match[isLandscape ? 2 : 1], 10);
|
|
469
477
|
const height = Number.parseInt(match[isLandscape ? 1 : 2], 10);
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
const { x: logicalWidth, y: logicalHeight } = this.reverseAdjustCoordinates(width, height);
|
|
478
|
+
const logicalWidth = Math.round(width / this.devicePixelRatio);
|
|
479
|
+
const logicalHeight = Math.round(height / this.devicePixelRatio);
|
|
473
480
|
return {
|
|
474
481
|
width: logicalWidth,
|
|
475
482
|
height: logicalHeight,
|
|
@@ -483,13 +490,6 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
483
490
|
y: Math.round(y * ratio)
|
|
484
491
|
};
|
|
485
492
|
}
|
|
486
|
-
reverseAdjustCoordinates(x, y) {
|
|
487
|
-
const ratio = this.devicePixelRatio;
|
|
488
|
-
return {
|
|
489
|
-
x: Math.round(x / ratio),
|
|
490
|
-
y: Math.round(y / ratio)
|
|
491
|
-
};
|
|
492
|
-
}
|
|
493
493
|
calculateScrollEndPoint(start, deltaX, deltaY, maxWidth, maxHeight) {
|
|
494
494
|
const minScrollDistance = 50;
|
|
495
495
|
let actualScrollDistanceX = 0;
|
|
@@ -516,7 +516,6 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
516
516
|
async screenshotBase64() {
|
|
517
517
|
var _this_options;
|
|
518
518
|
debugDevice('screenshotBase64 begin');
|
|
519
|
-
const { width, height } = await this.size();
|
|
520
519
|
const adb = await this.getAdb();
|
|
521
520
|
let screenshotBuffer;
|
|
522
521
|
const androidScreenshotPath = `/data/local/tmp/midscene_screenshot_${(0, shared_utils_namespaceObject.uuid)()}.png`;
|
|
@@ -558,14 +557,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
558
557
|
await adb.shell(`rm ${androidScreenshotPath}`);
|
|
559
558
|
}
|
|
560
559
|
}
|
|
561
|
-
debugDevice('Resizing screenshot image');
|
|
562
|
-
const { buffer, format } = await (0, img_namespaceObject.resizeAndConvertImgBuffer)('png', screenshotBuffer, {
|
|
563
|
-
width,
|
|
564
|
-
height
|
|
565
|
-
});
|
|
566
|
-
debugDevice('Image resize completed');
|
|
567
560
|
debugDevice('Converting to base64');
|
|
568
|
-
const result = (0, img_namespaceObject.createImgBase64ByFormat)(
|
|
561
|
+
const result = (0, img_namespaceObject.createImgBase64ByFormat)('png', screenshotBuffer.toString('base64'));
|
|
569
562
|
debugDevice('screenshotBase64 end');
|
|
570
563
|
return result;
|
|
571
564
|
}
|
|
@@ -951,6 +944,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
951
944
|
_define_property(this, "deviceId", void 0);
|
|
952
945
|
_define_property(this, "yadbPushed", false);
|
|
953
946
|
_define_property(this, "devicePixelRatio", 1);
|
|
947
|
+
_define_property(this, "devicePixelRatioInitialized", false);
|
|
954
948
|
_define_property(this, "adb", null);
|
|
955
949
|
_define_property(this, "connectingAdb", null);
|
|
956
950
|
_define_property(this, "destroyed", false);
|
package/dist/types/index.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export declare class AndroidDevice implements AbstractInterface {
|
|
|
22
22
|
private deviceId;
|
|
23
23
|
private yadbPushed;
|
|
24
24
|
private devicePixelRatio;
|
|
25
|
+
private devicePixelRatioInitialized;
|
|
25
26
|
private adb;
|
|
26
27
|
private connectingAdb;
|
|
27
28
|
private destroyed;
|
|
@@ -45,11 +46,11 @@ export declare class AndroidDevice implements AbstractInterface {
|
|
|
45
46
|
physical: string;
|
|
46
47
|
orientation: number;
|
|
47
48
|
}>;
|
|
49
|
+
private initializeDevicePixelRatio;
|
|
48
50
|
getDisplayDensity(): Promise<number>;
|
|
49
51
|
getDisplayOrientation(): Promise<number>;
|
|
50
52
|
size(): Promise<Size>;
|
|
51
53
|
private adjustCoordinates;
|
|
52
|
-
private reverseAdjustCoordinates;
|
|
53
54
|
/**
|
|
54
55
|
* Calculate the end point for scroll operations based on start point, scroll delta, and screen boundaries.
|
|
55
56
|
* This method ensures that scroll operations stay within screen bounds and maintain a minimum scroll distance
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/android",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.7-beta-20250930025459.0",
|
|
4
4
|
"description": "Android automation library for Midscene",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Android UI automation",
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"appium-adb": "12.12.1",
|
|
30
|
-
"@midscene/
|
|
31
|
-
"@midscene/
|
|
30
|
+
"@midscene/shared": "0.29.7-beta-20250930025459.0",
|
|
31
|
+
"@midscene/core": "0.29.7-beta-20250930025459.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@rslib/core": "^0.11.2",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"typescript": "^5.8.3",
|
|
38
38
|
"tsx": "^4.19.2",
|
|
39
39
|
"vitest": "3.0.5",
|
|
40
|
-
"@midscene/playground": "0.29.
|
|
40
|
+
"@midscene/playground": "0.29.7-beta-20250930025459.0"
|
|
41
41
|
},
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"scripts": {
|