@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 CHANGED
@@ -31493,13 +31493,14 @@ var AdbDeviceKit = class {
31493
31493
  client.removeListener("error", errorHandler);
31494
31494
  this.client = this.connect();
31495
31495
  this.device = this.client.getDevice(this.deviceId);
31496
+ client.off("error", errorHandler);
31496
31497
  };
31497
31498
  client.on("error", errorHandler);
31498
31499
  return client;
31499
31500
  }
31500
31501
  async listDevices() {
31501
- const devices = await this.client.listDevices().filter((device) => device.type === "device");
31502
- return devices;
31502
+ const allDevices = await this.client.listDevices();
31503
+ return allDevices.filter((device) => device.type === "device");
31503
31504
  }
31504
31505
  async getProperty(adbDevice, property) {
31505
31506
  try {
@@ -31558,6 +31559,38 @@ var AdbDeviceKit = class {
31558
31559
  matchesDeviceId(device) {
31559
31560
  return device.id === this.deviceId || device.id.endsWith(this.deviceId);
31560
31561
  }
31562
+ /**
31563
+ * Waits for USB debugging to be authorized (e.g. user enables and allows on device).
31564
+ * Returns a promise that resolves when the device is ready, or false on timeout.
31565
+ * Subscribe to events for progress (off, needs always allow, authorized).
31566
+ */
31567
+ waitForUsbDebugging(timeoutMs = 12e4, _numberOfAllowedAttempts) {
31568
+ const events = new UsbDebuggingEventEmitter();
31569
+ let cleanupRef = null;
31570
+ const promise = new Promise((resolve, reject) => {
31571
+ let settled = false;
31572
+ const done = (value) => {
31573
+ if (settled) return;
31574
+ settled = true;
31575
+ clearTimeout(timeout2);
31576
+ cleanupRef?.();
31577
+ cleanupRef = null;
31578
+ resolve(value);
31579
+ };
31580
+ const timeout2 = setTimeout(() => done(false), timeoutMs);
31581
+ events.once(USB_DEBUGGING_EVENT_AUTHORIZED, () => done(true));
31582
+ this.trackUsbDebuggingStatus(events).then((c) => {
31583
+ cleanupRef = c;
31584
+ }).catch((err) => {
31585
+ if (!settled) {
31586
+ settled = true;
31587
+ clearTimeout(timeout2);
31588
+ reject(err);
31589
+ }
31590
+ });
31591
+ });
31592
+ return { promise, events };
31593
+ }
31561
31594
  async trackUsbDebuggingStatus(eventEmitter) {
31562
31595
  const device = (await this.client.listDevices()).find(
31563
31596
  (device2) => device2.id === this.deviceId
@@ -31582,7 +31615,7 @@ var AdbDeviceKit = class {
31582
31615
  logError("Device removed from tracker");
31583
31616
  eventEmitter.emit(USB_DEBUGGING_EVENT_OFF, { deviceId: this.deviceId });
31584
31617
  });
31585
- tracker.on("change", (device2) => {
31618
+ const handleDeviceChange = (device2) => {
31586
31619
  if (!this.matchesDeviceId(device2)) return;
31587
31620
  if (device2.type === "unauthorized") {
31588
31621
  logDetail("Device needs 'Always allow' authorization");
@@ -31596,7 +31629,9 @@ var AdbDeviceKit = class {
31596
31629
  logDetail("Device removed from tracker");
31597
31630
  eventEmitter.emit(USB_DEBUGGING_EVENT_OFF, { deviceId: this.deviceId });
31598
31631
  }
31599
- });
31632
+ };
31633
+ tracker.on("add", handleDeviceChange);
31634
+ tracker.on("change", handleDeviceChange);
31600
31635
  return () => tracker.end();
31601
31636
  }
31602
31637
  async startPortForward(serviceName) {