@midscene/android 0.14.3 → 0.14.4-beta-20250415065130.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.d.ts +1 -0
- package/dist/es/index.js +48 -9
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +48 -9
- package/dist/types/index.d.ts +1 -0
- package/package.json +6 -5
- package/bin/yadb +0 -0
package/dist/es/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare class AndroidDevice implements AndroidDevicePage {
|
|
|
15
15
|
constructor(deviceId: string);
|
|
16
16
|
connect(): Promise<ADB>;
|
|
17
17
|
getAdb(): Promise<ADB>;
|
|
18
|
+
private createAdbProxy;
|
|
18
19
|
launch(uri: string): Promise<AndroidDevice>;
|
|
19
20
|
private execYadb;
|
|
20
21
|
getElementsInfo(): Promise<ElementInfo[]>;
|
package/dist/es/index.js
CHANGED
|
@@ -24,10 +24,10 @@ var AndroidDevice = class {
|
|
|
24
24
|
}
|
|
25
25
|
async getAdb() {
|
|
26
26
|
if (this.adb) {
|
|
27
|
-
return this.adb;
|
|
27
|
+
return this.createAdbProxy(this.adb);
|
|
28
28
|
}
|
|
29
29
|
if (this.connectingAdb) {
|
|
30
|
-
return this.connectingAdb;
|
|
30
|
+
return this.connectingAdb.then((adb) => this.createAdbProxy(adb));
|
|
31
31
|
}
|
|
32
32
|
this.connectingAdb = (async () => {
|
|
33
33
|
let error = null;
|
|
@@ -60,26 +60,56 @@ ${Object.keys(size).filter((key) => size[key]).map(
|
|
|
60
60
|
})();
|
|
61
61
|
return this.connectingAdb;
|
|
62
62
|
}
|
|
63
|
+
createAdbProxy(adb) {
|
|
64
|
+
return new Proxy(adb, {
|
|
65
|
+
get: (target, prop) => {
|
|
66
|
+
const originalMethod = target[prop];
|
|
67
|
+
if (typeof originalMethod !== "function") {
|
|
68
|
+
return originalMethod;
|
|
69
|
+
}
|
|
70
|
+
return async (...args) => {
|
|
71
|
+
try {
|
|
72
|
+
return await originalMethod.apply(target, args);
|
|
73
|
+
} catch (error) {
|
|
74
|
+
const methodName = String(prop);
|
|
75
|
+
const deviceId = this.deviceId;
|
|
76
|
+
debugPage(
|
|
77
|
+
`ADB error with device ${deviceId} when calling ${methodName}: ${error}`
|
|
78
|
+
);
|
|
79
|
+
throw new Error(
|
|
80
|
+
`ADB error with device ${deviceId} when calling ${methodName}, please check https://midscenejs.com/integrate-with-android.html#faq : ${error.message}`,
|
|
81
|
+
{
|
|
82
|
+
cause: error
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
63
90
|
async launch(uri) {
|
|
64
91
|
const adb = await this.getAdb();
|
|
65
92
|
try {
|
|
66
93
|
if (uri.startsWith("http://") || uri.startsWith("https://") || uri.includes("://")) {
|
|
67
94
|
await adb.startUri(uri);
|
|
68
|
-
} else
|
|
95
|
+
} else {
|
|
69
96
|
const [appPackage, appActivity] = uri.split("/");
|
|
97
|
+
if (!appPackage || !appActivity) {
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Invalid URI format: ${uri}, expected format: com.android/settings.Settings`
|
|
100
|
+
);
|
|
101
|
+
}
|
|
70
102
|
await adb.startApp({
|
|
71
103
|
pkg: appPackage,
|
|
72
104
|
activity: appActivity
|
|
73
105
|
});
|
|
74
|
-
} else {
|
|
75
|
-
await adb.startApp({
|
|
76
|
-
pkg: uri
|
|
77
|
-
});
|
|
78
106
|
}
|
|
79
107
|
debugPage(`Successfully launched: ${uri}`);
|
|
80
108
|
} catch (error) {
|
|
81
109
|
debugPage(`Error launching ${uri}: ${error}`);
|
|
82
|
-
throw new Error(`Failed to launch ${uri}: ${error}`, {
|
|
110
|
+
throw new Error(`Failed to launch ${uri}: ${error.message}`, {
|
|
111
|
+
cause: error
|
|
112
|
+
});
|
|
83
113
|
}
|
|
84
114
|
return this;
|
|
85
115
|
}
|
|
@@ -434,7 +464,12 @@ async function getConnectedDevices() {
|
|
|
434
464
|
return devices;
|
|
435
465
|
} catch (error) {
|
|
436
466
|
console.error("Failed to get device list:", error);
|
|
437
|
-
throw new Error(
|
|
467
|
+
throw new Error(
|
|
468
|
+
`Unable to get connected Android device list, please check https://midscenejs.com/integrate-with-android.html#faq : ${error.message}`,
|
|
469
|
+
{
|
|
470
|
+
cause: error
|
|
471
|
+
}
|
|
472
|
+
);
|
|
438
473
|
}
|
|
439
474
|
}
|
|
440
475
|
|
|
@@ -457,6 +492,10 @@ async function agentFromAdbDevice(deviceId, opts) {
|
|
|
457
492
|
if (!deviceId) {
|
|
458
493
|
const devices = await getConnectedDevices();
|
|
459
494
|
deviceId = devices[0].udid;
|
|
495
|
+
debugPage(
|
|
496
|
+
"deviceId not specified, will use the first device (id = %s)",
|
|
497
|
+
deviceId
|
|
498
|
+
);
|
|
460
499
|
}
|
|
461
500
|
const page = new AndroidDevice(deviceId);
|
|
462
501
|
await page.connect();
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare class AndroidDevice implements AndroidDevicePage {
|
|
|
15
15
|
constructor(deviceId: string);
|
|
16
16
|
connect(): Promise<ADB>;
|
|
17
17
|
getAdb(): Promise<ADB>;
|
|
18
|
+
private createAdbProxy;
|
|
18
19
|
launch(uri: string): Promise<AndroidDevice>;
|
|
19
20
|
private execYadb;
|
|
20
21
|
getElementsInfo(): Promise<ElementInfo[]>;
|
package/dist/lib/index.js
CHANGED
|
@@ -63,10 +63,10 @@ var AndroidDevice = class {
|
|
|
63
63
|
}
|
|
64
64
|
async getAdb() {
|
|
65
65
|
if (this.adb) {
|
|
66
|
-
return this.adb;
|
|
66
|
+
return this.createAdbProxy(this.adb);
|
|
67
67
|
}
|
|
68
68
|
if (this.connectingAdb) {
|
|
69
|
-
return this.connectingAdb;
|
|
69
|
+
return this.connectingAdb.then((adb) => this.createAdbProxy(adb));
|
|
70
70
|
}
|
|
71
71
|
this.connectingAdb = (async () => {
|
|
72
72
|
let error = null;
|
|
@@ -99,26 +99,56 @@ ${Object.keys(size).filter((key) => size[key]).map(
|
|
|
99
99
|
})();
|
|
100
100
|
return this.connectingAdb;
|
|
101
101
|
}
|
|
102
|
+
createAdbProxy(adb) {
|
|
103
|
+
return new Proxy(adb, {
|
|
104
|
+
get: (target, prop) => {
|
|
105
|
+
const originalMethod = target[prop];
|
|
106
|
+
if (typeof originalMethod !== "function") {
|
|
107
|
+
return originalMethod;
|
|
108
|
+
}
|
|
109
|
+
return async (...args) => {
|
|
110
|
+
try {
|
|
111
|
+
return await originalMethod.apply(target, args);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
const methodName = String(prop);
|
|
114
|
+
const deviceId = this.deviceId;
|
|
115
|
+
debugPage(
|
|
116
|
+
`ADB error with device ${deviceId} when calling ${methodName}: ${error}`
|
|
117
|
+
);
|
|
118
|
+
throw new Error(
|
|
119
|
+
`ADB error with device ${deviceId} when calling ${methodName}, please check https://midscenejs.com/integrate-with-android.html#faq : ${error.message}`,
|
|
120
|
+
{
|
|
121
|
+
cause: error
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
}
|
|
102
129
|
async launch(uri) {
|
|
103
130
|
const adb = await this.getAdb();
|
|
104
131
|
try {
|
|
105
132
|
if (uri.startsWith("http://") || uri.startsWith("https://") || uri.includes("://")) {
|
|
106
133
|
await adb.startUri(uri);
|
|
107
|
-
} else
|
|
134
|
+
} else {
|
|
108
135
|
const [appPackage, appActivity] = uri.split("/");
|
|
136
|
+
if (!appPackage || !appActivity) {
|
|
137
|
+
throw new Error(
|
|
138
|
+
`Invalid URI format: ${uri}, expected format: com.android/settings.Settings`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
109
141
|
await adb.startApp({
|
|
110
142
|
pkg: appPackage,
|
|
111
143
|
activity: appActivity
|
|
112
144
|
});
|
|
113
|
-
} else {
|
|
114
|
-
await adb.startApp({
|
|
115
|
-
pkg: uri
|
|
116
|
-
});
|
|
117
145
|
}
|
|
118
146
|
debugPage(`Successfully launched: ${uri}`);
|
|
119
147
|
} catch (error) {
|
|
120
148
|
debugPage(`Error launching ${uri}: ${error}`);
|
|
121
|
-
throw new Error(`Failed to launch ${uri}: ${error}`, {
|
|
149
|
+
throw new Error(`Failed to launch ${uri}: ${error.message}`, {
|
|
150
|
+
cause: error
|
|
151
|
+
});
|
|
122
152
|
}
|
|
123
153
|
return this;
|
|
124
154
|
}
|
|
@@ -473,7 +503,12 @@ async function getConnectedDevices() {
|
|
|
473
503
|
return devices;
|
|
474
504
|
} catch (error) {
|
|
475
505
|
console.error("Failed to get device list:", error);
|
|
476
|
-
throw new Error(
|
|
506
|
+
throw new Error(
|
|
507
|
+
`Unable to get connected Android device list, please check https://midscenejs.com/integrate-with-android.html#faq : ${error.message}`,
|
|
508
|
+
{
|
|
509
|
+
cause: error
|
|
510
|
+
}
|
|
511
|
+
);
|
|
477
512
|
}
|
|
478
513
|
}
|
|
479
514
|
|
|
@@ -496,6 +531,10 @@ async function agentFromAdbDevice(deviceId, opts) {
|
|
|
496
531
|
if (!deviceId) {
|
|
497
532
|
const devices = await getConnectedDevices();
|
|
498
533
|
deviceId = devices[0].udid;
|
|
534
|
+
debugPage(
|
|
535
|
+
"deviceId not specified, will use the first device (id = %s)",
|
|
536
|
+
deviceId
|
|
537
|
+
);
|
|
499
538
|
}
|
|
500
539
|
const page = new AndroidDevice(deviceId);
|
|
501
540
|
await page.connect();
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare class AndroidDevice implements AndroidDevicePage {
|
|
|
15
15
|
constructor(deviceId: string);
|
|
16
16
|
connect(): Promise<ADB>;
|
|
17
17
|
getAdb(): Promise<ADB>;
|
|
18
|
+
private createAdbProxy;
|
|
18
19
|
launch(uri: string): Promise<AndroidDevice>;
|
|
19
20
|
private execYadb;
|
|
20
21
|
getElementsInfo(): Promise<ElementInfo[]>;
|
package/package.json
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/android",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.4-beta-20250415065130.0",
|
|
4
4
|
"description": "Android automation library for Midscene",
|
|
5
5
|
"main": "./dist/lib/index.js",
|
|
6
6
|
"types": "./dist/types/index.d.ts",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist",
|
|
9
|
-
"bin",
|
|
10
9
|
"README.md"
|
|
11
10
|
],
|
|
12
11
|
"exports": {
|
|
@@ -17,9 +16,9 @@
|
|
|
17
16
|
},
|
|
18
17
|
"dependencies": {
|
|
19
18
|
"appium-adb": "12.12.1",
|
|
20
|
-
"@midscene/
|
|
21
|
-
"@midscene/
|
|
22
|
-
"@midscene/
|
|
19
|
+
"@midscene/shared": "0.14.4-beta-20250415065130.0",
|
|
20
|
+
"@midscene/web": "0.14.4-beta-20250415065130.0",
|
|
21
|
+
"@midscene/core": "0.14.4-beta-20250415065130.0"
|
|
23
22
|
},
|
|
24
23
|
"devDependencies": {
|
|
25
24
|
"@modern-js/module-tools": "2.60.6",
|
|
@@ -30,7 +29,9 @@
|
|
|
30
29
|
},
|
|
31
30
|
"license": "MIT",
|
|
32
31
|
"scripts": {
|
|
32
|
+
"dev": "modern dev",
|
|
33
33
|
"build": "modern build -c ./modern.config.ts",
|
|
34
|
+
"build:watch": "modern build -w -c ./modern.config.ts",
|
|
34
35
|
"test": "vitest --run",
|
|
35
36
|
"test:u": "vitest --run -u",
|
|
36
37
|
"test:ai": "MIDSCENE_CACHE=true npm run test"
|
package/bin/yadb
DELETED
|
Binary file
|