@lynx-js/devtool-connector 0.18.8 → 0.19.0
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/CHANGELOG.md +18 -0
- package/dist/2.js +4 -4
- package/dist/a.js +66 -56
- package/dist/client-id.d.ts +6 -5
- package/dist/command/contract.d.ts +2 -2
- package/dist/command/index.js +3 -10
- package/dist/command/open.d.ts +1 -1
- package/dist/command/reactlynx/protocol.d.ts +1 -1
- package/dist/command/timeout.d.ts +0 -2
- package/dist/daemon/entry.js +1 -1
- package/dist/daemon/protocol.d.ts +1 -0
- package/dist/daemon/server.d.ts +1 -1
- package/dist/f.js +57 -49
- package/dist/f1.js +55 -21
- package/dist/h.js +260 -542
- package/dist/hb.js +1 -4
- package/dist/index.d.ts +3 -25
- package/dist/index.js +1 -1
- package/dist/t.js +53 -24
- package/dist/transport/android.d.ts +2 -1
- package/dist/transport/daemon.d.ts +7 -3
- package/dist/transport/desktop.d.ts +1 -0
- package/dist/transport/hdt.d.ts +1 -0
- package/dist/transport/index.js +2 -2
- package/dist/transport/ios.d.ts +1 -0
- package/dist/transport/transport.d.ts +5 -0
- package/dist/types.d.ts +1 -24
- package/package.json +6 -6
- package/public/inspector-wrapper.html +1 -1
package/dist/h.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { AdbServerClient, escapeArg } from "@yume-chan/adb";
|
|
2
2
|
import node_net, { Server, Socket } from "node:net";
|
|
3
3
|
import node_os, { platform } from "node:os";
|
|
4
|
+
import { Duplex, Readable, Writable } from "node:stream";
|
|
4
5
|
import { TransformStream as web_TransformStream, WritableStream as web_WritableStream } from "node:stream/web";
|
|
5
6
|
import promises from "node:fs/promises";
|
|
6
7
|
import node_path from "node:path";
|
|
7
|
-
import { Duplex } from "node:stream";
|
|
8
8
|
import { on, once } from "node:events";
|
|
9
9
|
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
10
10
|
import { ansi_createDebug } from "./2.js";
|
|
11
|
+
import { requireNumericPort } from "./f1.js";
|
|
11
12
|
import * as __rspack_external_node_net_5ed819e1 from "node:net";
|
|
12
13
|
__webpack_require__.add({
|
|
13
14
|
"../../../node_modules/.pnpm/@xmldom+xmldom@0.9.10/node_modules/@xmldom/xmldom/lib/conventions.js" (__unused_rspack_module, exports) {
|
|
@@ -7889,17 +7890,9 @@ class PromiseResolver {
|
|
|
7889
7890
|
this.#state = 'rejected';
|
|
7890
7891
|
};
|
|
7891
7892
|
}
|
|
7892
|
-
function
|
|
7893
|
-
|
|
7894
|
-
|
|
7895
|
-
function tryClose(value) {
|
|
7896
|
-
try {
|
|
7897
|
-
const result = value.close();
|
|
7898
|
-
if (isPromiseLike(result)) return result.then(()=>true, ()=>false);
|
|
7899
|
-
return true;
|
|
7900
|
-
} catch {
|
|
7901
|
-
return false;
|
|
7902
|
-
}
|
|
7893
|
+
function noop() {}
|
|
7894
|
+
function suppressUnhandledRejection(promise) {
|
|
7895
|
+
promise.catch(noop);
|
|
7903
7896
|
}
|
|
7904
7897
|
async function tryCancel(stream) {
|
|
7905
7898
|
try {
|
|
@@ -7915,17 +7908,31 @@ function utils_getGlobalValue(key) {
|
|
|
7915
7908
|
const streams_ReadableStream = /* #__PURE__ */ (()=>{
|
|
7916
7909
|
const ReadableStream = utils_getGlobalValue("ReadableStream");
|
|
7917
7910
|
ReadableStream.from ??= function(iterable) {
|
|
7918
|
-
|
|
7919
|
-
|
|
7920
|
-
|
|
7921
|
-
|
|
7922
|
-
|
|
7923
|
-
|
|
7924
|
-
|
|
7925
|
-
|
|
7926
|
-
|
|
7927
|
-
|
|
7928
|
-
|
|
7911
|
+
if (Symbol.asyncIterator in iterable) {
|
|
7912
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
7913
|
+
return new ReadableStream({
|
|
7914
|
+
async pull (controller) {
|
|
7915
|
+
const result = await iterator.next();
|
|
7916
|
+
if (result.done) return void controller.close();
|
|
7917
|
+
controller.enqueue(result.value);
|
|
7918
|
+
},
|
|
7919
|
+
async cancel (reason) {
|
|
7920
|
+
await iterator.return?.(reason);
|
|
7921
|
+
}
|
|
7922
|
+
});
|
|
7923
|
+
} else {
|
|
7924
|
+
const iterator = iterable[Symbol.iterator]();
|
|
7925
|
+
return new ReadableStream({
|
|
7926
|
+
pull (controller) {
|
|
7927
|
+
const result = iterator.next();
|
|
7928
|
+
if (result.done) return void controller.close();
|
|
7929
|
+
controller.enqueue(result.value);
|
|
7930
|
+
},
|
|
7931
|
+
cancel (reason) {
|
|
7932
|
+
iterator.return?.(reason);
|
|
7933
|
+
}
|
|
7934
|
+
});
|
|
7935
|
+
}
|
|
7929
7936
|
};
|
|
7930
7937
|
ReadableStream.prototype.values ??= async function*(options) {
|
|
7931
7938
|
const reader = this.getReader();
|
|
@@ -7944,206 +7951,13 @@ const streams_ReadableStream = /* #__PURE__ */ (()=>{
|
|
|
7944
7951
|
return ReadableStream;
|
|
7945
7952
|
})();
|
|
7946
7953
|
const WritableStream = utils_getGlobalValue("WritableStream");
|
|
7947
|
-
|
|
7948
|
-
|
|
7949
|
-
#ready;
|
|
7950
|
-
#disposed = false;
|
|
7951
|
-
enqueue(task, bail = false) {
|
|
7952
|
-
if (this.#disposed) throw new Error("TaskQueue is disposed");
|
|
7953
|
-
if (!this.#ready) try {
|
|
7954
|
-
const result = task();
|
|
7955
|
-
if (isPromiseLike(result)) this.#ready = result.then(()=>{}, (e)=>{
|
|
7956
|
-
if (bail) throw e;
|
|
7957
|
-
});
|
|
7958
|
-
return result;
|
|
7959
|
-
} catch (e) {
|
|
7960
|
-
if (bail) {
|
|
7961
|
-
const promise = Promise.reject(e);
|
|
7962
|
-
promise.catch(()=>{});
|
|
7963
|
-
this.#ready = promise;
|
|
7964
|
-
}
|
|
7965
|
-
throw e;
|
|
7966
|
-
}
|
|
7967
|
-
const result = this.#ready.then(()=>{
|
|
7968
|
-
if (this.#disposed) throw new Error("TaskQueue is disposed");
|
|
7969
|
-
return task();
|
|
7970
|
-
});
|
|
7971
|
-
this.#ready = result.then(()=>{}, (e)=>{
|
|
7972
|
-
if (bail || this.#disposed) throw e;
|
|
7973
|
-
});
|
|
7974
|
-
return result;
|
|
7975
|
-
}
|
|
7976
|
-
dispose() {
|
|
7977
|
-
this.#disposed = true;
|
|
7978
|
-
}
|
|
7979
|
-
}
|
|
7980
|
-
class PushReadableStream extends streams_ReadableStream {
|
|
7981
|
-
constructor(source, strategy, logger){
|
|
7982
|
-
let controller;
|
|
7983
|
-
const tasks = new TaskQueue();
|
|
7984
|
-
let zeroHighWaterMarkAllowEnqueue = false;
|
|
7985
|
-
let waterMarkLow;
|
|
7986
|
-
const abortController = new abort_signal_AbortController();
|
|
7987
|
-
let stopped = false;
|
|
7988
|
-
const enqueue = (chunk)=>{
|
|
7989
|
-
logger?.({
|
|
7990
|
-
source: "producer",
|
|
7991
|
-
operation: "enqueue",
|
|
7992
|
-
value: chunk,
|
|
7993
|
-
phase: "start"
|
|
7994
|
-
});
|
|
7995
|
-
if (abortController.signal.aborted) {
|
|
7996
|
-
logger?.({
|
|
7997
|
-
source: "producer",
|
|
7998
|
-
operation: "enqueue",
|
|
7999
|
-
value: chunk,
|
|
8000
|
-
phase: "ignored"
|
|
8001
|
-
});
|
|
8002
|
-
return false;
|
|
8003
|
-
}
|
|
8004
|
-
if (null === controller.desiredSize) {
|
|
8005
|
-
controller.enqueue(chunk);
|
|
8006
|
-
throw new Error("unreachable");
|
|
8007
|
-
}
|
|
8008
|
-
if (zeroHighWaterMarkAllowEnqueue) {
|
|
8009
|
-
zeroHighWaterMarkAllowEnqueue = false;
|
|
8010
|
-
controller.enqueue(chunk);
|
|
8011
|
-
logger?.({
|
|
8012
|
-
source: "producer",
|
|
8013
|
-
operation: "enqueue",
|
|
8014
|
-
value: chunk,
|
|
8015
|
-
phase: "complete"
|
|
8016
|
-
});
|
|
8017
|
-
return true;
|
|
8018
|
-
}
|
|
8019
|
-
if (controller.desiredSize <= 0) {
|
|
8020
|
-
logger?.({
|
|
8021
|
-
source: "producer",
|
|
8022
|
-
operation: "enqueue",
|
|
8023
|
-
value: chunk,
|
|
8024
|
-
phase: "waiting"
|
|
8025
|
-
});
|
|
8026
|
-
waterMarkLow = new PromiseResolver();
|
|
8027
|
-
return waterMarkLow.promise.then(()=>{
|
|
8028
|
-
controller.enqueue(chunk);
|
|
8029
|
-
logger?.({
|
|
8030
|
-
source: "producer",
|
|
8031
|
-
operation: "enqueue",
|
|
8032
|
-
value: chunk,
|
|
8033
|
-
phase: "complete"
|
|
8034
|
-
});
|
|
8035
|
-
return true;
|
|
8036
|
-
}, ()=>{
|
|
8037
|
-
logger?.({
|
|
8038
|
-
source: "producer",
|
|
8039
|
-
operation: "enqueue",
|
|
8040
|
-
value: chunk,
|
|
8041
|
-
phase: "ignored"
|
|
8042
|
-
});
|
|
8043
|
-
return false;
|
|
8044
|
-
});
|
|
8045
|
-
}
|
|
8046
|
-
controller.enqueue(chunk);
|
|
8047
|
-
logger?.({
|
|
8048
|
-
source: "producer",
|
|
8049
|
-
operation: "enqueue",
|
|
8050
|
-
value: chunk,
|
|
8051
|
-
phase: "complete"
|
|
8052
|
-
});
|
|
8053
|
-
return true;
|
|
8054
|
-
};
|
|
8055
|
-
const close = (explicit)=>{
|
|
8056
|
-
logger?.({
|
|
8057
|
-
source: "producer",
|
|
8058
|
-
operation: "close",
|
|
8059
|
-
explicit,
|
|
8060
|
-
phase: "start"
|
|
8061
|
-
});
|
|
8062
|
-
if (abortController.signal.aborted || stopped && !explicit) return void logger?.({
|
|
8063
|
-
source: "producer",
|
|
8064
|
-
operation: "close",
|
|
8065
|
-
explicit,
|
|
8066
|
-
phase: "ignored"
|
|
8067
|
-
});
|
|
8068
|
-
controller.close();
|
|
8069
|
-
stopped = true;
|
|
8070
|
-
waterMarkLow?.reject();
|
|
8071
|
-
logger?.({
|
|
8072
|
-
source: "producer",
|
|
8073
|
-
operation: "close",
|
|
8074
|
-
explicit,
|
|
8075
|
-
phase: "complete"
|
|
8076
|
-
});
|
|
8077
|
-
};
|
|
8078
|
-
const error = (error, explicit)=>{
|
|
8079
|
-
logger?.({
|
|
8080
|
-
source: "producer",
|
|
8081
|
-
operation: "error",
|
|
8082
|
-
explicit,
|
|
8083
|
-
phase: "start"
|
|
8084
|
-
});
|
|
8085
|
-
stopped = true;
|
|
8086
|
-
controller.error(error);
|
|
8087
|
-
waterMarkLow?.reject();
|
|
8088
|
-
logger?.({
|
|
8089
|
-
source: "producer",
|
|
8090
|
-
operation: "error",
|
|
8091
|
-
explicit,
|
|
8092
|
-
phase: "complete"
|
|
8093
|
-
});
|
|
8094
|
-
};
|
|
8095
|
-
super({
|
|
8096
|
-
start: (controller_)=>{
|
|
8097
|
-
controller = controller_;
|
|
8098
|
-
const result = source({
|
|
8099
|
-
abortSignal: abortController.signal,
|
|
8100
|
-
enqueue: async (chunk)=>await tasks.enqueue(()=>enqueue(chunk)),
|
|
8101
|
-
close () {
|
|
8102
|
-
close(true);
|
|
8103
|
-
},
|
|
8104
|
-
error (e) {
|
|
8105
|
-
error(e, true);
|
|
8106
|
-
}
|
|
8107
|
-
});
|
|
8108
|
-
if (!stopped && isPromiseLike(result)) result.then(()=>close(false), (e)=>error(e, false));
|
|
8109
|
-
},
|
|
8110
|
-
pull: ()=>{
|
|
8111
|
-
logger?.({
|
|
8112
|
-
source: "consumer",
|
|
8113
|
-
operation: "pull",
|
|
8114
|
-
phase: "start"
|
|
8115
|
-
});
|
|
8116
|
-
if (waterMarkLow) {
|
|
8117
|
-
waterMarkLow.resolve(void 0);
|
|
8118
|
-
waterMarkLow = void 0;
|
|
8119
|
-
} else if (strategy?.highWaterMark === 0) zeroHighWaterMarkAllowEnqueue = true;
|
|
8120
|
-
logger?.({
|
|
8121
|
-
source: "consumer",
|
|
8122
|
-
operation: "pull",
|
|
8123
|
-
phase: "complete"
|
|
8124
|
-
});
|
|
8125
|
-
},
|
|
8126
|
-
cancel: (reason)=>{
|
|
8127
|
-
logger?.({
|
|
8128
|
-
source: "consumer",
|
|
8129
|
-
operation: "cancel",
|
|
8130
|
-
phase: "start"
|
|
8131
|
-
});
|
|
8132
|
-
stopped = true;
|
|
8133
|
-
abortController.abort(reason);
|
|
8134
|
-
waterMarkLow?.reject();
|
|
8135
|
-
logger?.({
|
|
8136
|
-
source: "consumer",
|
|
8137
|
-
operation: "cancel",
|
|
8138
|
-
phase: "complete"
|
|
8139
|
-
});
|
|
8140
|
-
}
|
|
8141
|
-
}, strategy);
|
|
8142
|
-
}
|
|
7954
|
+
function maybe_promise_isPromiseLike(value) {
|
|
7955
|
+
return "object" == typeof value && null !== value && "then" in value;
|
|
8143
7956
|
}
|
|
8144
7957
|
class ConsumableWritableStream extends WritableStream {
|
|
8145
7958
|
static async write(writer, value) {
|
|
8146
7959
|
const consumable = new consumable_Consumable(value);
|
|
7960
|
+
suppressUnhandledRejection(consumable.consumed);
|
|
8147
7961
|
await writer.write(consumable);
|
|
8148
7962
|
await consumable.consumed;
|
|
8149
7963
|
}
|
|
@@ -8253,7 +8067,7 @@ class ConsumableWrapByteReadableStream extends streams_ReadableStream {
|
|
|
8253
8067
|
});
|
|
8254
8068
|
}
|
|
8255
8069
|
}
|
|
8256
|
-
const { console
|
|
8070
|
+
const { console } = globalThis;
|
|
8257
8071
|
const createTask = /* #__PURE__ */ (()=>console?.createTask?.bind(console) ?? (()=>({
|
|
8258
8072
|
run (callback) {
|
|
8259
8073
|
return callback();
|
|
@@ -8288,7 +8102,7 @@ class consumable_Consumable {
|
|
|
8288
8102
|
tryConsume(callback) {
|
|
8289
8103
|
try {
|
|
8290
8104
|
let result = this.#task.run(()=>callback(this.value));
|
|
8291
|
-
if (
|
|
8105
|
+
if (maybe_promise_isPromiseLike(result)) result = result.then((value)=>{
|
|
8292
8106
|
this.#resolver.resolve();
|
|
8293
8107
|
return value;
|
|
8294
8108
|
}, (e)=>{
|
|
@@ -8307,28 +8121,25 @@ function tryConsume(value, callback) {
|
|
|
8307
8121
|
if (value instanceof consumable_Consumable) return value.tryConsume(callback);
|
|
8308
8122
|
else return callback(value);
|
|
8309
8123
|
}
|
|
8310
|
-
class
|
|
8311
|
-
constructor(
|
|
8312
|
-
|
|
8313
|
-
if (strategy) {
|
|
8314
|
-
wrappedStrategy = {};
|
|
8315
|
-
if ("highWaterMark" in strategy) wrappedStrategy.highWaterMark = strategy.highWaterMark;
|
|
8316
|
-
if ("size" in strategy) wrappedStrategy.size = (chunk)=>strategy.size(chunk instanceof consumable_Consumable ? chunk.value : chunk);
|
|
8317
|
-
}
|
|
8124
|
+
class MaybeConsumableWrapWritableStream extends WritableStream {
|
|
8125
|
+
constructor(stream, hooks){
|
|
8126
|
+
const writer = stream.getWriter();
|
|
8318
8127
|
super({
|
|
8319
|
-
|
|
8320
|
-
return
|
|
8321
|
-
|
|
8322
|
-
|
|
8323
|
-
|
|
8128
|
+
write (chunk) {
|
|
8129
|
+
return tryConsume(chunk, async (chunk)=>{
|
|
8130
|
+
if (hooks?.write) await hooks.write(chunk);
|
|
8131
|
+
await writer.write(chunk);
|
|
8132
|
+
});
|
|
8324
8133
|
},
|
|
8325
|
-
abort (reason) {
|
|
8326
|
-
|
|
8134
|
+
async abort (reason) {
|
|
8135
|
+
if (hooks?.abort) await hooks.abort(reason);
|
|
8136
|
+
await writer.abort(reason);
|
|
8327
8137
|
},
|
|
8328
|
-
close () {
|
|
8329
|
-
|
|
8138
|
+
async close () {
|
|
8139
|
+
if (hooks?.close) await hooks.close();
|
|
8140
|
+
await writer.close();
|
|
8330
8141
|
}
|
|
8331
|
-
}
|
|
8142
|
+
});
|
|
8332
8143
|
}
|
|
8333
8144
|
}
|
|
8334
8145
|
function findIndices(str, char) {
|
|
@@ -8364,7 +8175,7 @@ function parseTcpSocketSpec(spec) {
|
|
|
8364
8175
|
const end = spec.indexOf("]");
|
|
8365
8176
|
if (end < 0) throw new Error(`bad IPv6 address ${spec}`);
|
|
8366
8177
|
const host = spec.substring(1, end);
|
|
8367
|
-
|
|
8178
|
+
port = decimalToNumber(spec, end + 2);
|
|
8368
8179
|
if (void 0 === port || port <= 0 || port > 65535) throw new Error(`bad port number ${port} in ${spec}`);
|
|
8369
8180
|
return {
|
|
8370
8181
|
host,
|
|
@@ -8372,7 +8183,6 @@ function parseTcpSocketSpec(spec) {
|
|
|
8372
8183
|
};
|
|
8373
8184
|
}
|
|
8374
8185
|
let host;
|
|
8375
|
-
port = void 0;
|
|
8376
8186
|
const colons = findIndices(spec, ":");
|
|
8377
8187
|
if (!spec.includes(".") && colons.length >= 2 && colons.length <= 7) host = spec;
|
|
8378
8188
|
else if (0 === colons.length) host = spec;
|
|
@@ -8392,39 +8202,27 @@ function parseTcpSocketSpec(spec) {
|
|
|
8392
8202
|
}
|
|
8393
8203
|
function nodeSocketToConnection(socket) {
|
|
8394
8204
|
socket.setNoDelay(true);
|
|
8395
|
-
const
|
|
8396
|
-
|
|
8397
|
-
|
|
8205
|
+
const closedResolver = new PromiseResolver();
|
|
8206
|
+
const handleClose = ()=>{
|
|
8207
|
+
closedResolver.resolve(void 0);
|
|
8208
|
+
cleanup();
|
|
8209
|
+
};
|
|
8210
|
+
const handleError = (e)=>{
|
|
8211
|
+
closedResolver.reject(e);
|
|
8212
|
+
cleanup();
|
|
8213
|
+
};
|
|
8214
|
+
const cleanup = ()=>{
|
|
8215
|
+
socket.removeListener("close", handleClose);
|
|
8216
|
+
socket.removeListener("error", handleError);
|
|
8217
|
+
};
|
|
8218
|
+
socket.addListener("close", handleClose);
|
|
8219
|
+
socket.addListener("error", handleError);
|
|
8220
|
+
suppressUnhandledRejection(closedResolver.promise);
|
|
8398
8221
|
return {
|
|
8399
|
-
readable:
|
|
8400
|
-
|
|
8401
|
-
if (controller.abortSignal.aborted) return;
|
|
8402
|
-
socket.pause();
|
|
8403
|
-
await controller.enqueue(data);
|
|
8404
|
-
socket.resume();
|
|
8405
|
-
});
|
|
8406
|
-
socket.on("error", (e)=>{
|
|
8407
|
-
controller.error(e);
|
|
8408
|
-
});
|
|
8409
|
-
socket.on("end", ()=>{
|
|
8410
|
-
tryClose(controller);
|
|
8411
|
-
});
|
|
8412
|
-
}),
|
|
8413
|
-
writable: new MaybeConsumableWritableStream({
|
|
8414
|
-
start (controller) {
|
|
8415
|
-
socket.on("error", (e)=>{
|
|
8416
|
-
controller.error(e);
|
|
8417
|
-
});
|
|
8418
|
-
},
|
|
8419
|
-
write: (chunk)=>new Promise((resolve, reject)=>{
|
|
8420
|
-
socket.write(chunk, (err)=>{
|
|
8421
|
-
if (err) reject(err);
|
|
8422
|
-
else resolve();
|
|
8423
|
-
});
|
|
8424
|
-
})
|
|
8425
|
-
}),
|
|
8222
|
+
readable: Readable.toWeb(socket),
|
|
8223
|
+
writable: new MaybeConsumableWrapWritableStream(Writable.toWeb(socket)),
|
|
8426
8224
|
get closed () {
|
|
8427
|
-
return
|
|
8225
|
+
return closedResolver.promise;
|
|
8428
8226
|
},
|
|
8429
8227
|
close () {
|
|
8430
8228
|
socket.end();
|
|
@@ -8691,15 +8489,18 @@ async function connectWithPeertalk(connectRaw, options, takeoverHDT = true) {
|
|
|
8691
8489
|
const disposeReason = new Error("Peertalk connection disposed");
|
|
8692
8490
|
let terminationPromise;
|
|
8693
8491
|
let writerReleased = false;
|
|
8492
|
+
let pendingWrites = 0;
|
|
8694
8493
|
const releaseWriter = ()=>{
|
|
8695
8494
|
if (!writerReleased) {
|
|
8696
8495
|
writerReleased = true;
|
|
8697
8496
|
rawWriter.releaseLock();
|
|
8698
8497
|
}
|
|
8699
8498
|
};
|
|
8700
|
-
const terminateConnection = (reason)=>{
|
|
8499
|
+
const terminateConnection = (reason, abortIdleWriter = true)=>{
|
|
8701
8500
|
if (!terminationPromise) {
|
|
8702
|
-
const
|
|
8501
|
+
const shouldAbortWriter = !writerReleased && (abortIdleWriter || pendingWrites > 0);
|
|
8502
|
+
if (!shouldAbortWriter) releaseWriter();
|
|
8503
|
+
const rawAbort = shouldAbortWriter ? rawWriter.abort(reason) : Promise.resolve();
|
|
8703
8504
|
const dispose = Promise.resolve().then(()=>conn[Symbol.asyncDispose]());
|
|
8704
8505
|
terminationPromise = rawAbort.then(()=>dispose, async (error)=>{
|
|
8705
8506
|
await dispose.catch(()=>{});
|
|
@@ -8716,86 +8517,30 @@ async function connectWithPeertalk(connectRaw, options, takeoverHDT = true) {
|
|
|
8716
8517
|
signal.addEventListener("abort", abort, {
|
|
8717
8518
|
once: true
|
|
8718
8519
|
});
|
|
8520
|
+
pendingWrites += 1;
|
|
8719
8521
|
const write = Promise.resolve().then(()=>rawWriter.write(encodePeertalkMessage(message))).catch((error)=>{
|
|
8720
8522
|
terminateConnection(error).catch(()=>{});
|
|
8721
8523
|
throw error;
|
|
8722
8524
|
});
|
|
8723
8525
|
return write.finally(()=>{
|
|
8526
|
+
pendingWrites -= 1;
|
|
8724
8527
|
signal.removeEventListener("abort", abort);
|
|
8725
8528
|
});
|
|
8726
8529
|
},
|
|
8727
8530
|
close: releaseWriter,
|
|
8728
|
-
abort
|
|
8531
|
+
abort (reason) {
|
|
8532
|
+
return terminateConnection(reason, true);
|
|
8533
|
+
}
|
|
8729
8534
|
});
|
|
8730
8535
|
const readable = conn.readable.pipeThrough(new PeertalkToMessageTransformStream());
|
|
8731
8536
|
return {
|
|
8732
8537
|
readable,
|
|
8733
8538
|
writable,
|
|
8734
8539
|
[Symbol.asyncDispose] () {
|
|
8735
|
-
return terminateConnection(disposeReason);
|
|
8540
|
+
return terminateConnection(disposeReason, false);
|
|
8736
8541
|
}
|
|
8737
8542
|
};
|
|
8738
8543
|
}
|
|
8739
|
-
function requireNumericPort(port) {
|
|
8740
|
-
if ("number" == typeof port) return port;
|
|
8741
|
-
if (/^\d+$/.test(port)) return Number(port);
|
|
8742
|
-
throw new TypeError(`Transport requires a numeric port, received target: ${port}`);
|
|
8743
|
-
}
|
|
8744
|
-
function _ts_add_disposable_resource(env, value, async) {
|
|
8745
|
-
if (null != value) {
|
|
8746
|
-
if ("object" != typeof value && "function" != typeof value) throw new TypeError("Object expected.");
|
|
8747
|
-
var dispose, inner;
|
|
8748
|
-
if (async) {
|
|
8749
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
8750
|
-
dispose = value[Symbol.asyncDispose];
|
|
8751
|
-
}
|
|
8752
|
-
if (void 0 === dispose) {
|
|
8753
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
8754
|
-
dispose = value[Symbol.dispose];
|
|
8755
|
-
if (async) inner = dispose;
|
|
8756
|
-
}
|
|
8757
|
-
if ("function" != typeof dispose) throw new TypeError("Object not disposable.");
|
|
8758
|
-
if (inner) dispose = function() {
|
|
8759
|
-
try {
|
|
8760
|
-
inner.call(this);
|
|
8761
|
-
} catch (e) {
|
|
8762
|
-
return Promise.reject(e);
|
|
8763
|
-
}
|
|
8764
|
-
};
|
|
8765
|
-
env.stack.push({
|
|
8766
|
-
value: value,
|
|
8767
|
-
dispose: dispose,
|
|
8768
|
-
async: async
|
|
8769
|
-
});
|
|
8770
|
-
} else if (async) env.stack.push({
|
|
8771
|
-
async: true
|
|
8772
|
-
});
|
|
8773
|
-
return value;
|
|
8774
|
-
}
|
|
8775
|
-
function _ts_dispose_resources(env) {
|
|
8776
|
-
function fail(e) {
|
|
8777
|
-
env.error = env.hasError ? new _SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
8778
|
-
env.hasError = true;
|
|
8779
|
-
}
|
|
8780
|
-
var r, s = 0;
|
|
8781
|
-
function next() {
|
|
8782
|
-
while(r = env.stack.pop())try {
|
|
8783
|
-
if (!r.async && 1 === s) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
8784
|
-
if (r.dispose) {
|
|
8785
|
-
var result = r.dispose.call(r.value);
|
|
8786
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) {
|
|
8787
|
-
fail(e);
|
|
8788
|
-
return next();
|
|
8789
|
-
});
|
|
8790
|
-
} else s |= 1;
|
|
8791
|
-
} catch (e) {
|
|
8792
|
-
fail(e);
|
|
8793
|
-
}
|
|
8794
|
-
if (1 === s) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
8795
|
-
if (env.hasError) throw env.error;
|
|
8796
|
-
}
|
|
8797
|
-
return next();
|
|
8798
|
-
}
|
|
8799
8544
|
const android_debug = ansi_createDebug("devtool-mcp-server:connector:android");
|
|
8800
8545
|
const APP_ICON_HELPER_REMOTE_PATH = "/data/local/tmp/lynx-connector-app-icon-v1.jar";
|
|
8801
8546
|
const PNG_SIGNATURE = [
|
|
@@ -8808,73 +8553,56 @@ const PNG_SIGNATURE = [
|
|
|
8808
8553
|
0x1a,
|
|
8809
8554
|
0x0a
|
|
8810
8555
|
];
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
"cmd",
|
|
8814
|
-
"package",
|
|
8815
|
-
"query-activities",
|
|
8816
|
-
"--components",
|
|
8817
|
-
"-a",
|
|
8818
|
-
"android.intent.action.MAIN",
|
|
8819
|
-
"-c",
|
|
8820
|
-
"android.intent.category.LAUNCHER",
|
|
8821
|
-
"-p",
|
|
8822
|
-
packageName
|
|
8823
|
-
];
|
|
8824
|
-
}
|
|
8825
|
-
function parseLauncherActivityComponents(output) {
|
|
8826
|
-
return output.split("\n").map((line)=>line.trim()).filter((line)=>{
|
|
8827
|
-
const separatorIndex = line.indexOf("/");
|
|
8828
|
-
return !/\s/u.test(line) && separatorIndex > 0 && separatorIndex === line.lastIndexOf("/") && separatorIndex < line.length - 1;
|
|
8829
|
-
});
|
|
8830
|
-
}
|
|
8831
|
-
function createOpenAppCommandArgs(componentName, restart) {
|
|
8832
|
-
return [
|
|
8833
|
-
"am",
|
|
8834
|
-
"start",
|
|
8835
|
-
"-W",
|
|
8836
|
-
...restart ? [
|
|
8837
|
-
"-S"
|
|
8838
|
-
] : [],
|
|
8839
|
-
"-a",
|
|
8840
|
-
"android.intent.action.MAIN",
|
|
8841
|
-
"-c",
|
|
8842
|
-
"android.intent.category.LAUNCHER",
|
|
8843
|
-
"-n",
|
|
8844
|
-
componentName
|
|
8845
|
-
];
|
|
8846
|
-
}
|
|
8556
|
+
const SOCKET_GRACEFUL_CLOSE_TIMEOUT_MS = 100;
|
|
8557
|
+
const WAIT_FOR_DEVICE_TIMEOUT_MS = 3000;
|
|
8847
8558
|
function spawnWaitText(adb, command) {
|
|
8848
8559
|
return adb.subprocess.noneProtocol.spawn(command).wait().toString();
|
|
8849
8560
|
}
|
|
8850
8561
|
class AndroidTransport {
|
|
8562
|
+
id = "android";
|
|
8851
8563
|
client;
|
|
8852
8564
|
#appIconHelperDeployments = new Map();
|
|
8853
8565
|
constructor(spec){
|
|
8854
|
-
|
|
8855
|
-
|
|
8856
|
-
});
|
|
8857
|
-
else if ("path" in spec) this.client = new AdbServerNodeJsClient(spec);
|
|
8858
|
-
else this.client = new AdbServerNodeJsClient({
|
|
8566
|
+
const defaultHost = process.env["ANDROID_ADB_SERVER_ADDRESS"] ?? "127.0.0.1";
|
|
8567
|
+
this.client = spec ? "path" in spec ? new AdbServerNodeJsClient(spec) : new AdbServerNodeJsClient({
|
|
8859
8568
|
...spec,
|
|
8860
8569
|
host: spec.host ?? "127.0.0.1"
|
|
8570
|
+
}) : process.env["ADB_SERVER_SOCKET"] ? new AdbServerNodeJsClient() : new AdbServerNodeJsClient({
|
|
8571
|
+
host: defaultHost
|
|
8861
8572
|
});
|
|
8862
8573
|
}
|
|
8863
8574
|
async connect(options) {
|
|
8864
8575
|
return connectWithPeertalk((opts)=>this.#connectRaw(opts), options);
|
|
8865
8576
|
}
|
|
8866
|
-
async
|
|
8577
|
+
async close() {
|
|
8578
|
+
android_debug("Android transport closed");
|
|
8579
|
+
}
|
|
8580
|
+
async #waitForDevice(deviceId, signal) {
|
|
8581
|
+
const timeoutSignal = AbortSignal.timeout(WAIT_FOR_DEVICE_TIMEOUT_MS);
|
|
8582
|
+
const waitSignal = signal ? AbortSignal.any([
|
|
8583
|
+
signal,
|
|
8584
|
+
timeoutSignal
|
|
8585
|
+
]) : timeoutSignal;
|
|
8586
|
+
try {
|
|
8587
|
+
await this.client.waitFor({
|
|
8588
|
+
serial: deviceId
|
|
8589
|
+
}, "device", {
|
|
8590
|
+
signal: waitSignal
|
|
8591
|
+
});
|
|
8592
|
+
} catch (err) {
|
|
8593
|
+
if (!timeoutSignal.aborted || signal?.aborted) throw err;
|
|
8594
|
+
}
|
|
8595
|
+
}
|
|
8596
|
+
async #withAdb(deviceId, signal, fn) {
|
|
8597
|
+
await this.#waitForDevice(deviceId, signal);
|
|
8867
8598
|
const adb = await this.client.createAdb({
|
|
8868
8599
|
serial: deviceId
|
|
8869
8600
|
});
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
}
|
|
8875
|
-
}
|
|
8876
|
-
async close() {
|
|
8877
|
-
android_debug("Android transport closed");
|
|
8601
|
+
try {
|
|
8602
|
+
return await fn(adb);
|
|
8603
|
+
} finally{
|
|
8604
|
+
await adb.close();
|
|
8605
|
+
}
|
|
8878
8606
|
}
|
|
8879
8607
|
async #connectRaw({ deviceId, port, signal }) {
|
|
8880
8608
|
const numericPort = requireNumericPort(port);
|
|
@@ -8886,72 +8614,32 @@ class AndroidTransport {
|
|
|
8886
8614
|
signal,
|
|
8887
8615
|
closeController.signal
|
|
8888
8616
|
]) : closeController.signal;
|
|
8889
|
-
|
|
8890
|
-
|
|
8891
|
-
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
signal: socketSignal
|
|
8895
|
-
});
|
|
8896
|
-
} catch (err) {
|
|
8897
|
-
android_debug(`connect: create socket to ${service} failed with err: %o`, err);
|
|
8898
|
-
throw err;
|
|
8899
|
-
}
|
|
8900
|
-
const socketClosed = Promise.resolve(socket.closed);
|
|
8901
|
-
let socketClosedSettled = false;
|
|
8902
|
-
socketClosed.then(()=>{
|
|
8903
|
-
socketClosedSettled = true;
|
|
8904
|
-
}, ()=>{
|
|
8905
|
-
socketClosedSettled = true;
|
|
8617
|
+
await this.#waitForDevice(deviceId, socketSignal);
|
|
8618
|
+
const socket = await this.client.createDeviceConnection({
|
|
8619
|
+
serial: deviceId
|
|
8620
|
+
}, service, {
|
|
8621
|
+
signal: socketSignal
|
|
8906
8622
|
});
|
|
8623
|
+
const socketClosed = Promise.resolve(socket.closed).catch(()=>{});
|
|
8907
8624
|
let closePromise;
|
|
8908
|
-
const closeSocket = ()=>{
|
|
8909
|
-
|
|
8910
|
-
|
|
8625
|
+
const closeSocket = ()=>closePromise ??= (async ()=>{
|
|
8626
|
+
await socket.close();
|
|
8627
|
+
const timer = setTimeout(()=>closeController.abort(), SOCKET_GRACEFUL_CLOSE_TIMEOUT_MS);
|
|
8628
|
+
timer.unref?.();
|
|
8911
8629
|
try {
|
|
8912
|
-
|
|
8913
|
-
}
|
|
8914
|
-
|
|
8915
|
-
}
|
|
8916
|
-
|
|
8917
|
-
setImmediate(()=>{
|
|
8918
|
-
if (!socketClosedSettled) {
|
|
8919
|
-
android_debug(`connect: force close socket ${service} after graceful close stalled`);
|
|
8920
|
-
closeController.abort();
|
|
8921
|
-
}
|
|
8922
|
-
resolve();
|
|
8923
|
-
});
|
|
8924
|
-
});
|
|
8925
|
-
closePromise = Promise.allSettled([
|
|
8926
|
-
closeResult,
|
|
8927
|
-
socketClosed,
|
|
8928
|
-
hardCloseCheck
|
|
8929
|
-
]).then(([closeResultOutcome, socketClosedOutcome])=>{
|
|
8930
|
-
if ("rejected" === closeResultOutcome.status) throw closeResultOutcome.reason;
|
|
8931
|
-
if ("rejected" === socketClosedOutcome.status) throw socketClosedOutcome.reason;
|
|
8932
|
-
});
|
|
8933
|
-
}
|
|
8934
|
-
return closePromise;
|
|
8935
|
-
};
|
|
8630
|
+
await socketClosed;
|
|
8631
|
+
} finally{
|
|
8632
|
+
clearTimeout(timer);
|
|
8633
|
+
}
|
|
8634
|
+
})();
|
|
8936
8635
|
if (signal?.aborted) {
|
|
8937
|
-
|
|
8938
|
-
await closeSocket();
|
|
8939
|
-
} catch (err) {
|
|
8940
|
-
android_debug(`connect: close canceled socket ${service} err: %o`, err);
|
|
8941
|
-
}
|
|
8636
|
+
await closeSocket().catch(()=>{});
|
|
8942
8637
|
signal.throwIfAborted();
|
|
8943
8638
|
}
|
|
8944
|
-
const abortHandler = ()=>{
|
|
8945
|
-
closeSocket().catch((err)=>{
|
|
8946
|
-
android_debug(`connect: socket ${service} close on abort err: %o`, err);
|
|
8947
|
-
});
|
|
8948
|
-
};
|
|
8639
|
+
const abortHandler = ()=>void closeSocket().catch(()=>{});
|
|
8949
8640
|
signal?.addEventListener("abort", abortHandler, {
|
|
8950
8641
|
once: true
|
|
8951
8642
|
});
|
|
8952
|
-
socketClosed.catch((err)=>{
|
|
8953
|
-
android_debug(`connect: socket ${service} closed with err: %o`, err);
|
|
8954
|
-
});
|
|
8955
8643
|
return {
|
|
8956
8644
|
readable: socket.readable,
|
|
8957
8645
|
writable: socket.writable,
|
|
@@ -8972,43 +8660,42 @@ class AndroidTransport {
|
|
|
8972
8660
|
}
|
|
8973
8661
|
getKnownApp(_packageName) {}
|
|
8974
8662
|
async listAvailableApps(deviceId) {
|
|
8975
|
-
|
|
8976
|
-
stack: [],
|
|
8977
|
-
error: void 0,
|
|
8978
|
-
hasError: false
|
|
8979
|
-
};
|
|
8980
|
-
try {
|
|
8981
|
-
const adb = _ts_add_disposable_resource(env, await this.#createAdb(deviceId), true);
|
|
8663
|
+
return this.#withAdb(deviceId, void 0, async (adb)=>{
|
|
8982
8664
|
const output = await spawnWaitText(adb, [
|
|
8983
8665
|
"pm",
|
|
8984
8666
|
"list",
|
|
8985
8667
|
"packages",
|
|
8986
8668
|
"-3"
|
|
8987
8669
|
]);
|
|
8988
|
-
|
|
8989
|
-
android_debug("listAvailableApps all packages: %o", packages);
|
|
8990
|
-
return packages.map((packageName)=>({
|
|
8670
|
+
return output.split("\n").map((line)=>line.replace("package:", "").trim()).filter(Boolean).map((packageName)=>({
|
|
8991
8671
|
packageName,
|
|
8992
8672
|
name: this.getKnownApp(packageName)?.name ?? packageName
|
|
8993
8673
|
}));
|
|
8994
|
-
}
|
|
8995
|
-
env.error = e;
|
|
8996
|
-
env.hasError = true;
|
|
8997
|
-
} finally{
|
|
8998
|
-
const result = _ts_dispose_resources(env);
|
|
8999
|
-
if (result) await result;
|
|
9000
|
-
}
|
|
8674
|
+
});
|
|
9001
8675
|
}
|
|
9002
8676
|
async getAppIcon(deviceId, packageName) {
|
|
9003
|
-
|
|
9004
|
-
|
|
9005
|
-
|
|
9006
|
-
|
|
9007
|
-
|
|
9008
|
-
|
|
9009
|
-
|
|
9010
|
-
|
|
9011
|
-
|
|
8677
|
+
if (!/^[A-Za-z][\w.]*$/u.test(packageName)) throw new TypeError(`Invalid Android package name: ${packageName}`);
|
|
8678
|
+
return this.#withAdb(deviceId, void 0, async (adb)=>{
|
|
8679
|
+
let deployment = this.#appIconHelperDeployments.get(deviceId);
|
|
8680
|
+
if (!deployment) {
|
|
8681
|
+
deployment = adb.sync.write({
|
|
8682
|
+
path: APP_ICON_HELPER_REMOTE_PATH,
|
|
8683
|
+
permission: 420,
|
|
8684
|
+
readable: new streams_ReadableStream({
|
|
8685
|
+
start (controller) {
|
|
8686
|
+
controller.enqueue(ANDROID_APP_ICON_HELPER_JAR);
|
|
8687
|
+
controller.close();
|
|
8688
|
+
}
|
|
8689
|
+
})
|
|
8690
|
+
}).then(()=>void 0);
|
|
8691
|
+
this.#appIconHelperDeployments.set(deviceId, deployment);
|
|
8692
|
+
}
|
|
8693
|
+
try {
|
|
8694
|
+
await deployment;
|
|
8695
|
+
} catch (error) {
|
|
8696
|
+
this.#appIconHelperDeployments.delete(deviceId);
|
|
8697
|
+
throw error;
|
|
8698
|
+
}
|
|
9012
8699
|
const data = await adb.subprocess.noneProtocol.spawn([
|
|
9013
8700
|
`CLASSPATH=${APP_ICON_HELPER_REMOTE_PATH}`,
|
|
9014
8701
|
"app_process",
|
|
@@ -9021,60 +8708,22 @@ class AndroidTransport {
|
|
|
9021
8708
|
data,
|
|
9022
8709
|
mimeType: "image/png"
|
|
9023
8710
|
};
|
|
9024
|
-
}
|
|
9025
|
-
env.error = e;
|
|
9026
|
-
env.hasError = true;
|
|
9027
|
-
} finally{
|
|
9028
|
-
const result = _ts_dispose_resources(env);
|
|
9029
|
-
if (result) await result;
|
|
9030
|
-
}
|
|
9031
|
-
}
|
|
9032
|
-
async #ensureAppIconHelper(adb, deviceId) {
|
|
9033
|
-
let deployment = this.#appIconHelperDeployments.get(deviceId);
|
|
9034
|
-
if (!deployment) {
|
|
9035
|
-
deployment = adb.sync.write({
|
|
9036
|
-
path: APP_ICON_HELPER_REMOTE_PATH,
|
|
9037
|
-
permission: 420,
|
|
9038
|
-
readable: new streams_ReadableStream({
|
|
9039
|
-
start (controller) {
|
|
9040
|
-
controller.enqueue(ANDROID_APP_ICON_HELPER_JAR);
|
|
9041
|
-
controller.close();
|
|
9042
|
-
}
|
|
9043
|
-
})
|
|
9044
|
-
}).then(()=>void 0);
|
|
9045
|
-
this.#appIconHelperDeployments.set(deviceId, deployment);
|
|
9046
|
-
}
|
|
9047
|
-
try {
|
|
9048
|
-
await deployment;
|
|
9049
|
-
} catch (error) {
|
|
9050
|
-
this.#appIconHelperDeployments.delete(deviceId);
|
|
9051
|
-
throw error;
|
|
9052
|
-
}
|
|
8711
|
+
});
|
|
9053
8712
|
}
|
|
9054
|
-
async openApp(deviceId, packageName, { withDataCleared, schema, restart = true } = {}) {
|
|
9055
|
-
|
|
9056
|
-
stack: [],
|
|
9057
|
-
error: void 0,
|
|
9058
|
-
hasError: false
|
|
9059
|
-
};
|
|
9060
|
-
try {
|
|
9061
|
-
const adb = _ts_add_disposable_resource(env, await this.#createAdb(deviceId), true);
|
|
8713
|
+
async openApp(deviceId, packageName, { withDataCleared, schema, restart = true, signal } = {}) {
|
|
8714
|
+
await this.#withAdb(deviceId, signal, async (adb)=>{
|
|
9062
8715
|
const pmOutput = await spawnWaitText(adb, [
|
|
9063
8716
|
"pm",
|
|
9064
8717
|
"list",
|
|
9065
8718
|
"packages",
|
|
9066
8719
|
packageName
|
|
9067
8720
|
]);
|
|
9068
|
-
|
|
9069
|
-
if (
|
|
9070
|
-
|
|
9071
|
-
|
|
9072
|
-
|
|
9073
|
-
|
|
9074
|
-
packageName
|
|
9075
|
-
]);
|
|
9076
|
-
android_debug(`openApp clear data output ${output}`);
|
|
9077
|
-
}
|
|
8721
|
+
if (!pmOutput.split("\n").some((line)=>line.trim() === `package:${packageName}`)) throw new Error(`package ${packageName} not found`);
|
|
8722
|
+
if (withDataCleared) await spawnWaitText(adb, [
|
|
8723
|
+
"pm",
|
|
8724
|
+
"clear",
|
|
8725
|
+
packageName
|
|
8726
|
+
]);
|
|
9078
8727
|
let command;
|
|
9079
8728
|
if (schema) command = [
|
|
9080
8729
|
"am",
|
|
@@ -9094,27 +8743,44 @@ class AndroidTransport {
|
|
|
9094
8743
|
const knownActivity = this.getKnownApp(packageName)?.activityName;
|
|
9095
8744
|
let componentName = knownActivity ? `${packageName}/${knownActivity}` : void 0;
|
|
9096
8745
|
if (!componentName) {
|
|
9097
|
-
const queryOutput = await spawnWaitText(adb,
|
|
9098
|
-
|
|
9099
|
-
|
|
8746
|
+
const queryOutput = await spawnWaitText(adb, [
|
|
8747
|
+
"cmd",
|
|
8748
|
+
"package",
|
|
8749
|
+
"query-activities",
|
|
8750
|
+
"--components",
|
|
8751
|
+
"-a",
|
|
8752
|
+
"android.intent.action.MAIN",
|
|
8753
|
+
"-c",
|
|
8754
|
+
"android.intent.category.LAUNCHER",
|
|
8755
|
+
"-p",
|
|
8756
|
+
packageName
|
|
8757
|
+
]);
|
|
8758
|
+
[componentName] = queryOutput.split("\n").map((line)=>line.trim()).filter((line)=>!/\s/u.test(line) && /^[^/]+\/[^/]+$/u.test(line));
|
|
9100
8759
|
}
|
|
9101
8760
|
if (!componentName) throw new Error(`No launchable activity found for package ${packageName}.`);
|
|
9102
|
-
command =
|
|
8761
|
+
command = [
|
|
8762
|
+
"am",
|
|
8763
|
+
"start",
|
|
8764
|
+
"-W",
|
|
8765
|
+
...restart ? [
|
|
8766
|
+
"-S"
|
|
8767
|
+
] : [],
|
|
8768
|
+
"-a",
|
|
8769
|
+
"android.intent.action.MAIN",
|
|
8770
|
+
"-c",
|
|
8771
|
+
"android.intent.category.LAUNCHER",
|
|
8772
|
+
"-n",
|
|
8773
|
+
componentName
|
|
8774
|
+
];
|
|
9103
8775
|
}
|
|
9104
8776
|
const output = await spawnWaitText(adb, command);
|
|
9105
|
-
android_debug(`openApp output ${output}`);
|
|
9106
8777
|
if (output.includes("Error:") || output.includes("Security exception:") || output.includes("Permission Denial:") || output.includes("unable to resolve Intent") || /\b[A-Za-z0-9_$.]*Exception:/u.test(output) || /Error type \d+/u.test(output)) throw new Error(`Failed to open app ${packageName}: ${output.trim()}`);
|
|
9107
|
-
}
|
|
9108
|
-
env.error = e;
|
|
9109
|
-
env.hasError = true;
|
|
9110
|
-
} finally{
|
|
9111
|
-
const result = _ts_dispose_resources(env);
|
|
9112
|
-
if (result) await result;
|
|
9113
|
-
}
|
|
8778
|
+
});
|
|
9114
8779
|
}
|
|
9115
8780
|
}
|
|
9116
8781
|
const desktop_debug = ansi_createDebug("devtool-mcp-server:connector:desktop");
|
|
9117
8782
|
class DesktopTransport {
|
|
8783
|
+
id = "desktop";
|
|
9118
8784
|
#takeoverHDT;
|
|
9119
8785
|
constructor(takeoverHDT = true){
|
|
9120
8786
|
this.#takeoverHDT = takeoverHDT;
|
|
@@ -9203,15 +8869,52 @@ function parseBinary(data) {
|
|
|
9203
8869
|
const len = data.byteLength;
|
|
9204
8870
|
const header = String.fromCharCode(...data.subarray(0, 8));
|
|
9205
8871
|
if ('bplist00' !== header) throw new Error('Invalid binary plist: bad magic');
|
|
8872
|
+
if (len < 40) throw new Error('Invalid binary plist: file too short');
|
|
9206
8873
|
const trailerOffset = len - 32;
|
|
9207
8874
|
const offsetTableOffsetSize = view.getUint8(trailerOffset + 6);
|
|
9208
8875
|
const objectRefSize = view.getUint8(trailerOffset + 7);
|
|
9209
8876
|
const numObjects = readSizedInt(view, trailerOffset + 8, 8);
|
|
9210
8877
|
const topObject = readSizedInt(view, trailerOffset + 16, 8);
|
|
9211
8878
|
const offsetTableOffset = readSizedInt(view, trailerOffset + 24, 8);
|
|
8879
|
+
if (![
|
|
8880
|
+
1,
|
|
8881
|
+
2,
|
|
8882
|
+
4,
|
|
8883
|
+
8
|
|
8884
|
+
].includes(offsetTableOffsetSize) || ![
|
|
8885
|
+
1,
|
|
8886
|
+
2,
|
|
8887
|
+
4,
|
|
8888
|
+
8
|
|
8889
|
+
].includes(objectRefSize)) throw new Error('Invalid binary plist: bad trailer int size');
|
|
8890
|
+
if (numObjects < 1 || topObject >= numObjects || offsetTableOffset < 8 || offsetTableOffset + numObjects * offsetTableOffsetSize > trailerOffset) throw new Error('Invalid binary plist: bad trailer');
|
|
9212
8891
|
const offsets = [];
|
|
9213
|
-
for(let i = 0; i < numObjects; i++)
|
|
8892
|
+
for(let i = 0; i < numObjects; i++){
|
|
8893
|
+
const objOffset = readSizedInt(view, offsetTableOffset + i * offsetTableOffsetSize, offsetTableOffsetSize);
|
|
8894
|
+
if (objOffset < 8 || objOffset >= offsetTableOffset) throw new Error(`Invalid binary plist: bad offset for object ${i}`);
|
|
8895
|
+
offsets.push(objOffset);
|
|
8896
|
+
}
|
|
8897
|
+
const cache = new Map();
|
|
8898
|
+
const inProgress = new Set();
|
|
8899
|
+
function readRef(offset) {
|
|
8900
|
+
const ref = readSizedInt(view, offset, objectRefSize);
|
|
8901
|
+
if (ref >= numObjects) throw new Error(`Invalid binary plist: object ref ${ref} out of range`);
|
|
8902
|
+
return ref;
|
|
8903
|
+
}
|
|
9214
8904
|
function parseObject(index) {
|
|
8905
|
+
const cached = cache.get(index);
|
|
8906
|
+
if (void 0 !== cached) return cached;
|
|
8907
|
+
if (inProgress.has(index)) throw new Error('Invalid binary plist: circular object reference');
|
|
8908
|
+
inProgress.add(index);
|
|
8909
|
+
try {
|
|
8910
|
+
const value = parseObjectUncached(index);
|
|
8911
|
+
if (!(value instanceof Date) && !(value instanceof Uint8Array)) cache.set(index, value);
|
|
8912
|
+
return value;
|
|
8913
|
+
} finally{
|
|
8914
|
+
inProgress.delete(index);
|
|
8915
|
+
}
|
|
8916
|
+
}
|
|
8917
|
+
function parseObjectUncached(index) {
|
|
9215
8918
|
let offset = offsets[index];
|
|
9216
8919
|
const marker = view.getUint8(offset);
|
|
9217
8920
|
const type = marker >> 4;
|
|
@@ -9275,7 +8978,7 @@ function parseBinary(data) {
|
|
|
9275
8978
|
{
|
|
9276
8979
|
const arr = [];
|
|
9277
8980
|
for(let i = 0; i < size; i++){
|
|
9278
|
-
const ref =
|
|
8981
|
+
const ref = readRef(offset + i * objectRefSize);
|
|
9279
8982
|
arr.push(parseObject(ref));
|
|
9280
8983
|
}
|
|
9281
8984
|
return arr;
|
|
@@ -9284,8 +8987,8 @@ function parseBinary(data) {
|
|
|
9284
8987
|
{
|
|
9285
8988
|
const dict = {};
|
|
9286
8989
|
for(let i = 0; i < size; i++){
|
|
9287
|
-
const keyRef =
|
|
9288
|
-
const valRef =
|
|
8990
|
+
const keyRef = readRef(offset + i * objectRefSize);
|
|
8991
|
+
const valRef = readRef(offset + (size + i) * objectRefSize);
|
|
9289
8992
|
const key = parseObject(keyRef);
|
|
9290
8993
|
dict[key] = parseObject(valRef);
|
|
9291
8994
|
}
|
|
@@ -9461,6 +9164,9 @@ function parseOpenStep(input) {
|
|
|
9461
9164
|
return value;
|
|
9462
9165
|
}
|
|
9463
9166
|
const lib = __webpack_require__("../../../node_modules/.pnpm/@xmldom+xmldom@0.9.10/node_modules/@xmldom/xmldom/lib/index.js");
|
|
9167
|
+
function normalizeLineEndings(input) {
|
|
9168
|
+
return input.replace(/\r\n?/g, '\n');
|
|
9169
|
+
}
|
|
9464
9170
|
function base64ToUint8Array(base64) {
|
|
9465
9171
|
const binary = atob(base64);
|
|
9466
9172
|
const bytes = new Uint8Array(binary.length);
|
|
@@ -9491,7 +9197,9 @@ function parse(xml) {
|
|
|
9491
9197
|
const trimmed = xml.trimStart();
|
|
9492
9198
|
if (('{' === trimmed[0] || '(' === trimmed[0]) && !trimmed.startsWith('<?xml') && !trimmed.startsWith('<!DOCTYPE') && !trimmed.startsWith('<plist')) return parseOpenStep(xml);
|
|
9493
9199
|
}
|
|
9494
|
-
const doc = new lib.S4(
|
|
9200
|
+
const doc = new lib.S4({
|
|
9201
|
+
normalizeLineEndings
|
|
9202
|
+
}).parseFromString(xml, "text/xml");
|
|
9495
9203
|
const root = doc.documentElement;
|
|
9496
9204
|
invariant(null !== root && "plist" === root.nodeName, "malformed document. First element should be <plist>");
|
|
9497
9205
|
let plist = parsePlistXML(root);
|
|
@@ -9580,14 +9288,23 @@ function build(obj, opts) {
|
|
|
9580
9288
|
pubid: '-//Apple//DTD PLIST 1.0//EN',
|
|
9581
9289
|
sysid: 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'
|
|
9582
9290
|
};
|
|
9583
|
-
const
|
|
9584
|
-
|
|
9585
|
-
|
|
9291
|
+
const headless = opts?.headless === true;
|
|
9292
|
+
const createOptions = {
|
|
9293
|
+
headless
|
|
9294
|
+
};
|
|
9295
|
+
if (opts?.invalidCharReplacement !== void 0) createOptions.invalidCharReplacement = opts.invalidCharReplacement;
|
|
9296
|
+
const doc = xmlbuilder_lib.create('plist', createOptions);
|
|
9297
|
+
if (!headless) {
|
|
9298
|
+
doc.dec(XMLHDR.version, XMLHDR.encoding);
|
|
9299
|
+
doc.dtd(XMLDTD.pubid, XMLDTD.sysid);
|
|
9300
|
+
}
|
|
9586
9301
|
doc.att('version', '1.0');
|
|
9587
9302
|
walk_obj(obj, doc);
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
|
|
9303
|
+
const xmlToStringOptions = {
|
|
9304
|
+
...opts,
|
|
9305
|
+
pretty: opts?.pretty !== false
|
|
9306
|
+
};
|
|
9307
|
+
return doc.end(xmlToStringOptions);
|
|
9591
9308
|
}
|
|
9592
9309
|
function walk_obj(next, next_child) {
|
|
9593
9310
|
if (void 0 === next) return;
|
|
@@ -9600,10 +9317,10 @@ function walk_obj(next, next_child) {
|
|
|
9600
9317
|
next_child.ele('data').raw(uint8ArrayToBase64(bytes));
|
|
9601
9318
|
} else if ('object' != typeof next || null === next || next instanceof Date) {
|
|
9602
9319
|
if ('number' == typeof next) {
|
|
9603
|
-
const tag_type = next
|
|
9320
|
+
const tag_type = Number.isInteger(next) && Math.abs(next) < 1e21 ? 'integer' : 'real';
|
|
9604
9321
|
next_child.ele(tag_type).txt(next.toString());
|
|
9605
9322
|
} else if ('bigint' == typeof next) next_child.ele('integer').txt(next.toString());
|
|
9606
|
-
else if (next instanceof Date) next_child.ele('date').txt(new Date(next).toISOString().replace(
|
|
9323
|
+
else if (next instanceof Date) next_child.ele('date').txt(new Date(next).toISOString().replace(/\.000Z$/, 'Z'));
|
|
9607
9324
|
else if ('boolean' == typeof next) next_child.ele(next ? 'true' : 'false');
|
|
9608
9325
|
else if ('string' == typeof next) next_child.ele('string').txt(next);
|
|
9609
9326
|
} else {
|
|
@@ -9718,6 +9435,7 @@ class Usbmux {
|
|
|
9718
9435
|
}
|
|
9719
9436
|
const ios_debug = ansi_createDebug("devtool-mcp-server:connector:ios");
|
|
9720
9437
|
class iOSTransport {
|
|
9438
|
+
id = "ios";
|
|
9721
9439
|
#client;
|
|
9722
9440
|
constructor(options){
|
|
9723
9441
|
this.#client = new Usbmux(options);
|
|
@@ -9765,4 +9483,4 @@ class iOSTransport {
|
|
|
9765
9483
|
throw new Error("Not implemented");
|
|
9766
9484
|
}
|
|
9767
9485
|
}
|
|
9768
|
-
export { AndroidTransport, DesktopTransport, MessageToPeertalkTransformStream, PeertalkToMessageTransformStream, Usbmux, connectWithPeertalk, encodePeertalkMessage, iOSTransport
|
|
9486
|
+
export { AndroidTransport, DesktopTransport, MessageToPeertalkTransformStream, PeertalkToMessageTransformStream, Usbmux, connectWithPeertalk, encodePeertalkMessage, iOSTransport };
|