@mcesystems/adb-kit 1.0.70 → 1.0.72
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 +11 -0
- package/dist/index.js +170 -56
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +170 -56
- package/dist/index.mjs.map +3 -3
- package/dist/types/logic/adbDeviceKit.d.ts +1 -1
- package/dist/types/logic/adbDeviceKit.d.ts.map +1 -1
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -77,6 +77,17 @@ const client = await device.getClient();
|
|
|
77
77
|
const deviceClient = await device.getDeviceClient();
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
+
**First connected Android properties**
|
|
81
|
+
|
|
82
|
+
One-shot example that discovers the first connected Android device and prints a curated set of its properties (manufacturer, model, brand, Android version, etc.).
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# From packages/adb-kit
|
|
86
|
+
pnpm example:first-android-properties
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
See [src/examples/first-connected-android-properties.ts](./src/examples/first-connected-android-properties.ts) for the script.
|
|
90
|
+
|
|
80
91
|
**USB debugging robustness example**
|
|
81
92
|
|
|
82
93
|
Interactive example that runs the same flow 5 times to verify `waitForUsbDebugging` handling: start without USB debugging (device not found), short 5s timeout (user lets it pass), then wait up to 30s while the user enables USB debugging, show device recognized, then user disables USB debugging and repeats.
|
package/dist/index.js
CHANGED
|
@@ -31050,55 +31050,172 @@ var require_src2 = __commonJS2({
|
|
|
31050
31050
|
}
|
|
31051
31051
|
});
|
|
31052
31052
|
var import_debug = __toESM2(require_src2());
|
|
31053
|
-
|
|
31054
|
-
|
|
31055
|
-
|
|
31056
|
-
|
|
31057
|
-
|
|
31058
|
-
|
|
31059
|
-
|
|
31060
|
-
|
|
31061
|
-
|
|
31062
|
-
|
|
31063
|
-
|
|
31064
|
-
|
|
31065
|
-
|
|
31066
|
-
|
|
31067
|
-
|
|
31068
|
-
|
|
31069
|
-
|
|
31070
|
-
|
|
31071
|
-
|
|
31072
|
-
|
|
31073
|
-
|
|
31074
|
-
}
|
|
31075
|
-
|
|
31076
|
-
|
|
31077
|
-
|
|
31078
|
-
|
|
31079
|
-
|
|
31080
|
-
|
|
31081
|
-
|
|
31082
|
-
|
|
31083
|
-
|
|
31084
|
-
|
|
31085
|
-
|
|
31086
|
-
|
|
31087
|
-
|
|
31088
|
-
|
|
31089
|
-
|
|
31090
|
-
|
|
31091
|
-
|
|
31092
|
-
|
|
31093
|
-
|
|
31094
|
-
|
|
31095
|
-
|
|
31096
|
-
|
|
31097
|
-
|
|
31098
|
-
|
|
31099
|
-
|
|
31100
|
-
|
|
31053
|
+
function createLoggers(namespace, logLevel = process.env.LOG_LEVEL ?? "none") {
|
|
31054
|
+
const logInfo2 = (0, import_debug.default)(`${namespace}:info`);
|
|
31055
|
+
const logTask2 = (0, import_debug.default)(`${namespace}:task`);
|
|
31056
|
+
const logError2 = (0, import_debug.default)(`${namespace}:error`);
|
|
31057
|
+
const logDetail2 = (0, import_debug.default)(`${namespace}:detail`);
|
|
31058
|
+
const logDebug = (0, import_debug.default)(`${namespace}:debug`);
|
|
31059
|
+
const logWarning = (0, import_debug.default)(`${namespace}:warning`);
|
|
31060
|
+
const logColor = (0, import_debug.default)(`${namespace}:color`);
|
|
31061
|
+
logInfo2.color = "19";
|
|
31062
|
+
logTask2.color = "25";
|
|
31063
|
+
logError2.color = "1";
|
|
31064
|
+
logDetail2.color = "199";
|
|
31065
|
+
logWarning.color = "186";
|
|
31066
|
+
logDebug.color = "211";
|
|
31067
|
+
logColor.enabled = true;
|
|
31068
|
+
function setNamespace2(namespace2) {
|
|
31069
|
+
logInfo2.namespace = `${namespace2}:info`;
|
|
31070
|
+
logTask2.namespace = `${namespace2}:task`;
|
|
31071
|
+
logError2.namespace = `${namespace2}:error`;
|
|
31072
|
+
logDetail2.namespace = `${namespace2}:detail`;
|
|
31073
|
+
logWarning.namespace = `${namespace2}:warning`;
|
|
31074
|
+
logDebug.namespace = `${namespace2}:debug`;
|
|
31075
|
+
}
|
|
31076
|
+
function setLogLevel(level) {
|
|
31077
|
+
switch (level) {
|
|
31078
|
+
case "info":
|
|
31079
|
+
logInfo2.enabled = true;
|
|
31080
|
+
logTask2.enabled = true;
|
|
31081
|
+
logError2.enabled = true;
|
|
31082
|
+
logWarning.enabled = true;
|
|
31083
|
+
logDetail2.enabled = false;
|
|
31084
|
+
logDebug.enabled = false;
|
|
31085
|
+
break;
|
|
31086
|
+
case "debug":
|
|
31087
|
+
logInfo2.enabled = true;
|
|
31088
|
+
logTask2.enabled = true;
|
|
31089
|
+
logError2.enabled = true;
|
|
31090
|
+
logWarning.enabled = true;
|
|
31091
|
+
logDetail2.enabled = true;
|
|
31092
|
+
logDebug.enabled = true;
|
|
31093
|
+
break;
|
|
31094
|
+
case "none":
|
|
31095
|
+
logInfo2.enabled = false;
|
|
31096
|
+
logTask2.enabled = false;
|
|
31097
|
+
logError2.enabled = false;
|
|
31098
|
+
logWarning.enabled = false;
|
|
31099
|
+
logDetail2.enabled = false;
|
|
31100
|
+
logDebug.enabled = false;
|
|
31101
|
+
break;
|
|
31102
|
+
}
|
|
31103
|
+
}
|
|
31104
|
+
setLogLevel(logLevel);
|
|
31105
|
+
function setColors(type, color) {
|
|
31106
|
+
switch (type) {
|
|
31107
|
+
case "info":
|
|
31108
|
+
logInfo2.color = color;
|
|
31109
|
+
break;
|
|
31110
|
+
case "task":
|
|
31111
|
+
logTask2.color = color;
|
|
31112
|
+
break;
|
|
31113
|
+
case "error":
|
|
31114
|
+
logError2.color = color;
|
|
31115
|
+
break;
|
|
31116
|
+
case "detail":
|
|
31117
|
+
logDetail2.color = color;
|
|
31118
|
+
break;
|
|
31119
|
+
case "warning":
|
|
31120
|
+
logWarning.color = color;
|
|
31121
|
+
break;
|
|
31122
|
+
case "debug":
|
|
31123
|
+
logDebug.color = color;
|
|
31124
|
+
break;
|
|
31125
|
+
default:
|
|
31126
|
+
throw new Error(`Invalid log type: ${type}`);
|
|
31127
|
+
}
|
|
31128
|
+
}
|
|
31129
|
+
function printColors() {
|
|
31130
|
+
for (let i = 0; i < 256; i++) {
|
|
31131
|
+
logColor.color = `${i}`;
|
|
31132
|
+
logColor(`${i}: ${i}`);
|
|
31133
|
+
}
|
|
31134
|
+
}
|
|
31135
|
+
function logDataDetail(data, prefix = "# ") {
|
|
31136
|
+
if (data === null || data === void 0) {
|
|
31137
|
+
return `${prefix}<null or undefined>`;
|
|
31138
|
+
}
|
|
31139
|
+
if (typeof data !== "object") {
|
|
31140
|
+
return `${prefix}${String(data)}`;
|
|
31141
|
+
}
|
|
31142
|
+
const keys = Object.keys(data);
|
|
31143
|
+
let result = "";
|
|
31144
|
+
for (const key of keys) {
|
|
31145
|
+
result += `${prefix}${key}: `;
|
|
31146
|
+
if (key in data) {
|
|
31147
|
+
let dataKey = key;
|
|
31148
|
+
if (key in data) {
|
|
31149
|
+
dataKey = key;
|
|
31150
|
+
const value = data[dataKey];
|
|
31151
|
+
if (value === null || value === void 0) {
|
|
31152
|
+
result += `<${value === null ? "null" : "undefined"}>
|
|
31153
|
+
`;
|
|
31154
|
+
} else if (typeof value === "object") {
|
|
31155
|
+
result += `
|
|
31156
|
+
${logDataDetail(value, `${prefix} `)}
|
|
31157
|
+
`;
|
|
31158
|
+
} else {
|
|
31159
|
+
result += `${value}
|
|
31160
|
+
`;
|
|
31161
|
+
}
|
|
31162
|
+
}
|
|
31163
|
+
}
|
|
31164
|
+
}
|
|
31165
|
+
return result.trim();
|
|
31166
|
+
}
|
|
31167
|
+
function header(title, padding = 0) {
|
|
31168
|
+
return `${" ".repeat(padding)}${"=".repeat(80)}
|
|
31169
|
+
${" ".repeat(40 - title.length / 2)}${title}
|
|
31170
|
+
${" ".repeat(padding)}${"=".repeat(80)}`;
|
|
31171
|
+
}
|
|
31172
|
+
function logHeader(title) {
|
|
31173
|
+
logInfo2(`${header(title, 2)}`);
|
|
31101
31174
|
}
|
|
31175
|
+
function logDataObject(title, ...args) {
|
|
31176
|
+
const stack = new Error().stack?.split("\n")[2] || "";
|
|
31177
|
+
const stackMatch = stack.match(/\((.*):(\d+):(\d+)\)$/) || stack.match(/at (.*):(\d+):(\d+)$/);
|
|
31178
|
+
let callerDetails = "";
|
|
31179
|
+
if (stackMatch) {
|
|
31180
|
+
const functionMatch = stack.match(/at (.+) \(/);
|
|
31181
|
+
const functionName = functionMatch ? functionMatch[1] : "<anonymous>";
|
|
31182
|
+
callerDetails = `${functionName}`;
|
|
31183
|
+
}
|
|
31184
|
+
logDetail2(`${header(`*${title}* ${callerDetails}`)}
|
|
31185
|
+
${args.reduce((acc, arg) => `${acc}
|
|
31186
|
+
${logDataDetail(arg)}`, "")}
|
|
31187
|
+
|
|
31188
|
+
${"=".repeat(80)}`);
|
|
31189
|
+
}
|
|
31190
|
+
function logErrorObject(error, extraDetails) {
|
|
31191
|
+
if (error instanceof Error) {
|
|
31192
|
+
logError2(`${extraDetails ? header(extraDetails, 1) : header(error.message, 1)}
|
|
31193
|
+
Error Message:
|
|
31194
|
+
${error.message}
|
|
31195
|
+
Error Stack:
|
|
31196
|
+
${error.stack}
|
|
31197
|
+
${"=".repeat(80)}`);
|
|
31198
|
+
} else {
|
|
31199
|
+
logError2(`${extraDetails ? header(extraDetails, 1) : header(String(error), 1)}
|
|
31200
|
+
${"=".repeat(80)}`);
|
|
31201
|
+
}
|
|
31202
|
+
}
|
|
31203
|
+
return {
|
|
31204
|
+
logInfo: logInfo2,
|
|
31205
|
+
logTask: logTask2,
|
|
31206
|
+
logError: logError2,
|
|
31207
|
+
logDetail: logDetail2,
|
|
31208
|
+
logDebug,
|
|
31209
|
+
logWarning,
|
|
31210
|
+
logColor,
|
|
31211
|
+
setColors,
|
|
31212
|
+
printColors,
|
|
31213
|
+
logHeader,
|
|
31214
|
+
logDataObject,
|
|
31215
|
+
logErrorObject,
|
|
31216
|
+
setLogLevel,
|
|
31217
|
+
setNamespace: setNamespace2
|
|
31218
|
+
};
|
|
31102
31219
|
}
|
|
31103
31220
|
|
|
31104
31221
|
// ../../node_modules/.pnpm/get-port@7.1.0/node_modules/get-port/index.js
|
|
@@ -31278,6 +31395,7 @@ function getAdbBinaryPath() {
|
|
|
31278
31395
|
}
|
|
31279
31396
|
|
|
31280
31397
|
// src/logic/adbDeviceKit.ts
|
|
31398
|
+
var { logInfo, logError, logTask, logDetail, setNamespace } = createLoggers("adb-kit");
|
|
31281
31399
|
function ensureAdbPathFromResources() {
|
|
31282
31400
|
const adbPath = getAdbBinaryPath();
|
|
31283
31401
|
if (adbPath && !process.env.ADB_PATH) {
|
|
@@ -31333,8 +31451,7 @@ var deviceProps = {
|
|
|
31333
31451
|
var AdbDeviceKit = class {
|
|
31334
31452
|
constructor(deviceId, port) {
|
|
31335
31453
|
this.port = port;
|
|
31336
|
-
|
|
31337
|
-
logNamespace(`adb:${deviceId}`);
|
|
31454
|
+
setNamespace(`adb-kit:${deviceId}`);
|
|
31338
31455
|
ensureAdbPathFromResources();
|
|
31339
31456
|
installConnectionErrorHandler();
|
|
31340
31457
|
this.client = this.connect();
|
|
@@ -31366,12 +31483,9 @@ var AdbDeviceKit = class {
|
|
|
31366
31483
|
try {
|
|
31367
31484
|
logTask(`Getting property ${property} for device ${this.deviceId}`);
|
|
31368
31485
|
const stream = await adbDevice.shell(`getprop ${deviceProps[property]}`);
|
|
31369
|
-
logTask(`
|
|
31370
|
-
const
|
|
31371
|
-
|
|
31372
|
-
chunks.push(chunk);
|
|
31373
|
-
}
|
|
31374
|
-
return Buffer.concat(chunks).toString().trim();
|
|
31486
|
+
logTask(`Reading getprop output for ${property}`);
|
|
31487
|
+
const buffer = await adbkit.default.util.readAll(stream);
|
|
31488
|
+
return buffer.toString().trim();
|
|
31375
31489
|
} catch (error) {
|
|
31376
31490
|
logError(`Error getting property ${property} for device ${this.deviceId}: ${error}`);
|
|
31377
31491
|
return "";
|