@lynx-js/devtool-connector 0.18.8 → 0.19.1
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 +32 -0
- package/dist/{u.js → 0.js} +67 -55
- 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 +295 -574
- package/dist/hb.js +1 -4
- package/dist/index.d.ts +3 -25
- package/dist/index.js +1 -1
- package/dist/t.js +56 -26
- 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/peertalk.d.ts +0 -3
- package/dist/transport/transport.d.ts +5 -0
- package/dist/types.d.ts +1 -24
- package/dist/ws-stream.js +2 -2
- package/package.json +7 -7
- 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();
|
|
@@ -8627,7 +8425,7 @@ class PeertalkToMessageTransformStream extends web_TransformStream {
|
|
|
8627
8425
|
let end = 0;
|
|
8628
8426
|
const decoder = new TextDecoder();
|
|
8629
8427
|
super({
|
|
8630
|
-
transform
|
|
8428
|
+
transform (chunk, controller) {
|
|
8631
8429
|
const buffered = end - start;
|
|
8632
8430
|
if (buffer.length - end < chunk.length) if (buffered + chunk.length <= buffer.length) {
|
|
8633
8431
|
buffer.copyWithin(0, start, end);
|
|
@@ -8643,29 +8441,22 @@ class PeertalkToMessageTransformStream extends web_TransformStream {
|
|
|
8643
8441
|
buffer.set(chunk, end);
|
|
8644
8442
|
end += chunk.length;
|
|
8645
8443
|
while(end - start >= 20){
|
|
8646
|
-
const
|
|
8647
|
-
const len =
|
|
8444
|
+
const view = new DataView(buffer.buffer, buffer.byteOffset + start, 20);
|
|
8445
|
+
const len = view.getUint32(16);
|
|
8648
8446
|
if (end - start < 20 + len) break;
|
|
8649
8447
|
try {
|
|
8650
|
-
|
|
8651
|
-
} catch (
|
|
8652
|
-
|
|
8448
|
+
controller.enqueue(JSON.parse(decoder.decode(buffer.subarray(start + 20, start + 20 + len))));
|
|
8449
|
+
} catch (error) {
|
|
8450
|
+
controller.error(error);
|
|
8451
|
+
return;
|
|
8653
8452
|
}
|
|
8654
8453
|
start += 20 + len;
|
|
8655
|
-
if (start === end) {
|
|
8656
|
-
start = 0;
|
|
8657
|
-
end = 0;
|
|
8658
|
-
}
|
|
8659
8454
|
}
|
|
8660
|
-
|
|
8661
|
-
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
constructor(){
|
|
8666
|
-
super({
|
|
8667
|
-
transform (chunk, controller) {
|
|
8668
|
-
controller.enqueue(encodePeertalkMessage(chunk));
|
|
8455
|
+
if (start === end) {
|
|
8456
|
+
start = 0;
|
|
8457
|
+
end = 0;
|
|
8458
|
+
buffer = new Uint8Array(0);
|
|
8459
|
+
}
|
|
8669
8460
|
}
|
|
8670
8461
|
});
|
|
8671
8462
|
}
|
|
@@ -8687,19 +8478,19 @@ function encodePeertalkMessage(message) {
|
|
|
8687
8478
|
async function connectWithPeertalk(connectRaw, options, takeoverHDT = true) {
|
|
8688
8479
|
if (takeoverHDT) await takeoverDebugRouterLock();
|
|
8689
8480
|
const conn = await connectRaw(options);
|
|
8690
|
-
|
|
8691
|
-
|
|
8481
|
+
let rawWriter = conn.writable.getWriter();
|
|
8482
|
+
let writing = false;
|
|
8692
8483
|
let terminationPromise;
|
|
8693
|
-
let writerReleased = false;
|
|
8694
8484
|
const releaseWriter = ()=>{
|
|
8695
|
-
|
|
8696
|
-
|
|
8697
|
-
rawWriter.releaseLock();
|
|
8698
|
-
}
|
|
8485
|
+
rawWriter?.releaseLock();
|
|
8486
|
+
rawWriter = void 0;
|
|
8699
8487
|
};
|
|
8700
|
-
const terminateConnection = (reason)=>{
|
|
8488
|
+
const terminateConnection = (reason, abortIdleWriter = true)=>{
|
|
8701
8489
|
if (!terminationPromise) {
|
|
8702
|
-
const
|
|
8490
|
+
const writer = rawWriter;
|
|
8491
|
+
const shouldAbort = void 0 !== writer && (abortIdleWriter || writing);
|
|
8492
|
+
if (!shouldAbort) releaseWriter();
|
|
8493
|
+
const rawAbort = shouldAbort ? writer.abort(reason) : Promise.resolve();
|
|
8703
8494
|
const dispose = Promise.resolve().then(()=>conn[Symbol.asyncDispose]());
|
|
8704
8495
|
terminationPromise = rawAbort.then(()=>dispose, async (error)=>{
|
|
8705
8496
|
await dispose.catch(()=>{});
|
|
@@ -8710,92 +8501,43 @@ async function connectWithPeertalk(connectRaw, options, takeoverHDT = true) {
|
|
|
8710
8501
|
return terminationPromise;
|
|
8711
8502
|
};
|
|
8712
8503
|
const writable = new web_WritableStream({
|
|
8713
|
-
write (message, controller) {
|
|
8504
|
+
async write (message, controller) {
|
|
8714
8505
|
const signal = controller.signal;
|
|
8715
|
-
const abort = ()=>
|
|
8506
|
+
const abort = ()=>{
|
|
8507
|
+
if (writing) terminateConnection(signal.reason).catch(()=>{});
|
|
8508
|
+
};
|
|
8716
8509
|
signal.addEventListener("abort", abort, {
|
|
8717
8510
|
once: true
|
|
8718
8511
|
});
|
|
8719
|
-
|
|
8512
|
+
writing = true;
|
|
8513
|
+
try {
|
|
8514
|
+
await rawWriter.write(encodePeertalkMessage(message));
|
|
8515
|
+
} catch (error) {
|
|
8720
8516
|
terminateConnection(error).catch(()=>{});
|
|
8721
8517
|
throw error;
|
|
8722
|
-
}
|
|
8723
|
-
|
|
8518
|
+
} finally{
|
|
8519
|
+
writing = false;
|
|
8724
8520
|
signal.removeEventListener("abort", abort);
|
|
8725
|
-
}
|
|
8521
|
+
}
|
|
8726
8522
|
},
|
|
8727
8523
|
close: releaseWriter,
|
|
8728
|
-
abort
|
|
8524
|
+
abort (reason) {
|
|
8525
|
+
if (!writing) {
|
|
8526
|
+
releaseWriter();
|
|
8527
|
+
return Promise.resolve();
|
|
8528
|
+
}
|
|
8529
|
+
return terminateConnection(reason, true);
|
|
8530
|
+
}
|
|
8729
8531
|
});
|
|
8730
8532
|
const readable = conn.readable.pipeThrough(new PeertalkToMessageTransformStream());
|
|
8731
8533
|
return {
|
|
8732
8534
|
readable,
|
|
8733
8535
|
writable,
|
|
8734
8536
|
[Symbol.asyncDispose] () {
|
|
8735
|
-
return terminateConnection(
|
|
8537
|
+
return terminateConnection(new Error("Peertalk connection disposed"), false);
|
|
8736
8538
|
}
|
|
8737
8539
|
};
|
|
8738
8540
|
}
|
|
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
8541
|
const android_debug = ansi_createDebug("devtool-mcp-server:connector:android");
|
|
8800
8542
|
const APP_ICON_HELPER_REMOTE_PATH = "/data/local/tmp/lynx-connector-app-icon-v1.jar";
|
|
8801
8543
|
const PNG_SIGNATURE = [
|
|
@@ -8808,73 +8550,56 @@ const PNG_SIGNATURE = [
|
|
|
8808
8550
|
0x1a,
|
|
8809
8551
|
0x0a
|
|
8810
8552
|
];
|
|
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
|
-
}
|
|
8553
|
+
const SOCKET_GRACEFUL_CLOSE_TIMEOUT_MS = 100;
|
|
8554
|
+
const WAIT_FOR_DEVICE_TIMEOUT_MS = 3000;
|
|
8847
8555
|
function spawnWaitText(adb, command) {
|
|
8848
8556
|
return adb.subprocess.noneProtocol.spawn(command).wait().toString();
|
|
8849
8557
|
}
|
|
8850
8558
|
class AndroidTransport {
|
|
8559
|
+
id = "android";
|
|
8851
8560
|
client;
|
|
8852
8561
|
#appIconHelperDeployments = new Map();
|
|
8853
8562
|
constructor(spec){
|
|
8854
|
-
|
|
8855
|
-
|
|
8856
|
-
});
|
|
8857
|
-
else if ("path" in spec) this.client = new AdbServerNodeJsClient(spec);
|
|
8858
|
-
else this.client = new AdbServerNodeJsClient({
|
|
8563
|
+
const defaultHost = process.env["ANDROID_ADB_SERVER_ADDRESS"] ?? "127.0.0.1";
|
|
8564
|
+
this.client = spec ? "path" in spec ? new AdbServerNodeJsClient(spec) : new AdbServerNodeJsClient({
|
|
8859
8565
|
...spec,
|
|
8860
8566
|
host: spec.host ?? "127.0.0.1"
|
|
8567
|
+
}) : process.env["ADB_SERVER_SOCKET"] ? new AdbServerNodeJsClient() : new AdbServerNodeJsClient({
|
|
8568
|
+
host: defaultHost
|
|
8861
8569
|
});
|
|
8862
8570
|
}
|
|
8863
8571
|
async connect(options) {
|
|
8864
8572
|
return connectWithPeertalk((opts)=>this.#connectRaw(opts), options);
|
|
8865
8573
|
}
|
|
8866
|
-
async
|
|
8574
|
+
async close() {
|
|
8575
|
+
android_debug("Android transport closed");
|
|
8576
|
+
}
|
|
8577
|
+
async #waitForDevice(deviceId, signal) {
|
|
8578
|
+
const timeoutSignal = AbortSignal.timeout(WAIT_FOR_DEVICE_TIMEOUT_MS);
|
|
8579
|
+
const waitSignal = signal ? AbortSignal.any([
|
|
8580
|
+
signal,
|
|
8581
|
+
timeoutSignal
|
|
8582
|
+
]) : timeoutSignal;
|
|
8583
|
+
try {
|
|
8584
|
+
await this.client.waitFor({
|
|
8585
|
+
serial: deviceId
|
|
8586
|
+
}, "device", {
|
|
8587
|
+
signal: waitSignal
|
|
8588
|
+
});
|
|
8589
|
+
} catch (err) {
|
|
8590
|
+
if (!timeoutSignal.aborted || signal?.aborted) throw err;
|
|
8591
|
+
}
|
|
8592
|
+
}
|
|
8593
|
+
async #withAdb(deviceId, signal, fn) {
|
|
8594
|
+
await this.#waitForDevice(deviceId, signal);
|
|
8867
8595
|
const adb = await this.client.createAdb({
|
|
8868
8596
|
serial: deviceId
|
|
8869
8597
|
});
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
}
|
|
8875
|
-
}
|
|
8876
|
-
async close() {
|
|
8877
|
-
android_debug("Android transport closed");
|
|
8598
|
+
try {
|
|
8599
|
+
return await fn(adb);
|
|
8600
|
+
} finally{
|
|
8601
|
+
await adb.close();
|
|
8602
|
+
}
|
|
8878
8603
|
}
|
|
8879
8604
|
async #connectRaw({ deviceId, port, signal }) {
|
|
8880
8605
|
const numericPort = requireNumericPort(port);
|
|
@@ -8886,72 +8611,32 @@ class AndroidTransport {
|
|
|
8886
8611
|
signal,
|
|
8887
8612
|
closeController.signal
|
|
8888
8613
|
]) : 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;
|
|
8614
|
+
await this.#waitForDevice(deviceId, socketSignal);
|
|
8615
|
+
const socket = await this.client.createDeviceConnection({
|
|
8616
|
+
serial: deviceId
|
|
8617
|
+
}, service, {
|
|
8618
|
+
signal: socketSignal
|
|
8906
8619
|
});
|
|
8620
|
+
const socketClosed = Promise.resolve(socket.closed).catch(()=>{});
|
|
8907
8621
|
let closePromise;
|
|
8908
|
-
const closeSocket = ()=>{
|
|
8909
|
-
|
|
8910
|
-
|
|
8622
|
+
const closeSocket = ()=>closePromise ??= (async ()=>{
|
|
8623
|
+
await socket.close();
|
|
8624
|
+
const timer = setTimeout(()=>closeController.abort(), SOCKET_GRACEFUL_CLOSE_TIMEOUT_MS);
|
|
8625
|
+
timer.unref?.();
|
|
8911
8626
|
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
|
-
};
|
|
8627
|
+
await socketClosed;
|
|
8628
|
+
} finally{
|
|
8629
|
+
clearTimeout(timer);
|
|
8630
|
+
}
|
|
8631
|
+
})();
|
|
8936
8632
|
if (signal?.aborted) {
|
|
8937
|
-
|
|
8938
|
-
await closeSocket();
|
|
8939
|
-
} catch (err) {
|
|
8940
|
-
android_debug(`connect: close canceled socket ${service} err: %o`, err);
|
|
8941
|
-
}
|
|
8633
|
+
await closeSocket().catch(()=>{});
|
|
8942
8634
|
signal.throwIfAborted();
|
|
8943
8635
|
}
|
|
8944
|
-
const abortHandler = ()=>{
|
|
8945
|
-
closeSocket().catch((err)=>{
|
|
8946
|
-
android_debug(`connect: socket ${service} close on abort err: %o`, err);
|
|
8947
|
-
});
|
|
8948
|
-
};
|
|
8636
|
+
const abortHandler = ()=>void closeSocket().catch(()=>{});
|
|
8949
8637
|
signal?.addEventListener("abort", abortHandler, {
|
|
8950
8638
|
once: true
|
|
8951
8639
|
});
|
|
8952
|
-
socketClosed.catch((err)=>{
|
|
8953
|
-
android_debug(`connect: socket ${service} closed with err: %o`, err);
|
|
8954
|
-
});
|
|
8955
8640
|
return {
|
|
8956
8641
|
readable: socket.readable,
|
|
8957
8642
|
writable: socket.writable,
|
|
@@ -8972,43 +8657,42 @@ class AndroidTransport {
|
|
|
8972
8657
|
}
|
|
8973
8658
|
getKnownApp(_packageName) {}
|
|
8974
8659
|
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);
|
|
8660
|
+
return this.#withAdb(deviceId, void 0, async (adb)=>{
|
|
8982
8661
|
const output = await spawnWaitText(adb, [
|
|
8983
8662
|
"pm",
|
|
8984
8663
|
"list",
|
|
8985
8664
|
"packages",
|
|
8986
8665
|
"-3"
|
|
8987
8666
|
]);
|
|
8988
|
-
|
|
8989
|
-
android_debug("listAvailableApps all packages: %o", packages);
|
|
8990
|
-
return packages.map((packageName)=>({
|
|
8667
|
+
return output.split("\n").map((line)=>line.replace("package:", "").trim()).filter(Boolean).map((packageName)=>({
|
|
8991
8668
|
packageName,
|
|
8992
8669
|
name: this.getKnownApp(packageName)?.name ?? packageName
|
|
8993
8670
|
}));
|
|
8994
|
-
}
|
|
8995
|
-
env.error = e;
|
|
8996
|
-
env.hasError = true;
|
|
8997
|
-
} finally{
|
|
8998
|
-
const result = _ts_dispose_resources(env);
|
|
8999
|
-
if (result) await result;
|
|
9000
|
-
}
|
|
8671
|
+
});
|
|
9001
8672
|
}
|
|
9002
8673
|
async getAppIcon(deviceId, packageName) {
|
|
9003
|
-
|
|
9004
|
-
|
|
9005
|
-
|
|
9006
|
-
|
|
9007
|
-
|
|
9008
|
-
|
|
9009
|
-
|
|
9010
|
-
|
|
9011
|
-
|
|
8674
|
+
if (!/^[A-Za-z][\w.]*$/u.test(packageName)) throw new TypeError(`Invalid Android package name: ${packageName}`);
|
|
8675
|
+
return this.#withAdb(deviceId, void 0, async (adb)=>{
|
|
8676
|
+
let deployment = this.#appIconHelperDeployments.get(deviceId);
|
|
8677
|
+
if (!deployment) {
|
|
8678
|
+
deployment = adb.sync.write({
|
|
8679
|
+
path: APP_ICON_HELPER_REMOTE_PATH,
|
|
8680
|
+
permission: 420,
|
|
8681
|
+
readable: new streams_ReadableStream({
|
|
8682
|
+
start (controller) {
|
|
8683
|
+
controller.enqueue(ANDROID_APP_ICON_HELPER_JAR);
|
|
8684
|
+
controller.close();
|
|
8685
|
+
}
|
|
8686
|
+
})
|
|
8687
|
+
}).then(()=>void 0);
|
|
8688
|
+
this.#appIconHelperDeployments.set(deviceId, deployment);
|
|
8689
|
+
}
|
|
8690
|
+
try {
|
|
8691
|
+
await deployment;
|
|
8692
|
+
} catch (error) {
|
|
8693
|
+
this.#appIconHelperDeployments.delete(deviceId);
|
|
8694
|
+
throw error;
|
|
8695
|
+
}
|
|
9012
8696
|
const data = await adb.subprocess.noneProtocol.spawn([
|
|
9013
8697
|
`CLASSPATH=${APP_ICON_HELPER_REMOTE_PATH}`,
|
|
9014
8698
|
"app_process",
|
|
@@ -9021,60 +8705,22 @@ class AndroidTransport {
|
|
|
9021
8705
|
data,
|
|
9022
8706
|
mimeType: "image/png"
|
|
9023
8707
|
};
|
|
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
|
-
}
|
|
8708
|
+
});
|
|
9053
8709
|
}
|
|
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);
|
|
8710
|
+
async openApp(deviceId, packageName, { withDataCleared, schema, restart = true, signal } = {}) {
|
|
8711
|
+
await this.#withAdb(deviceId, signal, async (adb)=>{
|
|
9062
8712
|
const pmOutput = await spawnWaitText(adb, [
|
|
9063
8713
|
"pm",
|
|
9064
8714
|
"list",
|
|
9065
8715
|
"packages",
|
|
9066
8716
|
packageName
|
|
9067
8717
|
]);
|
|
9068
|
-
|
|
9069
|
-
if (
|
|
9070
|
-
|
|
9071
|
-
|
|
9072
|
-
|
|
9073
|
-
|
|
9074
|
-
packageName
|
|
9075
|
-
]);
|
|
9076
|
-
android_debug(`openApp clear data output ${output}`);
|
|
9077
|
-
}
|
|
8718
|
+
if (!pmOutput.split("\n").some((line)=>line.trim() === `package:${packageName}`)) throw new Error(`package ${packageName} not found`);
|
|
8719
|
+
if (withDataCleared) await spawnWaitText(adb, [
|
|
8720
|
+
"pm",
|
|
8721
|
+
"clear",
|
|
8722
|
+
packageName
|
|
8723
|
+
]);
|
|
9078
8724
|
let command;
|
|
9079
8725
|
if (schema) command = [
|
|
9080
8726
|
"am",
|
|
@@ -9094,27 +8740,44 @@ class AndroidTransport {
|
|
|
9094
8740
|
const knownActivity = this.getKnownApp(packageName)?.activityName;
|
|
9095
8741
|
let componentName = knownActivity ? `${packageName}/${knownActivity}` : void 0;
|
|
9096
8742
|
if (!componentName) {
|
|
9097
|
-
const queryOutput = await spawnWaitText(adb,
|
|
9098
|
-
|
|
9099
|
-
|
|
8743
|
+
const queryOutput = await spawnWaitText(adb, [
|
|
8744
|
+
"cmd",
|
|
8745
|
+
"package",
|
|
8746
|
+
"query-activities",
|
|
8747
|
+
"--components",
|
|
8748
|
+
"-a",
|
|
8749
|
+
"android.intent.action.MAIN",
|
|
8750
|
+
"-c",
|
|
8751
|
+
"android.intent.category.LAUNCHER",
|
|
8752
|
+
"-p",
|
|
8753
|
+
packageName
|
|
8754
|
+
]);
|
|
8755
|
+
[componentName] = queryOutput.split("\n").map((line)=>line.trim()).filter((line)=>!/\s/u.test(line) && /^[^/]+\/[^/]+$/u.test(line));
|
|
9100
8756
|
}
|
|
9101
8757
|
if (!componentName) throw new Error(`No launchable activity found for package ${packageName}.`);
|
|
9102
|
-
command =
|
|
8758
|
+
command = [
|
|
8759
|
+
"am",
|
|
8760
|
+
"start",
|
|
8761
|
+
"-W",
|
|
8762
|
+
...restart ? [
|
|
8763
|
+
"-S"
|
|
8764
|
+
] : [],
|
|
8765
|
+
"-a",
|
|
8766
|
+
"android.intent.action.MAIN",
|
|
8767
|
+
"-c",
|
|
8768
|
+
"android.intent.category.LAUNCHER",
|
|
8769
|
+
"-n",
|
|
8770
|
+
componentName
|
|
8771
|
+
];
|
|
9103
8772
|
}
|
|
9104
8773
|
const output = await spawnWaitText(adb, command);
|
|
9105
|
-
android_debug(`openApp output ${output}`);
|
|
9106
8774
|
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
|
-
}
|
|
8775
|
+
});
|
|
9114
8776
|
}
|
|
9115
8777
|
}
|
|
9116
8778
|
const desktop_debug = ansi_createDebug("devtool-mcp-server:connector:desktop");
|
|
9117
8779
|
class DesktopTransport {
|
|
8780
|
+
id = "desktop";
|
|
9118
8781
|
#takeoverHDT;
|
|
9119
8782
|
constructor(takeoverHDT = true){
|
|
9120
8783
|
this.#takeoverHDT = takeoverHDT;
|
|
@@ -9179,6 +8842,10 @@ class DesktopTransport {
|
|
|
9179
8842
|
}
|
|
9180
8843
|
}
|
|
9181
8844
|
}
|
|
8845
|
+
function assertSafeKey(key) {
|
|
8846
|
+
if ('string' != typeof key) throw new Error(`Invalid plist dictionary key of type ${typeof key}`);
|
|
8847
|
+
if ('__proto__' === key) throw new Error('__proto__ keys can lead to prototype pollution. More details on CVE-2022-22912');
|
|
8848
|
+
}
|
|
9182
8849
|
const EPOCH_2001 = 978307200000;
|
|
9183
8850
|
function readSizedInt(view, offset, size) {
|
|
9184
8851
|
switch(size){
|
|
@@ -9203,15 +8870,52 @@ function parseBinary(data) {
|
|
|
9203
8870
|
const len = data.byteLength;
|
|
9204
8871
|
const header = String.fromCharCode(...data.subarray(0, 8));
|
|
9205
8872
|
if ('bplist00' !== header) throw new Error('Invalid binary plist: bad magic');
|
|
8873
|
+
if (len < 40) throw new Error('Invalid binary plist: file too short');
|
|
9206
8874
|
const trailerOffset = len - 32;
|
|
9207
8875
|
const offsetTableOffsetSize = view.getUint8(trailerOffset + 6);
|
|
9208
8876
|
const objectRefSize = view.getUint8(trailerOffset + 7);
|
|
9209
8877
|
const numObjects = readSizedInt(view, trailerOffset + 8, 8);
|
|
9210
8878
|
const topObject = readSizedInt(view, trailerOffset + 16, 8);
|
|
9211
8879
|
const offsetTableOffset = readSizedInt(view, trailerOffset + 24, 8);
|
|
8880
|
+
if (![
|
|
8881
|
+
1,
|
|
8882
|
+
2,
|
|
8883
|
+
4,
|
|
8884
|
+
8
|
|
8885
|
+
].includes(offsetTableOffsetSize) || ![
|
|
8886
|
+
1,
|
|
8887
|
+
2,
|
|
8888
|
+
4,
|
|
8889
|
+
8
|
|
8890
|
+
].includes(objectRefSize)) throw new Error('Invalid binary plist: bad trailer int size');
|
|
8891
|
+
if (numObjects < 1 || topObject >= numObjects || offsetTableOffset < 8 || offsetTableOffset + numObjects * offsetTableOffsetSize > trailerOffset) throw new Error('Invalid binary plist: bad trailer');
|
|
9212
8892
|
const offsets = [];
|
|
9213
|
-
for(let i = 0; i < numObjects; i++)
|
|
8893
|
+
for(let i = 0; i < numObjects; i++){
|
|
8894
|
+
const objOffset = readSizedInt(view, offsetTableOffset + i * offsetTableOffsetSize, offsetTableOffsetSize);
|
|
8895
|
+
if (objOffset < 8 || objOffset >= offsetTableOffset) throw new Error(`Invalid binary plist: bad offset for object ${i}`);
|
|
8896
|
+
offsets.push(objOffset);
|
|
8897
|
+
}
|
|
8898
|
+
const cache = new Map();
|
|
8899
|
+
const inProgress = new Set();
|
|
8900
|
+
function readRef(offset) {
|
|
8901
|
+
const ref = readSizedInt(view, offset, objectRefSize);
|
|
8902
|
+
if (ref >= numObjects) throw new Error(`Invalid binary plist: object ref ${ref} out of range`);
|
|
8903
|
+
return ref;
|
|
8904
|
+
}
|
|
9214
8905
|
function parseObject(index) {
|
|
8906
|
+
const cached = cache.get(index);
|
|
8907
|
+
if (void 0 !== cached) return cached;
|
|
8908
|
+
if (inProgress.has(index)) throw new Error('Invalid binary plist: circular object reference');
|
|
8909
|
+
inProgress.add(index);
|
|
8910
|
+
try {
|
|
8911
|
+
const value = parseObjectUncached(index);
|
|
8912
|
+
if (!(value instanceof Date) && !(value instanceof Uint8Array)) cache.set(index, value);
|
|
8913
|
+
return value;
|
|
8914
|
+
} finally{
|
|
8915
|
+
inProgress.delete(index);
|
|
8916
|
+
}
|
|
8917
|
+
}
|
|
8918
|
+
function parseObjectUncached(index) {
|
|
9215
8919
|
let offset = offsets[index];
|
|
9216
8920
|
const marker = view.getUint8(offset);
|
|
9217
8921
|
const type = marker >> 4;
|
|
@@ -9275,7 +8979,7 @@ function parseBinary(data) {
|
|
|
9275
8979
|
{
|
|
9276
8980
|
const arr = [];
|
|
9277
8981
|
for(let i = 0; i < size; i++){
|
|
9278
|
-
const ref =
|
|
8982
|
+
const ref = readRef(offset + i * objectRefSize);
|
|
9279
8983
|
arr.push(parseObject(ref));
|
|
9280
8984
|
}
|
|
9281
8985
|
return arr;
|
|
@@ -9284,9 +8988,10 @@ function parseBinary(data) {
|
|
|
9284
8988
|
{
|
|
9285
8989
|
const dict = {};
|
|
9286
8990
|
for(let i = 0; i < size; i++){
|
|
9287
|
-
const keyRef =
|
|
9288
|
-
const valRef =
|
|
8991
|
+
const keyRef = readRef(offset + i * objectRefSize);
|
|
8992
|
+
const valRef = readRef(offset + (size + i) * objectRefSize);
|
|
9289
8993
|
const key = parseObject(keyRef);
|
|
8994
|
+
assertSafeKey(key);
|
|
9290
8995
|
dict[key] = parseObject(valRef);
|
|
9291
8996
|
}
|
|
9292
8997
|
return dict;
|
|
@@ -9348,6 +9053,7 @@ class OpenStepParser {
|
|
|
9348
9053
|
return obj;
|
|
9349
9054
|
}
|
|
9350
9055
|
const key = this.parseValue();
|
|
9056
|
+
assertSafeKey(key);
|
|
9351
9057
|
this.skipWhitespaceAndComments();
|
|
9352
9058
|
if (this.pos >= this.input.length || '=' !== this.input[this.pos]) throw new Error(`Expected '=' after key "${key}" at position ${this.pos}`);
|
|
9353
9059
|
this.pos++;
|
|
@@ -9461,6 +9167,9 @@ function parseOpenStep(input) {
|
|
|
9461
9167
|
return value;
|
|
9462
9168
|
}
|
|
9463
9169
|
const lib = __webpack_require__("../../../node_modules/.pnpm/@xmldom+xmldom@0.9.10/node_modules/@xmldom/xmldom/lib/index.js");
|
|
9170
|
+
function normalizeLineEndings(input) {
|
|
9171
|
+
return input.replace(/\r\n?/g, '\n');
|
|
9172
|
+
}
|
|
9464
9173
|
function base64ToUint8Array(base64) {
|
|
9465
9174
|
const binary = atob(base64);
|
|
9466
9175
|
const bytes = new Uint8Array(binary.length);
|
|
@@ -9491,7 +9200,9 @@ function parse(xml) {
|
|
|
9491
9200
|
const trimmed = xml.trimStart();
|
|
9492
9201
|
if (('{' === trimmed[0] || '(' === trimmed[0]) && !trimmed.startsWith('<?xml') && !trimmed.startsWith('<!DOCTYPE') && !trimmed.startsWith('<plist')) return parseOpenStep(xml);
|
|
9493
9202
|
}
|
|
9494
|
-
const doc = new lib.S4(
|
|
9203
|
+
const doc = new lib.S4({
|
|
9204
|
+
normalizeLineEndings
|
|
9205
|
+
}).parseFromString(xml, "text/xml");
|
|
9495
9206
|
const root = doc.documentElement;
|
|
9496
9207
|
invariant(null !== root && "plist" === root.nodeName, "malformed document. First element should be <plist>");
|
|
9497
9208
|
let plist = parsePlistXML(root);
|
|
@@ -9580,14 +9291,23 @@ function build(obj, opts) {
|
|
|
9580
9291
|
pubid: '-//Apple//DTD PLIST 1.0//EN',
|
|
9581
9292
|
sysid: 'http://www.apple.com/DTDs/PropertyList-1.0.dtd'
|
|
9582
9293
|
};
|
|
9583
|
-
const
|
|
9584
|
-
|
|
9585
|
-
|
|
9294
|
+
const headless = opts?.headless === true;
|
|
9295
|
+
const createOptions = {
|
|
9296
|
+
headless
|
|
9297
|
+
};
|
|
9298
|
+
if (opts?.invalidCharReplacement !== void 0) createOptions.invalidCharReplacement = opts.invalidCharReplacement;
|
|
9299
|
+
const doc = xmlbuilder_lib.create('plist', createOptions);
|
|
9300
|
+
if (!headless) {
|
|
9301
|
+
doc.dec(XMLHDR.version, XMLHDR.encoding);
|
|
9302
|
+
doc.dtd(XMLDTD.pubid, XMLDTD.sysid);
|
|
9303
|
+
}
|
|
9586
9304
|
doc.att('version', '1.0');
|
|
9587
9305
|
walk_obj(obj, doc);
|
|
9588
|
-
|
|
9589
|
-
|
|
9590
|
-
|
|
9306
|
+
const xmlToStringOptions = {
|
|
9307
|
+
...opts,
|
|
9308
|
+
pretty: opts?.pretty !== false
|
|
9309
|
+
};
|
|
9310
|
+
return doc.end(xmlToStringOptions);
|
|
9591
9311
|
}
|
|
9592
9312
|
function walk_obj(next, next_child) {
|
|
9593
9313
|
if (void 0 === next) return;
|
|
@@ -9600,10 +9320,10 @@ function walk_obj(next, next_child) {
|
|
|
9600
9320
|
next_child.ele('data').raw(uint8ArrayToBase64(bytes));
|
|
9601
9321
|
} else if ('object' != typeof next || null === next || next instanceof Date) {
|
|
9602
9322
|
if ('number' == typeof next) {
|
|
9603
|
-
const tag_type = next
|
|
9323
|
+
const tag_type = Number.isInteger(next) && Math.abs(next) < 1e21 ? 'integer' : 'real';
|
|
9604
9324
|
next_child.ele(tag_type).txt(next.toString());
|
|
9605
9325
|
} 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(
|
|
9326
|
+
else if (next instanceof Date) next_child.ele('date').txt(new Date(next).toISOString().replace(/\.000Z$/, 'Z'));
|
|
9607
9327
|
else if ('boolean' == typeof next) next_child.ele(next ? 'true' : 'false');
|
|
9608
9328
|
else if ('string' == typeof next) next_child.ele('string').txt(next);
|
|
9609
9329
|
} else {
|
|
@@ -9718,6 +9438,7 @@ class Usbmux {
|
|
|
9718
9438
|
}
|
|
9719
9439
|
const ios_debug = ansi_createDebug("devtool-mcp-server:connector:ios");
|
|
9720
9440
|
class iOSTransport {
|
|
9441
|
+
id = "ios";
|
|
9721
9442
|
#client;
|
|
9722
9443
|
constructor(options){
|
|
9723
9444
|
this.#client = new Usbmux(options);
|
|
@@ -9765,4 +9486,4 @@ class iOSTransport {
|
|
|
9765
9486
|
throw new Error("Not implemented");
|
|
9766
9487
|
}
|
|
9767
9488
|
}
|
|
9768
|
-
export { AndroidTransport, DesktopTransport,
|
|
9489
|
+
export { AndroidTransport, DesktopTransport, PeertalkToMessageTransformStream, Usbmux, connectWithPeertalk, encodePeertalkMessage, iOSTransport };
|