@midscene/android 0.30.3-beta-20251015093703.0 → 0.30.3
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 +28 -11
- package/dist/lib/index.js +28 -11
- package/dist/types/index.d.ts +3 -0
- package/package.json +4 -4
package/dist/es/index.mjs
CHANGED
|
@@ -287,12 +287,14 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
287
287
|
};
|
|
288
288
|
}
|
|
289
289
|
async getScreenSize() {
|
|
290
|
-
var _this_options;
|
|
290
|
+
var _this_options, _this_options1;
|
|
291
|
+
const shouldCache = !((null == (_this_options = this.options) ? void 0 : _this_options.alwaysFetchScreenInfo) ?? false);
|
|
292
|
+
if (shouldCache && this.cachedScreenSize) return this.cachedScreenSize;
|
|
291
293
|
const adb = await this.getAdb();
|
|
292
|
-
if ('number' == typeof (null == (
|
|
293
|
-
var
|
|
294
|
+
if ('number' == typeof (null == (_this_options1 = this.options) ? void 0 : _this_options1.displayId)) try {
|
|
295
|
+
var _this_options2;
|
|
294
296
|
const stdout = await adb.shell('dumpsys display');
|
|
295
|
-
if (null == (
|
|
297
|
+
if (null == (_this_options2 = this.options) ? void 0 : _this_options2.usePhysicalDisplayIdForDisplayLookup) {
|
|
296
298
|
const physicalDisplayId = await this.getPhysicalDisplayId();
|
|
297
299
|
if (physicalDisplayId) {
|
|
298
300
|
const lineRegex = new RegExp(`^.*uniqueId \"local:${physicalDisplayId}\".*$
|
|
@@ -308,11 +310,13 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
308
310
|
const rotation = Number(rotationMatch[1]);
|
|
309
311
|
const sizeStr = `${width}x${height}`;
|
|
310
312
|
debugDevice(`Using display info for long ID ${physicalDisplayId}: ${sizeStr}, rotation: ${rotation}`);
|
|
311
|
-
|
|
313
|
+
const result = {
|
|
312
314
|
override: sizeStr,
|
|
313
315
|
physical: sizeStr,
|
|
314
316
|
orientation: rotation
|
|
315
317
|
};
|
|
318
|
+
if (shouldCache) this.cachedScreenSize = result;
|
|
319
|
+
return result;
|
|
316
320
|
}
|
|
317
321
|
}
|
|
318
322
|
}
|
|
@@ -329,11 +333,13 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
329
333
|
const rotation = Number(orientationMatch[1]);
|
|
330
334
|
const sizeStr = `${width}x${height}`;
|
|
331
335
|
debugDevice(`Using display info for display ID ${this.options.displayId}: ${sizeStr}, rotation: ${rotation}`);
|
|
332
|
-
|
|
336
|
+
const result = {
|
|
333
337
|
override: sizeStr,
|
|
334
338
|
physical: sizeStr,
|
|
335
339
|
orientation: rotation
|
|
336
340
|
};
|
|
341
|
+
if (shouldCache) this.cachedScreenSize = result;
|
|
342
|
+
return result;
|
|
337
343
|
}
|
|
338
344
|
}
|
|
339
345
|
}
|
|
@@ -360,10 +366,14 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
360
366
|
size.physical = physicalSize[1].trim();
|
|
361
367
|
}
|
|
362
368
|
const orientation = await this.getDisplayOrientation();
|
|
363
|
-
if (size.override || size.physical)
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
369
|
+
if (size.override || size.physical) {
|
|
370
|
+
const result = {
|
|
371
|
+
...size,
|
|
372
|
+
orientation
|
|
373
|
+
};
|
|
374
|
+
if (shouldCache) this.cachedScreenSize = result;
|
|
375
|
+
return result;
|
|
376
|
+
}
|
|
367
377
|
throw new Error(`Failed to get screen size, output: ${stdout}`);
|
|
368
378
|
}
|
|
369
379
|
async initializeDevicePixelRatio() {
|
|
@@ -411,6 +421,9 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
411
421
|
return density ?? 160;
|
|
412
422
|
}
|
|
413
423
|
async getDisplayOrientation() {
|
|
424
|
+
var _this_options;
|
|
425
|
+
const shouldCache = !((null == (_this_options = this.options) ? void 0 : _this_options.alwaysFetchScreenInfo) ?? false);
|
|
426
|
+
if (shouldCache && null !== this.cachedOrientation) return this.cachedOrientation;
|
|
414
427
|
const adb = await this.getAdb();
|
|
415
428
|
let orientation = 0;
|
|
416
429
|
try {
|
|
@@ -432,6 +445,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
432
445
|
debugDevice('Failed to get orientation from display, default to 0');
|
|
433
446
|
}
|
|
434
447
|
}
|
|
448
|
+
if (shouldCache) this.cachedOrientation = orientation;
|
|
435
449
|
return orientation;
|
|
436
450
|
}
|
|
437
451
|
async size() {
|
|
@@ -920,6 +934,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
920
934
|
_define_property(this, "destroyed", false);
|
|
921
935
|
_define_property(this, "description", void 0);
|
|
922
936
|
_define_property(this, "customActions", void 0);
|
|
937
|
+
_define_property(this, "cachedScreenSize", null);
|
|
938
|
+
_define_property(this, "cachedOrientation", null);
|
|
923
939
|
_define_property(this, "interfaceType", 'android');
|
|
924
940
|
_define_property(this, "uri", void 0);
|
|
925
941
|
_define_property(this, "options", void 0);
|
|
@@ -971,7 +987,8 @@ async function agentFromAdbDevice(deviceId, opts) {
|
|
|
971
987
|
displayId: null == opts ? void 0 : opts.displayId,
|
|
972
988
|
usePhysicalDisplayIdForScreenshot: null == opts ? void 0 : opts.usePhysicalDisplayIdForScreenshot,
|
|
973
989
|
usePhysicalDisplayIdForDisplayLookup: null == opts ? void 0 : opts.usePhysicalDisplayIdForDisplayLookup,
|
|
974
|
-
screenshotResizeScale: null == opts ? void 0 : opts.screenshotResizeScale
|
|
990
|
+
screenshotResizeScale: null == opts ? void 0 : opts.screenshotResizeScale,
|
|
991
|
+
alwaysFetchScreenInfo: null == opts ? void 0 : opts.alwaysFetchScreenInfo
|
|
975
992
|
});
|
|
976
993
|
await device.connect();
|
|
977
994
|
return new AndroidAgent(device, opts);
|
package/dist/lib/index.js
CHANGED
|
@@ -333,12 +333,14 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
333
333
|
};
|
|
334
334
|
}
|
|
335
335
|
async getScreenSize() {
|
|
336
|
-
var _this_options;
|
|
336
|
+
var _this_options, _this_options1;
|
|
337
|
+
const shouldCache = !((null == (_this_options = this.options) ? void 0 : _this_options.alwaysFetchScreenInfo) ?? false);
|
|
338
|
+
if (shouldCache && this.cachedScreenSize) return this.cachedScreenSize;
|
|
337
339
|
const adb = await this.getAdb();
|
|
338
|
-
if ('number' == typeof (null == (
|
|
339
|
-
var
|
|
340
|
+
if ('number' == typeof (null == (_this_options1 = this.options) ? void 0 : _this_options1.displayId)) try {
|
|
341
|
+
var _this_options2;
|
|
340
342
|
const stdout = await adb.shell('dumpsys display');
|
|
341
|
-
if (null == (
|
|
343
|
+
if (null == (_this_options2 = this.options) ? void 0 : _this_options2.usePhysicalDisplayIdForDisplayLookup) {
|
|
342
344
|
const physicalDisplayId = await this.getPhysicalDisplayId();
|
|
343
345
|
if (physicalDisplayId) {
|
|
344
346
|
const lineRegex = new RegExp(`^.*uniqueId \"local:${physicalDisplayId}\".*$
|
|
@@ -354,11 +356,13 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
354
356
|
const rotation = Number(rotationMatch[1]);
|
|
355
357
|
const sizeStr = `${width}x${height}`;
|
|
356
358
|
debugDevice(`Using display info for long ID ${physicalDisplayId}: ${sizeStr}, rotation: ${rotation}`);
|
|
357
|
-
|
|
359
|
+
const result = {
|
|
358
360
|
override: sizeStr,
|
|
359
361
|
physical: sizeStr,
|
|
360
362
|
orientation: rotation
|
|
361
363
|
};
|
|
364
|
+
if (shouldCache) this.cachedScreenSize = result;
|
|
365
|
+
return result;
|
|
362
366
|
}
|
|
363
367
|
}
|
|
364
368
|
}
|
|
@@ -375,11 +379,13 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
375
379
|
const rotation = Number(orientationMatch[1]);
|
|
376
380
|
const sizeStr = `${width}x${height}`;
|
|
377
381
|
debugDevice(`Using display info for display ID ${this.options.displayId}: ${sizeStr}, rotation: ${rotation}`);
|
|
378
|
-
|
|
382
|
+
const result = {
|
|
379
383
|
override: sizeStr,
|
|
380
384
|
physical: sizeStr,
|
|
381
385
|
orientation: rotation
|
|
382
386
|
};
|
|
387
|
+
if (shouldCache) this.cachedScreenSize = result;
|
|
388
|
+
return result;
|
|
383
389
|
}
|
|
384
390
|
}
|
|
385
391
|
}
|
|
@@ -406,10 +412,14 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
406
412
|
size.physical = physicalSize[1].trim();
|
|
407
413
|
}
|
|
408
414
|
const orientation = await this.getDisplayOrientation();
|
|
409
|
-
if (size.override || size.physical)
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
415
|
+
if (size.override || size.physical) {
|
|
416
|
+
const result = {
|
|
417
|
+
...size,
|
|
418
|
+
orientation
|
|
419
|
+
};
|
|
420
|
+
if (shouldCache) this.cachedScreenSize = result;
|
|
421
|
+
return result;
|
|
422
|
+
}
|
|
413
423
|
throw new Error(`Failed to get screen size, output: ${stdout}`);
|
|
414
424
|
}
|
|
415
425
|
async initializeDevicePixelRatio() {
|
|
@@ -457,6 +467,9 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
457
467
|
return density ?? 160;
|
|
458
468
|
}
|
|
459
469
|
async getDisplayOrientation() {
|
|
470
|
+
var _this_options;
|
|
471
|
+
const shouldCache = !((null == (_this_options = this.options) ? void 0 : _this_options.alwaysFetchScreenInfo) ?? false);
|
|
472
|
+
if (shouldCache && null !== this.cachedOrientation) return this.cachedOrientation;
|
|
460
473
|
const adb = await this.getAdb();
|
|
461
474
|
let orientation = 0;
|
|
462
475
|
try {
|
|
@@ -478,6 +491,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
478
491
|
debugDevice('Failed to get orientation from display, default to 0');
|
|
479
492
|
}
|
|
480
493
|
}
|
|
494
|
+
if (shouldCache) this.cachedOrientation = orientation;
|
|
481
495
|
return orientation;
|
|
482
496
|
}
|
|
483
497
|
async size() {
|
|
@@ -966,6 +980,8 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
|
|
|
966
980
|
_define_property(this, "destroyed", false);
|
|
967
981
|
_define_property(this, "description", void 0);
|
|
968
982
|
_define_property(this, "customActions", void 0);
|
|
983
|
+
_define_property(this, "cachedScreenSize", null);
|
|
984
|
+
_define_property(this, "cachedOrientation", null);
|
|
969
985
|
_define_property(this, "interfaceType", 'android');
|
|
970
986
|
_define_property(this, "uri", void 0);
|
|
971
987
|
_define_property(this, "options", void 0);
|
|
@@ -1018,7 +1034,8 @@ async function agentFromAdbDevice(deviceId, opts) {
|
|
|
1018
1034
|
displayId: null == opts ? void 0 : opts.displayId,
|
|
1019
1035
|
usePhysicalDisplayIdForScreenshot: null == opts ? void 0 : opts.usePhysicalDisplayIdForScreenshot,
|
|
1020
1036
|
usePhysicalDisplayIdForDisplayLookup: null == opts ? void 0 : opts.usePhysicalDisplayIdForDisplayLookup,
|
|
1021
|
-
screenshotResizeScale: null == opts ? void 0 : opts.screenshotResizeScale
|
|
1037
|
+
screenshotResizeScale: null == opts ? void 0 : opts.screenshotResizeScale,
|
|
1038
|
+
alwaysFetchScreenInfo: null == opts ? void 0 : opts.alwaysFetchScreenInfo
|
|
1022
1039
|
});
|
|
1023
1040
|
await device.connect();
|
|
1024
1041
|
return new AndroidAgent(device, opts);
|
package/dist/types/index.d.ts
CHANGED
|
@@ -30,6 +30,8 @@ export declare class AndroidDevice implements AbstractInterface {
|
|
|
30
30
|
private destroyed;
|
|
31
31
|
private description;
|
|
32
32
|
private customActions?;
|
|
33
|
+
private cachedScreenSize;
|
|
34
|
+
private cachedOrientation;
|
|
33
35
|
interfaceType: InterfaceType;
|
|
34
36
|
uri: string | undefined;
|
|
35
37
|
options?: AndroidDeviceOpt;
|
|
@@ -127,6 +129,7 @@ declare type AndroidDeviceOpt = {
|
|
|
127
129
|
usePhysicalDisplayIdForDisplayLookup?: boolean;
|
|
128
130
|
customActions?: DeviceAction<any>[];
|
|
129
131
|
screenshotResizeScale?: number;
|
|
132
|
+
alwaysFetchScreenInfo?: boolean;
|
|
130
133
|
} & AndroidDeviceInputOpt;
|
|
131
134
|
|
|
132
135
|
export declare function getConnectedDevices(): Promise<Device[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/android",
|
|
3
|
-
"version": "0.30.3
|
|
3
|
+
"version": "0.30.3",
|
|
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/core": "0.30.3
|
|
31
|
-
"@midscene/shared": "0.30.3
|
|
30
|
+
"@midscene/core": "0.30.3",
|
|
31
|
+
"@midscene/shared": "0.30.3"
|
|
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.30.3
|
|
40
|
+
"@midscene/playground": "0.30.3"
|
|
41
41
|
},
|
|
42
42
|
"license": "MIT",
|
|
43
43
|
"scripts": {
|