@mcesystems/adb-kit 1.0.96 → 1.0.97
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/index.js +39 -4
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +39 -4
- package/dist/index.mjs.map +3 -3
- package/dist/types/index.d.ts +9 -0
- package/package.json +3 -4
package/dist/index.mjs
CHANGED
|
@@ -31485,13 +31485,14 @@ var AdbDeviceKit = class {
|
|
|
31485
31485
|
client.removeListener("error", errorHandler);
|
|
31486
31486
|
this.client = this.connect();
|
|
31487
31487
|
this.device = this.client.getDevice(this.deviceId);
|
|
31488
|
+
client.off("error", errorHandler);
|
|
31488
31489
|
};
|
|
31489
31490
|
client.on("error", errorHandler);
|
|
31490
31491
|
return client;
|
|
31491
31492
|
}
|
|
31492
31493
|
async listDevices() {
|
|
31493
|
-
const
|
|
31494
|
-
return
|
|
31494
|
+
const allDevices = await this.client.listDevices();
|
|
31495
|
+
return allDevices.filter((device) => device.type === "device");
|
|
31495
31496
|
}
|
|
31496
31497
|
async getProperty(adbDevice, property) {
|
|
31497
31498
|
try {
|
|
@@ -31550,6 +31551,38 @@ var AdbDeviceKit = class {
|
|
|
31550
31551
|
matchesDeviceId(device) {
|
|
31551
31552
|
return device.id === this.deviceId || device.id.endsWith(this.deviceId);
|
|
31552
31553
|
}
|
|
31554
|
+
/**
|
|
31555
|
+
* Waits for USB debugging to be authorized (e.g. user enables and allows on device).
|
|
31556
|
+
* Returns a promise that resolves when the device is ready, or false on timeout.
|
|
31557
|
+
* Subscribe to events for progress (off, needs always allow, authorized).
|
|
31558
|
+
*/
|
|
31559
|
+
waitForUsbDebugging(timeoutMs = 12e4, _numberOfAllowedAttempts) {
|
|
31560
|
+
const events = new UsbDebuggingEventEmitter();
|
|
31561
|
+
let cleanupRef = null;
|
|
31562
|
+
const promise = new Promise((resolve, reject) => {
|
|
31563
|
+
let settled = false;
|
|
31564
|
+
const done = (value) => {
|
|
31565
|
+
if (settled) return;
|
|
31566
|
+
settled = true;
|
|
31567
|
+
clearTimeout(timeout2);
|
|
31568
|
+
cleanupRef?.();
|
|
31569
|
+
cleanupRef = null;
|
|
31570
|
+
resolve(value);
|
|
31571
|
+
};
|
|
31572
|
+
const timeout2 = setTimeout(() => done(false), timeoutMs);
|
|
31573
|
+
events.once(USB_DEBUGGING_EVENT_AUTHORIZED, () => done(true));
|
|
31574
|
+
this.trackUsbDebuggingStatus(events).then((c) => {
|
|
31575
|
+
cleanupRef = c;
|
|
31576
|
+
}).catch((err) => {
|
|
31577
|
+
if (!settled) {
|
|
31578
|
+
settled = true;
|
|
31579
|
+
clearTimeout(timeout2);
|
|
31580
|
+
reject(err);
|
|
31581
|
+
}
|
|
31582
|
+
});
|
|
31583
|
+
});
|
|
31584
|
+
return { promise, events };
|
|
31585
|
+
}
|
|
31553
31586
|
async trackUsbDebuggingStatus(eventEmitter) {
|
|
31554
31587
|
const device = (await this.client.listDevices()).find(
|
|
31555
31588
|
(device2) => device2.id === this.deviceId
|
|
@@ -31574,7 +31607,7 @@ var AdbDeviceKit = class {
|
|
|
31574
31607
|
logError("Device removed from tracker");
|
|
31575
31608
|
eventEmitter.emit(USB_DEBUGGING_EVENT_OFF, { deviceId: this.deviceId });
|
|
31576
31609
|
});
|
|
31577
|
-
|
|
31610
|
+
const handleDeviceChange = (device2) => {
|
|
31578
31611
|
if (!this.matchesDeviceId(device2)) return;
|
|
31579
31612
|
if (device2.type === "unauthorized") {
|
|
31580
31613
|
logDetail("Device needs 'Always allow' authorization");
|
|
@@ -31588,7 +31621,9 @@ var AdbDeviceKit = class {
|
|
|
31588
31621
|
logDetail("Device removed from tracker");
|
|
31589
31622
|
eventEmitter.emit(USB_DEBUGGING_EVENT_OFF, { deviceId: this.deviceId });
|
|
31590
31623
|
}
|
|
31591
|
-
}
|
|
31624
|
+
};
|
|
31625
|
+
tracker.on("add", handleDeviceChange);
|
|
31626
|
+
tracker.on("change", handleDeviceChange);
|
|
31592
31627
|
return () => tracker.end();
|
|
31593
31628
|
}
|
|
31594
31629
|
async startPortForward(serviceName) {
|