@mcesystems/adb-kit 1.0.93 → 1.0.94
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 +53 -93
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +52 -93
- package/dist/index.mjs.map +3 -3
- package/dist/types/index.d.ts +26 -12
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -30216,7 +30216,6 @@ var require_dist = __commonJS({
|
|
|
30216
30216
|
|
|
30217
30217
|
// src/logic/adbDeviceKit.ts
|
|
30218
30218
|
var adbkit = __toESM(require_dist());
|
|
30219
|
-
import { EventEmitter } from "node:events";
|
|
30220
30219
|
|
|
30221
30220
|
// ../tool-debug/dist/index.mjs
|
|
30222
30221
|
import process22 from "node:process";
|
|
@@ -31351,9 +31350,21 @@ function portNumbers(from, to) {
|
|
|
31351
31350
|
}
|
|
31352
31351
|
|
|
31353
31352
|
// src/types/usbDebugging.ts
|
|
31353
|
+
import EventEmitter from "node:events";
|
|
31354
31354
|
var USB_DEBUGGING_EVENT_OFF = "usbDebuggingOff";
|
|
31355
31355
|
var USB_DEBUGGING_EVENT_NEEDS_ALWAYS_ALLOW = "usbDebuggingNeedsAlwaysAllow";
|
|
31356
31356
|
var USB_DEBUGGING_EVENT_AUTHORIZED = "usbDebuggingAuthorized";
|
|
31357
|
+
var UsbDebuggingEventEmitter = class extends EventEmitter {
|
|
31358
|
+
on(event, listener) {
|
|
31359
|
+
return super.on(event, listener);
|
|
31360
|
+
}
|
|
31361
|
+
emit(event, ...args) {
|
|
31362
|
+
return super.emit(event, ...args);
|
|
31363
|
+
}
|
|
31364
|
+
off(event, listener) {
|
|
31365
|
+
return super.off(event, listener);
|
|
31366
|
+
}
|
|
31367
|
+
};
|
|
31357
31368
|
|
|
31358
31369
|
// src/utils/adbPath.ts
|
|
31359
31370
|
import { existsSync } from "node:fs";
|
|
@@ -31539,99 +31550,46 @@ var AdbDeviceKit = class {
|
|
|
31539
31550
|
matchesDeviceId(device) {
|
|
31540
31551
|
return device.id === this.deviceId || device.id.endsWith(this.deviceId);
|
|
31541
31552
|
}
|
|
31542
|
-
|
|
31543
|
-
const
|
|
31544
|
-
|
|
31545
|
-
|
|
31546
|
-
|
|
31547
|
-
|
|
31548
|
-
logDetail(
|
|
31549
|
-
|
|
31550
|
-
|
|
31551
|
-
|
|
31553
|
+
async trackUsbDebuggingStatus(eventEmitter) {
|
|
31554
|
+
const device = (await this.client.listDevices()).find(
|
|
31555
|
+
(device2) => device2.id === this.deviceId
|
|
31556
|
+
);
|
|
31557
|
+
logDetail(`Device: ${device?.id} (${device?.type})`);
|
|
31558
|
+
if (device?.type === "device") {
|
|
31559
|
+
logDetail("USB debugging is already enabled");
|
|
31560
|
+
eventEmitter.emit(USB_DEBUGGING_EVENT_AUTHORIZED, { deviceId: this.deviceId });
|
|
31561
|
+
return () => {
|
|
31562
|
+
};
|
|
31563
|
+
}
|
|
31564
|
+
if (device?.type === "unauthorized") {
|
|
31565
|
+
logDetail("Device needs 'Always allow' authorization");
|
|
31566
|
+
eventEmitter.emit(USB_DEBUGGING_EVENT_NEEDS_ALWAYS_ALLOW, { deviceId: this.deviceId });
|
|
31567
|
+
} else {
|
|
31568
|
+
logDetail("Device is not authorized");
|
|
31569
|
+
eventEmitter.emit(USB_DEBUGGING_EVENT_OFF, { deviceId: this.deviceId });
|
|
31570
|
+
}
|
|
31571
|
+
const trackingClient = this.createTrackingClient();
|
|
31572
|
+
const tracker = await trackingClient.trackDevices();
|
|
31573
|
+
tracker.on("remove", (_) => {
|
|
31574
|
+
logError("Device removed from tracker");
|
|
31575
|
+
eventEmitter.emit(USB_DEBUGGING_EVENT_OFF, { deviceId: this.deviceId });
|
|
31576
|
+
});
|
|
31577
|
+
tracker.on("change", (device2) => {
|
|
31578
|
+
if (!this.matchesDeviceId(device2)) return;
|
|
31579
|
+
if (device2.type === "unauthorized") {
|
|
31580
|
+
logDetail("Device needs 'Always allow' authorization");
|
|
31581
|
+
eventEmitter.emit(USB_DEBUGGING_EVENT_NEEDS_ALWAYS_ALLOW, { deviceId: this.deviceId });
|
|
31552
31582
|
}
|
|
31553
|
-
|
|
31554
|
-
|
|
31555
|
-
|
|
31556
|
-
|
|
31557
|
-
|
|
31558
|
-
|
|
31559
|
-
|
|
31560
|
-
|
|
31561
|
-
|
|
31562
|
-
|
|
31563
|
-
return new Promise((resolve, reject) => {
|
|
31564
|
-
const timeoutId = setTimeout(() => {
|
|
31565
|
-
logError("Timeout waiting for USB debugging");
|
|
31566
|
-
settle({ type: "reject", err: new Error("Timeout waiting for USB debugging") });
|
|
31567
|
-
}, timeout2);
|
|
31568
|
-
const cleanupTrackingClient = () => {
|
|
31569
|
-
try {
|
|
31570
|
-
tracker.end();
|
|
31571
|
-
} catch {
|
|
31572
|
-
}
|
|
31573
|
-
trackingClient.on("error", () => {
|
|
31574
|
-
});
|
|
31575
|
-
};
|
|
31576
|
-
const settle = (result) => {
|
|
31577
|
-
if (settled) return;
|
|
31578
|
-
settled = true;
|
|
31579
|
-
clearTimeout(timeoutId);
|
|
31580
|
-
cleanupTrackingClient();
|
|
31581
|
-
if (result.type === "resolve") {
|
|
31582
|
-
resolve(result.value);
|
|
31583
|
-
} else {
|
|
31584
|
-
logError(result.err.message);
|
|
31585
|
-
reject(result.err);
|
|
31586
|
-
}
|
|
31587
|
-
};
|
|
31588
|
-
const handleAddOrChange = (device2) => {
|
|
31589
|
-
if (!this.matchesDeviceId(device2)) return;
|
|
31590
|
-
if (device2.type === "unauthorized") {
|
|
31591
|
-
logDetail("Device needs 'Always allow' authorization");
|
|
31592
|
-
events.emit(USB_DEBUGGING_EVENT_NEEDS_ALWAYS_ALLOW);
|
|
31593
|
-
return;
|
|
31594
|
-
}
|
|
31595
|
-
if (device2.type === "device") {
|
|
31596
|
-
logDetail("Device authorized");
|
|
31597
|
-
events.emit(USB_DEBUGGING_EVENT_AUTHORIZED);
|
|
31598
|
-
settle({ type: "resolve", value: true });
|
|
31599
|
-
}
|
|
31600
|
-
};
|
|
31601
|
-
trackingClient.on("error", (err) => {
|
|
31602
|
-
if (isConnectionErrorMessage(err)) {
|
|
31603
|
-
logDetail(`Tracking client connection closed: ${err.message}`);
|
|
31604
|
-
settle({ type: "resolve", value: false });
|
|
31605
|
-
} else {
|
|
31606
|
-
logError(`Tracking client error: ${err.message}`);
|
|
31607
|
-
settle({ type: "reject", err });
|
|
31608
|
-
}
|
|
31609
|
-
});
|
|
31610
|
-
tracker.on("error", (err) => {
|
|
31611
|
-
if (isConnectionErrorMessage(err)) {
|
|
31612
|
-
logDetail(`Tracker connection closed: ${err.message}`);
|
|
31613
|
-
settle({ type: "resolve", value: false });
|
|
31614
|
-
} else {
|
|
31615
|
-
logError(`Tracker error: ${err.message}`);
|
|
31616
|
-
settle({ type: "reject", err });
|
|
31617
|
-
}
|
|
31618
|
-
});
|
|
31619
|
-
tracker.on("end", () => {
|
|
31620
|
-
logDetail("Device tracking ended");
|
|
31621
|
-
settle({ type: "resolve", value: false });
|
|
31622
|
-
});
|
|
31623
|
-
tracker.on("remove", (_) => {
|
|
31624
|
-
logError("Device removed from tracker");
|
|
31625
|
-
settle({
|
|
31626
|
-
type: "reject",
|
|
31627
|
-
err: new Error("Device removed while waiting for USB debugging")
|
|
31628
|
-
});
|
|
31629
|
-
});
|
|
31630
|
-
tracker.on("add", handleAddOrChange);
|
|
31631
|
-
tracker.on("change", handleAddOrChange);
|
|
31632
|
-
});
|
|
31633
|
-
})();
|
|
31634
|
-
return { promise, events };
|
|
31583
|
+
if (device2.type === "device") {
|
|
31584
|
+
logDetail("Device authorized");
|
|
31585
|
+
eventEmitter.emit(USB_DEBUGGING_EVENT_AUTHORIZED, { deviceId: this.deviceId });
|
|
31586
|
+
}
|
|
31587
|
+
if (!device2.type) {
|
|
31588
|
+
logDetail("Device removed from tracker");
|
|
31589
|
+
eventEmitter.emit(USB_DEBUGGING_EVENT_OFF, { deviceId: this.deviceId });
|
|
31590
|
+
}
|
|
31591
|
+
});
|
|
31592
|
+
return () => tracker.end();
|
|
31635
31593
|
}
|
|
31636
31594
|
async startPortForward(serviceName) {
|
|
31637
31595
|
if (this.devicePort) {
|
|
@@ -31663,6 +31621,7 @@ export {
|
|
|
31663
31621
|
USB_DEBUGGING_EVENT_AUTHORIZED,
|
|
31664
31622
|
USB_DEBUGGING_EVENT_NEEDS_ALWAYS_ALLOW,
|
|
31665
31623
|
USB_DEBUGGING_EVENT_OFF,
|
|
31624
|
+
UsbDebuggingEventEmitter,
|
|
31666
31625
|
readAll
|
|
31667
31626
|
};
|
|
31668
31627
|
//# sourceMappingURL=index.mjs.map
|