@mcesystems/adb-kit 1.0.90 → 1.0.91
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 +23 -4
- package/dist/index.js +101 -75
- package/dist/index.js.map +4 -4
- package/dist/index.mjs +98 -75
- package/dist/index.mjs.map +4 -4
- package/dist/types/index.d.ts +13 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -61,7 +61,11 @@ await device.uninstallApp('com.example.app');
|
|
|
61
61
|
|
|
62
62
|
```typescript
|
|
63
63
|
const hasDebugging = await device.hasUsbDebugging();
|
|
64
|
-
|
|
64
|
+
const { promise, events } = device.waitForUsbDebugging(30000); // 30s timeout
|
|
65
|
+
events.on("usbDebuggingOff", () => console.log("Enable USB debugging on device"));
|
|
66
|
+
events.on("usbDebuggingNeedsAlwaysAllow", () => console.log("Tap Always allow on device"));
|
|
67
|
+
events.on("usbDebuggingAuthorized", () => console.log("Device ready"));
|
|
68
|
+
const ok = await promise;
|
|
65
69
|
```
|
|
66
70
|
|
|
67
71
|
**Port forwarding**
|
|
@@ -97,7 +101,18 @@ Interactive example that runs the same flow 5 times to verify `waitForUsbDebuggi
|
|
|
97
101
|
pnpm example:usb-debugging
|
|
98
102
|
```
|
|
99
103
|
|
|
100
|
-
See [examples/usb-debugging-robustness.ts](./examples/usb-debugging-robustness.ts) for the script.
|
|
104
|
+
See [src/examples/usb-debugging-robustness.ts](./src/examples/usb-debugging-robustness.ts) for the script.
|
|
105
|
+
|
|
106
|
+
**USB debugging playground**
|
|
107
|
+
|
|
108
|
+
Interactive playground to observe status events while you toggle USB debugging on/off or revoke authorizations. Prints events in real time as you change device settings.
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# From packages/adb-kit (set ADB_DEVICE_SERIAL if USB debugging is off)
|
|
112
|
+
pnpm example:usb-debugging-playground
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
See [src/examples/usb-debugging-playground.ts](./src/examples/usb-debugging-playground.ts) for the script.
|
|
101
116
|
|
|
102
117
|
For more scenarios and step-by-step explanations, see [Example.md](./Example.md).
|
|
103
118
|
|
|
@@ -148,7 +163,10 @@ For more scenarios and step-by-step explanations, see [Example.md](./Example.md)
|
|
|
148
163
|
**waitForUsbDebugging(timeout?, numberOfAllowedAttempts?)**
|
|
149
164
|
|
|
150
165
|
- **Input:** `timeout?: number` (default `120000` ms), `numberOfAllowedAttempts?: number` (default `5`, accepted for backward compatibility; give-up is determined by timeout and tracker end only)
|
|
151
|
-
- **Output:** `Promise<boolean
|
|
166
|
+
- **Output:** `{ promise: Promise<boolean>; events: EventEmitter }` — await `promise` for the result (`true` when device is ready, `false` when tracking ends without device; rejects on timeout, device removal, or connection error). Subscribe to `events` for state changes:
|
|
167
|
+
- `usbDebuggingOff` — waiting started (USB debugging not enabled on device)
|
|
168
|
+
- `usbDebuggingNeedsAlwaysAllow` — device visible but user must tap "Always allow" on device
|
|
169
|
+
- `usbDebuggingAuthorized` — device ready
|
|
152
170
|
|
|
153
171
|
**startPortForward(serviceName)**
|
|
154
172
|
|
|
@@ -191,7 +209,8 @@ const deviceId = 'ABC123'; // from your device discovery
|
|
|
191
209
|
const device = new AdbDeviceKit(deviceId, 1);
|
|
192
210
|
|
|
193
211
|
// 1. Wait for USB debugging (e.g. after user enables it)
|
|
194
|
-
|
|
212
|
+
const { promise } = device.waitForUsbDebugging(60000);
|
|
213
|
+
await promise;
|
|
195
214
|
|
|
196
215
|
// 2. Identify device
|
|
197
216
|
const [manufacturer, model] = await device.getDeviceProperties(['Manufacturer', 'Model']);
|
package/dist/index.js
CHANGED
|
@@ -25692,7 +25692,7 @@ var require_server = __commonJS({
|
|
|
25692
25692
|
var require_api = __commonJS({
|
|
25693
25693
|
"../../node_modules/.pnpm/@devicefarmer+adbkit-monkey@1.2.1/node_modules/@devicefarmer/adbkit-monkey/lib/monkey/api.js"(exports2, module2) {
|
|
25694
25694
|
(function() {
|
|
25695
|
-
var Api,
|
|
25695
|
+
var Api, EventEmitter2, _ref, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) {
|
|
25696
25696
|
for (var key in parent) {
|
|
25697
25697
|
if (__hasProp.call(parent, key)) child[key] = parent[key];
|
|
25698
25698
|
}
|
|
@@ -25704,7 +25704,7 @@ var require_api = __commonJS({
|
|
|
25704
25704
|
child.__super__ = parent.prototype;
|
|
25705
25705
|
return child;
|
|
25706
25706
|
};
|
|
25707
|
-
|
|
25707
|
+
EventEmitter2 = require("events").EventEmitter;
|
|
25708
25708
|
Api = (function(_super) {
|
|
25709
25709
|
__extends(Api2, _super);
|
|
25710
25710
|
function Api2() {
|
|
@@ -25918,7 +25918,7 @@ var require_api = __commonJS({
|
|
|
25918
25918
|
return this;
|
|
25919
25919
|
};
|
|
25920
25920
|
return Api2;
|
|
25921
|
-
})(
|
|
25921
|
+
})(EventEmitter2);
|
|
25922
25922
|
module2.exports = Api;
|
|
25923
25923
|
}).call(exports2);
|
|
25924
25924
|
}
|
|
@@ -26099,7 +26099,7 @@ var require_multi = __commonJS({
|
|
|
26099
26099
|
var require_parser2 = __commonJS({
|
|
26100
26100
|
"../../node_modules/.pnpm/@devicefarmer+adbkit-monkey@1.2.1/node_modules/@devicefarmer/adbkit-monkey/lib/monkey/parser.js"(exports2, module2) {
|
|
26101
26101
|
(function() {
|
|
26102
|
-
var
|
|
26102
|
+
var EventEmitter2, Parser, Reply, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) {
|
|
26103
26103
|
for (var key in parent) {
|
|
26104
26104
|
if (__hasProp.call(parent, key)) child[key] = parent[key];
|
|
26105
26105
|
}
|
|
@@ -26111,7 +26111,7 @@ var require_parser2 = __commonJS({
|
|
|
26111
26111
|
child.__super__ = parent.prototype;
|
|
26112
26112
|
return child;
|
|
26113
26113
|
};
|
|
26114
|
-
|
|
26114
|
+
EventEmitter2 = require("events").EventEmitter;
|
|
26115
26115
|
Reply = require_reply();
|
|
26116
26116
|
Parser = (function(_super) {
|
|
26117
26117
|
__extends(Parser2, _super);
|
|
@@ -26159,7 +26159,7 @@ var require_parser2 = __commonJS({
|
|
|
26159
26159
|
this.emit("error", new SyntaxError("Unparseable line '" + line + "'"));
|
|
26160
26160
|
};
|
|
26161
26161
|
return Parser2;
|
|
26162
|
-
})(
|
|
26162
|
+
})(EventEmitter2);
|
|
26163
26163
|
module2.exports = Parser;
|
|
26164
26164
|
}).call(exports2);
|
|
26165
26165
|
}
|
|
@@ -30214,11 +30214,15 @@ var require_dist = __commonJS({
|
|
|
30214
30214
|
var index_exports = {};
|
|
30215
30215
|
__export(index_exports, {
|
|
30216
30216
|
AdbDeviceKit: () => AdbDeviceKit,
|
|
30217
|
+
USB_DEBUGGING_EVENT_AUTHORIZED: () => USB_DEBUGGING_EVENT_AUTHORIZED,
|
|
30218
|
+
USB_DEBUGGING_EVENT_NEEDS_ALWAYS_ALLOW: () => USB_DEBUGGING_EVENT_NEEDS_ALWAYS_ALLOW,
|
|
30219
|
+
USB_DEBUGGING_EVENT_OFF: () => USB_DEBUGGING_EVENT_OFF,
|
|
30217
30220
|
readAll: () => readAll
|
|
30218
30221
|
});
|
|
30219
30222
|
module.exports = __toCommonJS(index_exports);
|
|
30220
30223
|
|
|
30221
30224
|
// src/logic/adbDeviceKit.ts
|
|
30225
|
+
var import_node_events = require("node:events");
|
|
30222
30226
|
var adbkit = __toESM(require_dist());
|
|
30223
30227
|
|
|
30224
30228
|
// ../tool-debug/dist/index.mjs
|
|
@@ -31353,6 +31357,11 @@ function portNumbers(from, to) {
|
|
|
31353
31357
|
return generator(from, to);
|
|
31354
31358
|
}
|
|
31355
31359
|
|
|
31360
|
+
// src/types/usbDebugging.ts
|
|
31361
|
+
var USB_DEBUGGING_EVENT_OFF = "usbDebuggingOff";
|
|
31362
|
+
var USB_DEBUGGING_EVENT_NEEDS_ALWAYS_ALLOW = "usbDebuggingNeedsAlwaysAllow";
|
|
31363
|
+
var USB_DEBUGGING_EVENT_AUTHORIZED = "usbDebuggingAuthorized";
|
|
31364
|
+
|
|
31356
31365
|
// src/utils/adbPath.ts
|
|
31357
31366
|
var import_node_fs = require("node:fs");
|
|
31358
31367
|
var import_node_path = __toESM(require("node:path"));
|
|
@@ -31534,78 +31543,92 @@ var AdbDeviceKit = class {
|
|
|
31534
31543
|
const adbBin = process.env.ADB_PATH ?? this.config?.binPath ?? "adb";
|
|
31535
31544
|
return adbkit.default.createClient({ bin: adbBin });
|
|
31536
31545
|
}
|
|
31537
|
-
|
|
31538
|
-
|
|
31539
|
-
|
|
31540
|
-
|
|
31541
|
-
|
|
31542
|
-
const
|
|
31543
|
-
|
|
31544
|
-
|
|
31545
|
-
|
|
31546
|
-
|
|
31547
|
-
|
|
31548
|
-
|
|
31549
|
-
|
|
31550
|
-
|
|
31551
|
-
|
|
31552
|
-
|
|
31553
|
-
|
|
31554
|
-
|
|
31555
|
-
|
|
31546
|
+
matchesDeviceId(device) {
|
|
31547
|
+
return device.id === this.deviceId || device.id.endsWith(this.deviceId);
|
|
31548
|
+
}
|
|
31549
|
+
waitForUsbDebugging(timeout2 = 12e4, _numberOfAllowedAttempts = 5) {
|
|
31550
|
+
const events = new import_node_events.EventEmitter();
|
|
31551
|
+
const promise = (async () => {
|
|
31552
|
+
if (await this.hasUsbDebugging()) {
|
|
31553
|
+
logDetail("USB debugging is already enabled");
|
|
31554
|
+
return true;
|
|
31555
|
+
}
|
|
31556
|
+
const trackingClient = this.createTrackingClient();
|
|
31557
|
+
const tracker = await trackingClient.trackDevices();
|
|
31558
|
+
events.emit(USB_DEBUGGING_EVENT_OFF);
|
|
31559
|
+
let settled = false;
|
|
31560
|
+
return new Promise((resolve, reject) => {
|
|
31561
|
+
const timeoutId = setTimeout(() => {
|
|
31562
|
+
logError("Timeout waiting for USB debugging");
|
|
31563
|
+
settle({ type: "reject", err: new Error("Timeout waiting for USB debugging") });
|
|
31564
|
+
}, timeout2);
|
|
31565
|
+
const cleanupTrackingClient = () => {
|
|
31566
|
+
try {
|
|
31567
|
+
tracker.end();
|
|
31568
|
+
} catch {
|
|
31569
|
+
}
|
|
31570
|
+
trackingClient.on("error", () => {
|
|
31571
|
+
});
|
|
31572
|
+
};
|
|
31573
|
+
const settle = (result) => {
|
|
31574
|
+
if (settled) return;
|
|
31575
|
+
settled = true;
|
|
31576
|
+
clearTimeout(timeoutId);
|
|
31577
|
+
cleanupTrackingClient();
|
|
31578
|
+
if (result.type === "resolve") {
|
|
31579
|
+
resolve(result.value);
|
|
31580
|
+
} else {
|
|
31581
|
+
logError(result.err.message);
|
|
31582
|
+
reject(result.err);
|
|
31583
|
+
}
|
|
31584
|
+
};
|
|
31585
|
+
const handleAddOrChange = (device) => {
|
|
31586
|
+
if (!this.matchesDeviceId(device)) return;
|
|
31587
|
+
if (device.type === "unauthorized") {
|
|
31588
|
+
logDetail("Device needs 'Always allow' authorization");
|
|
31589
|
+
events.emit(USB_DEBUGGING_EVENT_NEEDS_ALWAYS_ALLOW);
|
|
31590
|
+
return;
|
|
31591
|
+
}
|
|
31592
|
+
if (device.type === "device") {
|
|
31593
|
+
logDetail("Device authorized");
|
|
31594
|
+
events.emit(USB_DEBUGGING_EVENT_AUTHORIZED);
|
|
31595
|
+
settle({ type: "resolve", value: true });
|
|
31596
|
+
}
|
|
31597
|
+
};
|
|
31598
|
+
trackingClient.on("error", (err) => {
|
|
31599
|
+
if (isConnectionErrorMessage(err)) {
|
|
31600
|
+
logDetail(`Tracking client connection closed: ${err.message}`);
|
|
31601
|
+
settle({ type: "resolve", value: false });
|
|
31602
|
+
} else {
|
|
31603
|
+
logError(`Tracking client error: ${err.message}`);
|
|
31604
|
+
settle({ type: "reject", err });
|
|
31605
|
+
}
|
|
31556
31606
|
});
|
|
31557
|
-
|
|
31558
|
-
|
|
31559
|
-
|
|
31560
|
-
|
|
31561
|
-
|
|
31562
|
-
|
|
31563
|
-
|
|
31564
|
-
|
|
31565
|
-
}
|
|
31566
|
-
|
|
31567
|
-
|
|
31568
|
-
}
|
|
31569
|
-
};
|
|
31570
|
-
trackingClient.on("error", (err) => {
|
|
31571
|
-
if (isConnectionErrorMessage(err)) {
|
|
31572
|
-
logDetail(`Tracking client connection closed: ${err.message}`);
|
|
31573
|
-
settle({ type: "resolve", value: false });
|
|
31574
|
-
} else {
|
|
31575
|
-
logError(`Tracking client error: ${err.message}`);
|
|
31576
|
-
settle({ type: "reject", err });
|
|
31577
|
-
}
|
|
31578
|
-
});
|
|
31579
|
-
tracker.on("error", (err) => {
|
|
31580
|
-
if (isConnectionErrorMessage(err)) {
|
|
31581
|
-
logDetail(`Tracker connection closed: ${err.message}`);
|
|
31607
|
+
tracker.on("error", (err) => {
|
|
31608
|
+
if (isConnectionErrorMessage(err)) {
|
|
31609
|
+
logDetail(`Tracker connection closed: ${err.message}`);
|
|
31610
|
+
settle({ type: "resolve", value: false });
|
|
31611
|
+
} else {
|
|
31612
|
+
logError(`Tracker error: ${err.message}`);
|
|
31613
|
+
settle({ type: "reject", err });
|
|
31614
|
+
}
|
|
31615
|
+
});
|
|
31616
|
+
tracker.on("end", () => {
|
|
31617
|
+
logDetail("Device tracking ended");
|
|
31582
31618
|
settle({ type: "resolve", value: false });
|
|
31583
|
-
}
|
|
31584
|
-
|
|
31585
|
-
|
|
31586
|
-
|
|
31587
|
-
|
|
31588
|
-
|
|
31589
|
-
|
|
31590
|
-
|
|
31591
|
-
|
|
31592
|
-
|
|
31593
|
-
logError("Device removed from tracker");
|
|
31594
|
-
settle({ type: "reject", err: new Error("Device removed while waiting for USB debugging") });
|
|
31595
|
-
});
|
|
31596
|
-
tracker.on("add", (device) => {
|
|
31597
|
-
if (device.type === "device") {
|
|
31598
|
-
logDetail("Device added to tracker");
|
|
31599
|
-
settle({ type: "resolve", value: true });
|
|
31600
|
-
}
|
|
31601
|
-
});
|
|
31602
|
-
tracker.on("change", (device) => {
|
|
31603
|
-
if (device.type === "device") {
|
|
31604
|
-
logDetail("Device changed in tracker");
|
|
31605
|
-
settle({ type: "resolve", value: true });
|
|
31606
|
-
}
|
|
31619
|
+
});
|
|
31620
|
+
tracker.on("remove", (_) => {
|
|
31621
|
+
logError("Device removed from tracker");
|
|
31622
|
+
settle({
|
|
31623
|
+
type: "reject",
|
|
31624
|
+
err: new Error("Device removed while waiting for USB debugging")
|
|
31625
|
+
});
|
|
31626
|
+
});
|
|
31627
|
+
tracker.on("add", handleAddOrChange);
|
|
31628
|
+
tracker.on("change", handleAddOrChange);
|
|
31607
31629
|
});
|
|
31608
|
-
});
|
|
31630
|
+
})();
|
|
31631
|
+
return { promise, events };
|
|
31609
31632
|
}
|
|
31610
31633
|
async startPortForward(serviceName) {
|
|
31611
31634
|
if (this.devicePort) {
|
|
@@ -31635,6 +31658,9 @@ var readAll = import_adbkit.default.util.readAll;
|
|
|
31635
31658
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31636
31659
|
0 && (module.exports = {
|
|
31637
31660
|
AdbDeviceKit,
|
|
31661
|
+
USB_DEBUGGING_EVENT_AUTHORIZED,
|
|
31662
|
+
USB_DEBUGGING_EVENT_NEEDS_ALWAYS_ALLOW,
|
|
31663
|
+
USB_DEBUGGING_EVENT_OFF,
|
|
31638
31664
|
readAll
|
|
31639
31665
|
});
|
|
31640
31666
|
//# sourceMappingURL=index.js.map
|