@midscene/android-mcp 1.9.6-beta-20260615083255.0 → 1.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/20.js ADDED
@@ -0,0 +1,2753 @@
1
+ "use strict";
2
+ const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
3
+ return typeof document === 'undefined'
4
+ ? new (require('url'.replace('', '')).URL)('file:' + __filename).href
5
+ : (document.currentScript && document.currentScript.src) ||
6
+ new URL('main.js', document.baseURI).href;
7
+ })();
8
+ ;
9
+ exports.ids = ["20"];
10
+ exports.modules = {
11
+ "../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/index.js"(__unused_rspack___webpack_module__, __webpack_exports__, __webpack_require__) {
12
+
13
+ // EXPORTS
14
+ __webpack_require__.d(__webpack_exports__, {
15
+ Adb: () => (/* reexport */ Adb),
16
+ AdbServerClient: () => (/* reexport */ AdbServerClient)
17
+ });
18
+
19
+ // UNUSED EXPORTS: adbSyncPushV2, AdbSyncError, AdbNoneProtocolSpawner, ADB_DAEMON_DEFAULT_FEATURES, AdbBanner, ADB_DAEMON_VERSION_OMIT_CHECKSUM, AdbSync, adbSyncOpenDir, AdbBannerKey, AdbShellProtocolId, AdbShellProtocolSpawner, AdbDaemonSocketController, AdbSyncSendV2Flags, AdbShellProtocolPtyProcess, AdbSyncLstatResponse, AdbDaemonTransport, AdbReverseErrorResponse, AdbShellProtocolPacket, adbSyncLstat, encodeUtf8, AdbDaemonSocket, LinuxFileType, AdbFeature, calculateChecksum, dirname, adbSyncReadResponses, raceSignal, setBigUint, adbSyncPushV1, ADB_SERVER_DEFAULT_FEATURES, ADB_SYNC_MAX_PACKET_SIZE, AdbFrameBufferV1, AdbNoneProtocolSubprocessService, rsaParsePrivateKey, AdbShellProtocolSubprocessService, adbSyncEncodeId, AdbPublicKeyAuthenticator, FAIL, hexToNumber, unreachable, AdbPower, AdbSyncResponseId, AdbSyncDataResponse, AdbAuthType, adbSyncReadResponse, SHA1_DIGEST_INFO, AdbFrameBufferForbiddenError, AdbServerTransport, AdbServerStream, AdbAuthenticationProcessor, AdbReverseNotSupportedError, AdbReverseService, ASN1_OID, ASN1_OCTET_STRING, ASN1_NULL, rsaSign, AdbSubprocessService, ASN1_SEQUENCE, AdbSyncSocketLocked, AdbSyncFailResponse, AdbSyncStatErrorCode, adbSyncWriteRequest, adbGetPublicKeySize, decodeUtf8, AdbReverseError, AdbNoneProtocolProcessImpl, AdbServiceBase, adbSyncPullGenerator, NOOP, sequenceEqual, AdbSyncStatResponse, adbSyncPush, AdbPacketSerializeStream, AdbSignatureAuthenticator, AdbFrameBufferUnsupportedVersionError, Ref, ADB_DEFAULT_AUTHENTICATORS, AdbFrameBufferError, splitCommand, getBigUint, AdbFrameBufferV2, AdbSyncSocket, adbSyncStat, AdbSyncSendV2Request, unorderedRemove, AdbTcpIpService, SHA1_DIGEST_LENGTH, write4HexDigits, AdbSyncEntry2Response, decodeBase64, modInverse, adbGeneratePublicKey, AdbNoneProtocolPtyProcess, adbSyncOpenDirV1, AdbServerDeviceObserverOwner, AdbShellProtocolProcessImpl, AdbSyncEntryResponse, AutoResetEvent, adbSyncPull, encodeBase64, AdbSyncOkResponse, AdbPacketDispatcher, escapeArg, AdbPacket, AdbSyncRequestId, toLocalUint8Array, AdbSyncNumberRequest, powMod, framebuffer, adbSyncOpenDirV2, ADB_DAEMON_DEFAULT_INITIAL_PAYLOAD_SIZE, AdbPacketHeader, calculateBase64EncodedLength, AdbCommand
20
+
21
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/encoding.js
22
+ var encoding = __webpack_require__("../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/encoding.js");
23
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+async@4.1.3/node_modules/@yume-chan/async/esm/promise-resolver.js
24
+ var promise_resolver = __webpack_require__("../../node_modules/.pnpm/@yume-chan+async@4.1.3/node_modules/@yume-chan/async/esm/promise-resolver.js");
25
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/buffer.js
26
+ var esm_buffer = __webpack_require__("../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/buffer.js");
27
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/stream.js
28
+ var esm_stream = __webpack_require__("../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/stream.js");
29
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/concat.js
30
+
31
+
32
+
33
+ // `TransformStream` only calls its `source.flush` method when its `readable` is being read.
34
+ // If the user want to use the `Promise` interface, the `flush` method will never be called,
35
+ // so the `PromiseResolver` will never be resolved.
36
+ // Thus we need to implement our own `TransformStream` using a `WritableStream` and a `ReadableStream`.
37
+ /**
38
+ * A `TransformStream` that concatenates strings.
39
+ *
40
+ * Its `readable` is also a `Promise<string>`, so it's possible to `await` it to get the result.
41
+ *
42
+ * ```ts
43
+ * const result: string = await readable.pipeThrough(new ConcatStringStream());
44
+ * ```
45
+ */
46
+ class ConcatStringStream {
47
+ // PERF: rope (concat strings) is faster than `[].join('')`
48
+ #result = "";
49
+ #resolver = new promise_resolver/* .PromiseResolver */.O();
50
+ #writable = new esm_stream/* .WritableStream */.ho({
51
+ write: (chunk) => {
52
+ this.#result += chunk;
53
+ },
54
+ close: () => {
55
+ this.#resolver.resolve(this.#result);
56
+ this.#readableController.enqueue(this.#result);
57
+ this.#readableController.close();
58
+ },
59
+ abort: (reason) => {
60
+ this.#resolver.reject(reason);
61
+ this.#readableController.error(reason);
62
+ },
63
+ });
64
+ get writable() {
65
+ return this.#writable;
66
+ }
67
+ #readableController;
68
+ #readable = new esm_stream/* .ReadableStream */.ZY({
69
+ start: (controller) => {
70
+ this.#readableController = controller;
71
+ },
72
+ });
73
+ get readable() {
74
+ return this.#readable;
75
+ }
76
+ constructor() {
77
+ void Object.defineProperties(this.#readable, {
78
+ then: {
79
+ get: () => this.#resolver.promise.then.bind(this.#resolver.promise),
80
+ },
81
+ catch: {
82
+ get: () => this.#resolver.promise.catch.bind(this.#resolver.promise),
83
+ },
84
+ finally: {
85
+ get: () => this.#resolver.promise.finally.bind(this.#resolver.promise),
86
+ },
87
+ });
88
+ }
89
+ }
90
+ /**
91
+ * A `TransformStream` that concatenates `Uint8Array`s.
92
+ *
93
+ * If you want to decode the result as string,
94
+ * prefer `.pipeThrough(new TextDecoderStream()).pipeThrough(new ConcatStringStream())`,
95
+ * than `.pipeThough(new ConcatBufferStream()).pipeThrough(new TextDecoderStream())`,
96
+ * because of JavaScript engine optimizations,
97
+ * concatenating strings is faster than concatenating `Uint8Array`s.
98
+ */
99
+ class ConcatBufferStream {
100
+ #segments = [];
101
+ #resolver = new promise_resolver/* .PromiseResolver */.O();
102
+ #writable = new esm_stream/* .WritableStream */.ho({
103
+ write: (chunk) => {
104
+ this.#segments.push(chunk);
105
+ },
106
+ close: () => {
107
+ let result;
108
+ let offset = 0;
109
+ switch (this.#segments.length) {
110
+ case 0:
111
+ result = esm_buffer/* .EmptyUint8Array */.j;
112
+ break;
113
+ case 1:
114
+ result = this.#segments[0];
115
+ break;
116
+ default:
117
+ result = new Uint8Array(this.#segments.reduce((prev, item) => prev + item.length, 0));
118
+ for (const segment of this.#segments) {
119
+ result.set(segment, offset);
120
+ offset += segment.length;
121
+ }
122
+ break;
123
+ }
124
+ this.#resolver.resolve(result);
125
+ this.#readableController.enqueue(result);
126
+ this.#readableController.close();
127
+ },
128
+ abort: (reason) => {
129
+ this.#resolver.reject(reason);
130
+ this.#readableController.error(reason);
131
+ },
132
+ });
133
+ get writable() {
134
+ return this.#writable;
135
+ }
136
+ #readableController;
137
+ #readable = new esm_stream/* .ReadableStream */.ZY({
138
+ start: (controller) => {
139
+ this.#readableController = controller;
140
+ },
141
+ });
142
+ get readable() {
143
+ return this.#readable;
144
+ }
145
+ constructor() {
146
+ void Object.defineProperties(this.#readable, {
147
+ then: {
148
+ get: () => this.#resolver.promise.then.bind(this.#resolver.promise),
149
+ },
150
+ catch: {
151
+ get: () => this.#resolver.promise.catch.bind(this.#resolver.promise),
152
+ },
153
+ finally: {
154
+ get: () => this.#resolver.promise.finally.bind(this.#resolver.promise),
155
+ },
156
+ });
157
+ }
158
+ }
159
+ //# sourceMappingURL=concat.js.map
160
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/features.js
161
+ // The order follows
162
+ // https://cs.android.com/android/platform/superproject/+/master:packages/modules/adb/transport.cpp;l=77;drc=6d14d35d0241f6fee145f8e54ffd77252e8d29fd
163
+ const AdbFeature = {
164
+ ShellV2: "shell_v2",
165
+ Cmd: "cmd",
166
+ StatV2: "stat_v2",
167
+ ListV2: "ls_v2",
168
+ FixedPushMkdir: "fixed_push_mkdir",
169
+ Abb: "abb",
170
+ AbbExec: "abb_exec",
171
+ SendReceiveV2: "sendrecv_v2",
172
+ DelayedAck: "delayed_ack",
173
+ };
174
+ //# sourceMappingURL=features.js.map
175
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/subprocess/none/process.js
176
+
177
+ class AdbNoneProtocolProcessImpl {
178
+ #socket;
179
+ get stdin() {
180
+ return this.#socket.writable;
181
+ }
182
+ get output() {
183
+ return this.#socket.readable;
184
+ }
185
+ #exited;
186
+ get exited() {
187
+ return this.#exited;
188
+ }
189
+ constructor(socket, signal) {
190
+ this.#socket = socket;
191
+ if (signal) {
192
+ // `signal` won't affect `this.output`
193
+ // So remaining data can still be read
194
+ // (call `controller.error` will discard all pending data)
195
+ const exited = new promise_resolver/* .PromiseResolver */.O();
196
+ this.#socket.closed.then(() => exited.resolve(undefined), (e) => exited.reject(e));
197
+ signal.addEventListener("abort", () => {
198
+ exited.reject(signal.reason);
199
+ this.#socket.close();
200
+ });
201
+ this.#exited = exited.promise;
202
+ }
203
+ else {
204
+ this.#exited = this.#socket.closed;
205
+ }
206
+ }
207
+ kill() {
208
+ return this.#socket.close();
209
+ }
210
+ }
211
+ //# sourceMappingURL=process.js.map
212
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/maybe-consumable/writable.js
213
+ var maybe_consumable_writable = __webpack_require__("../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/maybe-consumable/writable.js");
214
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/subprocess/none/pty.js
215
+
216
+ class AdbNoneProtocolPtyProcess {
217
+ #socket;
218
+ #writer;
219
+ #input;
220
+ get input() {
221
+ return this.#input;
222
+ }
223
+ get output() {
224
+ return this.#socket.readable;
225
+ }
226
+ get exited() {
227
+ return this.#socket.closed;
228
+ }
229
+ constructor(socket) {
230
+ this.#socket = socket;
231
+ this.#writer = this.#socket.writable.getWriter();
232
+ this.#input = new maybe_consumable_writable/* .MaybeConsumableWritableStream */.g({
233
+ write: (chunk) => this.#writer.write(chunk),
234
+ });
235
+ }
236
+ sigint() {
237
+ return this.#writer.write(new Uint8Array([0x03]));
238
+ }
239
+ kill() {
240
+ return this.#socket.close();
241
+ }
242
+ }
243
+ //# sourceMappingURL=pty.js.map
244
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/subprocess/utils.js
245
+ function escapeArg(s) {
246
+ let result = "";
247
+ result += `'`;
248
+ let base = 0;
249
+ while (true) {
250
+ const found = s.indexOf(`'`, base);
251
+ if (found === -1) {
252
+ result += s.substring(base);
253
+ break;
254
+ }
255
+ result += s.substring(base, found);
256
+ // a'b becomes a'\'b (the backslash is not a escape character)
257
+ result += String.raw `'\''`;
258
+ base = found + 1;
259
+ }
260
+ result += `'`;
261
+ return result;
262
+ }
263
+ function splitCommand(command) {
264
+ const result = [];
265
+ let quote;
266
+ let isEscaped = false;
267
+ let start = 0;
268
+ for (let i = 0, len = command.length; i < len; i += 1) {
269
+ if (isEscaped) {
270
+ isEscaped = false;
271
+ continue;
272
+ }
273
+ const char = command.charAt(i);
274
+ switch (char) {
275
+ case " ":
276
+ if (!quote && i !== start) {
277
+ result.push(command.substring(start, i));
278
+ start = i + 1;
279
+ }
280
+ break;
281
+ case "'":
282
+ case '"':
283
+ if (!quote) {
284
+ quote = char;
285
+ }
286
+ else if (char === quote) {
287
+ quote = undefined;
288
+ }
289
+ break;
290
+ case "\\":
291
+ isEscaped = true;
292
+ break;
293
+ }
294
+ }
295
+ if (start < command.length) {
296
+ result.push(command.substring(start));
297
+ }
298
+ return result;
299
+ }
300
+ //# sourceMappingURL=utils.js.map
301
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/subprocess/none/spawner.js
302
+
303
+
304
+ class AdbNoneProtocolSpawner {
305
+ #spawn;
306
+ constructor(spawn) {
307
+ this.#spawn = spawn;
308
+ }
309
+ spawn(command, signal) {
310
+ signal?.throwIfAborted();
311
+ if (typeof command === "string") {
312
+ command = splitCommand(command);
313
+ }
314
+ return this.#spawn(command, signal);
315
+ }
316
+ async spawnWait(command) {
317
+ const process = await this.spawn(command);
318
+ return await process.output.pipeThrough(new ConcatBufferStream());
319
+ }
320
+ async spawnWaitText(command) {
321
+ const process = await this.spawn(command);
322
+ return await process.output
323
+ .pipeThrough(new encoding/* .TextDecoderStream */.W())
324
+ .pipeThrough(new ConcatStringStream());
325
+ }
326
+ }
327
+ //# sourceMappingURL=spawner.js.map
328
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/subprocess/none/service.js
329
+
330
+
331
+
332
+ class AdbNoneProtocolSubprocessService extends AdbNoneProtocolSpawner {
333
+ #adb;
334
+ get adb() {
335
+ return this.#adb;
336
+ }
337
+ constructor(adb) {
338
+ super(async (command, signal) => {
339
+ // `shell,raw:${command}` also triggers raw mode,
340
+ // But is not supported on Android version <7.
341
+ const socket = await this.#adb.createSocket(`exec:${command.join(" ")}`);
342
+ if (signal?.aborted) {
343
+ await socket.close();
344
+ throw signal.reason;
345
+ }
346
+ return new AdbNoneProtocolProcessImpl(socket, signal);
347
+ });
348
+ this.#adb = adb;
349
+ }
350
+ async pty(command) {
351
+ if (command === undefined) {
352
+ command = "";
353
+ }
354
+ else if (Array.isArray(command)) {
355
+ command = command.join(" ");
356
+ }
357
+ return new AdbNoneProtocolPtyProcess(
358
+ // https://github.com/microsoft/typescript/issues/17002
359
+ await this.#adb.createSocket(`shell:${command}`));
360
+ }
361
+ }
362
+ //# sourceMappingURL=service.js.map
363
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/push-readable.js
364
+ var push_readable = __webpack_require__("../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/push-readable.js");
365
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/struct-deserialize.js + 1 modules
366
+ var struct_deserialize = __webpack_require__("../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/struct-deserialize.js");
367
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/struct.js
368
+ var struct = __webpack_require__("../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/struct.js");
369
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/number.js + 3 modules
370
+ var number = __webpack_require__("../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/number.js");
371
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/subprocess/shell/shared.js
372
+
373
+ const AdbShellProtocolId = {
374
+ Stdin: 0,
375
+ Stdout: 1,
376
+ Stderr: 2,
377
+ Exit: 3,
378
+ CloseStdin: 4,
379
+ WindowSizeChange: 5,
380
+ };
381
+ // This packet format is used in both directions.
382
+ const AdbShellProtocolPacket = (0,struct/* .struct */.w3)({
383
+ id: (0,number.u8)(),
384
+ data: (0,esm_buffer/* .buffer */.r)(number/* .u32 */.DH),
385
+ }, { littleEndian: true });
386
+ //# sourceMappingURL=shared.js.map
387
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/subprocess/shell/process.js
388
+
389
+
390
+
391
+
392
+ class AdbShellProtocolProcessImpl {
393
+ #socket;
394
+ #writer;
395
+ #stdin;
396
+ get stdin() {
397
+ return this.#stdin;
398
+ }
399
+ #stdout;
400
+ get stdout() {
401
+ return this.#stdout;
402
+ }
403
+ #stderr;
404
+ get stderr() {
405
+ return this.#stderr;
406
+ }
407
+ #exited;
408
+ get exited() {
409
+ return this.#exited;
410
+ }
411
+ constructor(socket, signal) {
412
+ this.#socket = socket;
413
+ let stdoutController;
414
+ let stderrController;
415
+ this.#stdout = new push_readable/* .PushReadableStream */.F((controller) => {
416
+ stdoutController = controller;
417
+ });
418
+ this.#stderr = new push_readable/* .PushReadableStream */.F((controller) => {
419
+ stderrController = controller;
420
+ });
421
+ const exited = new promise_resolver/* .PromiseResolver */.O();
422
+ this.#exited = exited.promise;
423
+ socket.readable
424
+ .pipeThrough(new struct_deserialize/* .StructDeserializeStream */.f(AdbShellProtocolPacket))
425
+ .pipeTo(new esm_stream/* .WritableStream */.ho({
426
+ write: async (chunk) => {
427
+ switch (chunk.id) {
428
+ case AdbShellProtocolId.Exit:
429
+ exited.resolve(chunk.data[0]);
430
+ break;
431
+ case AdbShellProtocolId.Stdout:
432
+ await stdoutController.enqueue(chunk.data);
433
+ break;
434
+ case AdbShellProtocolId.Stderr:
435
+ await stderrController.enqueue(chunk.data);
436
+ break;
437
+ default:
438
+ // Ignore unknown messages like Google ADB does
439
+ // https://cs.android.com/android/platform/superproject/main/+/main:packages/modules/adb/daemon/shell_service.cpp;l=684;drc=61197364367c9e404c7da6900658f1b16c42d0da
440
+ break;
441
+ }
442
+ },
443
+ }))
444
+ .then(() => {
445
+ stdoutController.close();
446
+ stderrController.close();
447
+ // If `exited` has already settled, this will be a no-op
448
+ exited.reject(new Error("Socket ended without exit message"));
449
+ }, (e) => {
450
+ stdoutController.error(e);
451
+ stderrController.error(e);
452
+ // If `exited` has already settled, this will be a no-op
453
+ exited.reject(e);
454
+ });
455
+ if (signal) {
456
+ // `signal` won't affect `this.stdout` and `this.stderr`
457
+ // So remaining data can still be read
458
+ // (call `controller.error` will discard all pending data)
459
+ signal.addEventListener("abort", () => {
460
+ exited.reject(signal.reason);
461
+ this.#socket.close();
462
+ });
463
+ }
464
+ this.#writer = this.#socket.writable.getWriter();
465
+ this.#stdin = new maybe_consumable_writable/* .MaybeConsumableWritableStream */.g({
466
+ write: async (chunk) => {
467
+ await this.#writer.write(AdbShellProtocolPacket.serialize({
468
+ id: AdbShellProtocolId.Stdin,
469
+ data: chunk,
470
+ }));
471
+ },
472
+ close: () =>
473
+ // Only shell protocol + raw mode supports closing stdin
474
+ this.#writer.write(AdbShellProtocolPacket.serialize({
475
+ id: AdbShellProtocolId.CloseStdin,
476
+ data: esm_buffer/* .EmptyUint8Array */.j,
477
+ })),
478
+ });
479
+ }
480
+ kill() {
481
+ return this.#socket.close();
482
+ }
483
+ }
484
+ //# sourceMappingURL=process.js.map
485
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/utils.js
486
+ var utils = __webpack_require__("../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/utils.js");
487
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/subprocess/shell/pty.js
488
+
489
+
490
+
491
+
492
+ class AdbShellProtocolPtyProcess {
493
+ #socket;
494
+ #writer;
495
+ #input;
496
+ get input() {
497
+ return this.#input;
498
+ }
499
+ #stdout;
500
+ get output() {
501
+ return this.#stdout;
502
+ }
503
+ #exited = new promise_resolver/* .PromiseResolver */.O();
504
+ get exited() {
505
+ return this.#exited.promise;
506
+ }
507
+ constructor(socket) {
508
+ this.#socket = socket;
509
+ let stdoutController;
510
+ this.#stdout = new push_readable/* .PushReadableStream */.F((controller) => {
511
+ stdoutController = controller;
512
+ });
513
+ socket.readable
514
+ .pipeThrough(new struct_deserialize/* .StructDeserializeStream */.f(AdbShellProtocolPacket))
515
+ .pipeTo(new esm_stream/* .WritableStream */.ho({
516
+ write: async (chunk) => {
517
+ switch (chunk.id) {
518
+ case AdbShellProtocolId.Exit:
519
+ this.#exited.resolve(chunk.data[0]);
520
+ break;
521
+ case AdbShellProtocolId.Stdout:
522
+ await stdoutController.enqueue(chunk.data);
523
+ break;
524
+ }
525
+ },
526
+ }))
527
+ .then(() => {
528
+ stdoutController.close();
529
+ // If `#exit` has already resolved, this will be a no-op
530
+ this.#exited.reject(new Error("Socket ended without exit message"));
531
+ }, (e) => {
532
+ stdoutController.error(e);
533
+ // If `#exit` has already resolved, this will be a no-op
534
+ this.#exited.reject(e);
535
+ });
536
+ this.#writer = this.#socket.writable.getWriter();
537
+ this.#input = new maybe_consumable_writable/* .MaybeConsumableWritableStream */.g({
538
+ write: (chunk) => this.#writeStdin(chunk),
539
+ });
540
+ }
541
+ #writeStdin(chunk) {
542
+ return this.#writer.write(AdbShellProtocolPacket.serialize({
543
+ id: AdbShellProtocolId.Stdin,
544
+ data: chunk,
545
+ }));
546
+ }
547
+ async resize(rows, cols) {
548
+ await this.#writer.write(AdbShellProtocolPacket.serialize({
549
+ id: AdbShellProtocolId.WindowSizeChange,
550
+ // The "correct" format is `${rows}x${cols},${x_pixels}x${y_pixels}`
551
+ // However, according to https://linux.die.net/man/4/tty_ioctl
552
+ // `x_pixels` and `y_pixels` are unused, so always sending `0` should be fine.
553
+ data: (0,utils/* .encodeUtf8 */.Af)(`${rows}x${cols},0x0\0`),
554
+ }));
555
+ }
556
+ sigint() {
557
+ return this.#writeStdin(new Uint8Array([0x03]));
558
+ }
559
+ kill() {
560
+ return this.#socket.close();
561
+ }
562
+ }
563
+ //# sourceMappingURL=pty.js.map
564
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/subprocess/shell/spawner.js
565
+
566
+
567
+ class AdbShellProtocolSpawner {
568
+ #spawn;
569
+ constructor(spawn) {
570
+ this.#spawn = spawn;
571
+ }
572
+ spawn(command, signal) {
573
+ signal?.throwIfAborted();
574
+ if (typeof command === "string") {
575
+ command = splitCommand(command);
576
+ }
577
+ return this.#spawn(command, signal);
578
+ }
579
+ async spawnWait(command) {
580
+ const process = await this.spawn(command);
581
+ const [stdout, stderr, exitCode] = await Promise.all([
582
+ process.stdout.pipeThrough(new ConcatBufferStream()),
583
+ process.stderr.pipeThrough(new ConcatBufferStream()),
584
+ process.exited,
585
+ ]);
586
+ return { stdout, stderr, exitCode };
587
+ }
588
+ async spawnWaitText(command) {
589
+ const process = await this.spawn(command);
590
+ const [stdout, stderr, exitCode] = await Promise.all([
591
+ process.stdout
592
+ .pipeThrough(new encoding/* .TextDecoderStream */.W())
593
+ .pipeThrough(new ConcatStringStream()),
594
+ process.stderr
595
+ .pipeThrough(new encoding/* .TextDecoderStream */.W())
596
+ .pipeThrough(new ConcatStringStream()),
597
+ process.exited,
598
+ ]);
599
+ return { stdout, stderr, exitCode };
600
+ }
601
+ }
602
+ //# sourceMappingURL=spawner.js.map
603
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/subprocess/shell/service.js
604
+
605
+
606
+
607
+
608
+ class AdbShellProtocolSubprocessService extends AdbShellProtocolSpawner {
609
+ #adb;
610
+ get adb() {
611
+ return this.#adb;
612
+ }
613
+ get isSupported() {
614
+ return this.#adb.canUseFeature(AdbFeature.ShellV2);
615
+ }
616
+ constructor(adb) {
617
+ super(async (command, signal) => {
618
+ const socket = await this.#adb.createSocket(`shell,v2,raw:${command.join(" ")}`);
619
+ if (signal?.aborted) {
620
+ await socket.close();
621
+ throw signal.reason;
622
+ }
623
+ return new AdbShellProtocolProcessImpl(socket, signal);
624
+ });
625
+ this.#adb = adb;
626
+ }
627
+ async pty(options) {
628
+ let service = "shell,v2,pty";
629
+ if (options?.terminalType) {
630
+ service += `,TERM=` + options.terminalType;
631
+ }
632
+ service += ":";
633
+ if (options) {
634
+ if (typeof options.command === "string") {
635
+ service += options.command;
636
+ }
637
+ else if (Array.isArray(options.command)) {
638
+ service += options.command.join(" ");
639
+ }
640
+ }
641
+ return new AdbShellProtocolPtyProcess(await this.#adb.createSocket(service));
642
+ }
643
+ }
644
+ //# sourceMappingURL=service.js.map
645
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/subprocess/service.js
646
+
647
+
648
+
649
+ class AdbSubprocessService {
650
+ #adb;
651
+ get adb() {
652
+ return this.#adb;
653
+ }
654
+ #noneProtocol;
655
+ get noneProtocol() {
656
+ return this.#noneProtocol;
657
+ }
658
+ #shellProtocol;
659
+ get shellProtocol() {
660
+ return this.#shellProtocol;
661
+ }
662
+ constructor(adb) {
663
+ this.#adb = adb;
664
+ this.#noneProtocol = new AdbNoneProtocolSubprocessService(adb);
665
+ if (adb.canUseFeature(AdbFeature.ShellV2)) {
666
+ this.#shellProtocol = new AdbShellProtocolSubprocessService(adb);
667
+ }
668
+ }
669
+ }
670
+ //# sourceMappingURL=service.js.map
671
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/base.js + 1 modules
672
+ var commands_base = __webpack_require__("../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/base.js");
673
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/power.js
674
+ // cspell: ignore bootloader
675
+ // cspell: ignore fastboot
676
+ // cspell: ignore keyevent
677
+ // cspell: ignore longpress
678
+
679
+ class AdbPower extends commands_base/* .AdbServiceBase */.Y {
680
+ reboot(mode = "") {
681
+ return this.adb.createSocketAndWait(`reboot:${mode}`);
682
+ }
683
+ bootloader() {
684
+ return this.reboot("bootloader");
685
+ }
686
+ fastboot() {
687
+ return this.reboot("fastboot");
688
+ }
689
+ recovery() {
690
+ return this.reboot("recovery");
691
+ }
692
+ sideload() {
693
+ return this.reboot("sideload");
694
+ }
695
+ /**
696
+ * Reboot to Qualcomm Emergency Download (EDL) Mode.
697
+ *
698
+ * Only works on some Qualcomm devices.
699
+ */
700
+ qualcommEdlMode() {
701
+ return this.reboot("edl");
702
+ }
703
+ powerOff() {
704
+ return this.adb.subprocess.noneProtocol.spawnWaitText(["reboot", "-p"]);
705
+ }
706
+ powerButton(longPress = false) {
707
+ const args = ["input", "keyevent"];
708
+ if (longPress) {
709
+ args.push("--longpress");
710
+ }
711
+ args.push("POWER");
712
+ return this.adb.subprocess.noneProtocol.spawnWaitText(args);
713
+ }
714
+ /**
715
+ * Reboot to Samsung Odin download mode.
716
+ *
717
+ * Only works on Samsung devices.
718
+ */
719
+ samsungOdin() {
720
+ return this.reboot("download");
721
+ }
722
+ }
723
+ //# sourceMappingURL=power.js.map
724
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/reverse.js
725
+ var reverse = __webpack_require__("../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/reverse.js");
726
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/tcpip.js
727
+
728
+ function parsePort(value) {
729
+ if (!value || value === "0") {
730
+ return undefined;
731
+ }
732
+ return Number.parseInt(value, 10);
733
+ }
734
+ class AdbTcpIpService extends commands_base/* .AdbServiceBase */.Y {
735
+ async getListenAddresses() {
736
+ const serviceListenAddresses = await this.adb.getProp("service.adb.listen_addrs");
737
+ const servicePort = await this.adb.getProp("service.adb.tcp.port");
738
+ const persistPort = await this.adb.getProp("persist.adb.tcp.port");
739
+ return {
740
+ serviceListenAddresses: serviceListenAddresses != ""
741
+ ? serviceListenAddresses.split(",")
742
+ : [],
743
+ servicePort: parsePort(servicePort),
744
+ persistPort: parsePort(persistPort),
745
+ };
746
+ }
747
+ async setPort(port) {
748
+ if (port <= 0) {
749
+ throw new TypeError(`Invalid port ${port}`);
750
+ }
751
+ const output = await this.adb.createSocketAndWait(`tcpip:${port}`);
752
+ if (output !== `restarting in TCP mode port: ${port}\n`) {
753
+ throw new Error(output);
754
+ }
755
+ return output;
756
+ }
757
+ async disable() {
758
+ const output = await this.adb.createSocketAndWait("usb:");
759
+ if (output !== "restarting in USB mode\n") {
760
+ throw new Error(output);
761
+ }
762
+ return output;
763
+ }
764
+ }
765
+ //# sourceMappingURL=tcpip.js.map
766
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/extend.js
767
+ var extend = __webpack_require__("../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/extend.js");
768
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/string.js
769
+ var string = __webpack_require__("../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/string.js");
770
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+no-data-view@2.0.0/node_modules/@yume-chan/no-data-view/esm/uint32.js
771
+ var uint32 = __webpack_require__("../../node_modules/.pnpm/@yume-chan+no-data-view@2.0.0/node_modules/@yume-chan/no-data-view/esm/uint32.js");
772
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/utils/no-op.js
773
+ var no_op = __webpack_require__("../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/utils/no-op.js");
774
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/sync/response.js
775
+
776
+
777
+
778
+ function encodeAsciiUnchecked(value) {
779
+ const result = new Uint8Array(value.length);
780
+ for (let i = 0; i < value.length; i += 1) {
781
+ result[i] = value.charCodeAt(i);
782
+ }
783
+ return result;
784
+ }
785
+ /**
786
+ * Encode ID to numbers for faster comparison
787
+ * @param value A 4-character string
788
+ * @returns A 32-bit integer by encoding the string as little-endian
789
+ *
790
+ * #__NO_SIDE_EFFECTS__
791
+ */
792
+ function adbSyncEncodeId(value) {
793
+ const buffer = encodeAsciiUnchecked(value);
794
+ return (0,uint32/* .getUint32LittleEndian */.FQ)(buffer, 0);
795
+ }
796
+ const AdbSyncResponseId = {
797
+ Entry: adbSyncEncodeId("DENT"),
798
+ Entry2: adbSyncEncodeId("DNT2"),
799
+ Lstat: adbSyncEncodeId("STAT"),
800
+ Stat: adbSyncEncodeId("STA2"),
801
+ Lstat2: adbSyncEncodeId("LST2"),
802
+ Done: adbSyncEncodeId("DONE"),
803
+ Data: adbSyncEncodeId("DATA"),
804
+ Ok: adbSyncEncodeId("OKAY"),
805
+ Fail: adbSyncEncodeId("FAIL"),
806
+ };
807
+ class AdbSyncError extends Error {
808
+ }
809
+ const AdbSyncFailResponse = (0,struct/* .struct */.w3)({ message: (0,string/* .string */.Y)(number/* .u32 */.DH) }, {
810
+ littleEndian: true,
811
+ postDeserialize(value) {
812
+ throw new AdbSyncError(value.message);
813
+ },
814
+ });
815
+ async function adbSyncReadResponse(stream, id, type) {
816
+ if (typeof id === "string") {
817
+ id = adbSyncEncodeId(id);
818
+ }
819
+ const buffer = await stream.readExactly(4);
820
+ switch ((0,uint32/* .getUint32LittleEndian */.FQ)(buffer, 0)) {
821
+ case AdbSyncResponseId.Fail:
822
+ await AdbSyncFailResponse.deserialize(stream);
823
+ throw new Error("Unreachable");
824
+ case id:
825
+ return await type.deserialize(stream);
826
+ default:
827
+ throw new Error(`Expected '${id}', but got '${(0,utils/* .decodeUtf8 */._6)(buffer)}'`);
828
+ }
829
+ }
830
+ async function* adbSyncReadResponses(stream, id, type) {
831
+ if (typeof id === "string") {
832
+ id = adbSyncEncodeId(id);
833
+ }
834
+ while (true) {
835
+ const buffer = await stream.readExactly(4);
836
+ switch ((0,uint32/* .getUint32LittleEndian */.FQ)(buffer, 0)) {
837
+ case AdbSyncResponseId.Fail:
838
+ await AdbSyncFailResponse.deserialize(stream);
839
+ (0,no_op/* .unreachable */.H)();
840
+ case AdbSyncResponseId.Done:
841
+ // `DONE` responses' size are always same as the request's normal response.
842
+ //
843
+ // For example, `DONE` responses for `LIST` requests are 16 bytes (same as `DENT` responses),
844
+ // but `DONE` responses for `STAT` requests are 12 bytes (same as `STAT` responses).
845
+ await stream.readExactly(type.size);
846
+ return;
847
+ case id:
848
+ yield await type.deserialize(stream);
849
+ break;
850
+ default:
851
+ throw new Error(`Expected '${id}' or '${AdbSyncResponseId.Done}', but got '${(0,utils/* .decodeUtf8 */._6)(buffer)}'`);
852
+ }
853
+ }
854
+ }
855
+ //# sourceMappingURL=response.js.map
856
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/sync/request.js
857
+
858
+
859
+ const AdbSyncRequestId = {
860
+ List: adbSyncEncodeId("LIST"),
861
+ ListV2: adbSyncEncodeId("LIS2"),
862
+ Send: adbSyncEncodeId("SEND"),
863
+ SendV2: adbSyncEncodeId("SND2"),
864
+ Lstat: adbSyncEncodeId("STAT"),
865
+ Stat: adbSyncEncodeId("STA2"),
866
+ LstatV2: adbSyncEncodeId("LST2"),
867
+ Data: adbSyncEncodeId("DATA"),
868
+ Done: adbSyncEncodeId("DONE"),
869
+ Receive: adbSyncEncodeId("RECV"),
870
+ };
871
+ const AdbSyncNumberRequest = (0,struct/* .struct */.w3)({ id: number/* .u32 */.DH, arg: number/* .u32 */.DH }, { littleEndian: true });
872
+ async function adbSyncWriteRequest(writable, id, value) {
873
+ if (typeof id === "string") {
874
+ id = adbSyncEncodeId(id);
875
+ }
876
+ if (typeof value === "number") {
877
+ await writable.write(AdbSyncNumberRequest.serialize({ id, arg: value }));
878
+ return;
879
+ }
880
+ if (typeof value === "string") {
881
+ value = (0,utils/* .encodeUtf8 */.Af)(value);
882
+ }
883
+ // `writable` is buffered, it copies inputs to an internal buffer,
884
+ // so don't concatenate headers and data here, that will be an unnecessary copy.
885
+ await writable.write(AdbSyncNumberRequest.serialize({ id, arg: value.length }));
886
+ await writable.write(value);
887
+ }
888
+ //# sourceMappingURL=request.js.map
889
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/sync/stat.js
890
+
891
+
892
+
893
+ // https://github.com/python/cpython/blob/4e581d64b8aff3e2eda99b12f080c877bb78dfca/Lib/stat.py#L36
894
+ const LinuxFileType = {
895
+ Directory: 0o04,
896
+ File: 0o10,
897
+ Link: 0o12,
898
+ };
899
+ const AdbSyncLstatResponse = (0,struct/* .struct */.w3)({ mode: number/* .u32 */.DH, size: number/* .u32 */.DH, mtime: number/* .u32 */.DH }, {
900
+ littleEndian: true,
901
+ extra: {
902
+ get type() {
903
+ return (this.mode >> 12);
904
+ },
905
+ get permission() {
906
+ return this.mode & 0b00001111_11111111;
907
+ },
908
+ },
909
+ postDeserialize(value) {
910
+ if (value.mode === 0 && value.size === 0 && value.mtime === 0) {
911
+ throw new Error("lstat error");
912
+ }
913
+ return value;
914
+ },
915
+ });
916
+ const AdbSyncStatErrorCode = {
917
+ SUCCESS: 0,
918
+ EACCES: 13,
919
+ EEXIST: 17,
920
+ EFAULT: 14,
921
+ EFBIG: 27,
922
+ EINTR: 4,
923
+ EINVAL: 22,
924
+ EIO: 5,
925
+ EISDIR: 21,
926
+ ELOOP: 40,
927
+ EMFILE: 24,
928
+ ENAMETOOLONG: 36,
929
+ ENFILE: 23,
930
+ ENOENT: 2,
931
+ ENOMEM: 12,
932
+ ENOSPC: 28,
933
+ ENOTDIR: 20,
934
+ EOVERFLOW: 75,
935
+ EPERM: 1,
936
+ EROFS: 30,
937
+ ETXTBSY: 26,
938
+ };
939
+ const AdbSyncStatErrorName = /* #__PURE__ */ (() => Object.fromEntries(Object.entries(AdbSyncStatErrorCode).map(([key, value]) => [
940
+ value,
941
+ key,
942
+ ])))();
943
+ const AdbSyncStatResponse = (0,struct/* .struct */.w3)({
944
+ error: (0,number/* .u32 */.DH)(),
945
+ dev: number/* .u64 */._l,
946
+ ino: number/* .u64 */._l,
947
+ mode: number/* .u32 */.DH,
948
+ nlink: number/* .u32 */.DH,
949
+ uid: number/* .u32 */.DH,
950
+ gid: number/* .u32 */.DH,
951
+ size: number/* .u64 */._l,
952
+ atime: number/* .u64 */._l,
953
+ mtime: number/* .u64 */._l,
954
+ ctime: number/* .u64 */._l,
955
+ }, {
956
+ littleEndian: true,
957
+ extra: {
958
+ get type() {
959
+ return (this.mode >> 12);
960
+ },
961
+ get permission() {
962
+ return this.mode & 0b00001111_11111111;
963
+ },
964
+ },
965
+ postDeserialize(value) {
966
+ if (value.error) {
967
+ throw new Error(AdbSyncStatErrorName[value.error]);
968
+ }
969
+ return value;
970
+ },
971
+ });
972
+ async function adbSyncLstat(socket, path, v2) {
973
+ const locked = await socket.lock();
974
+ try {
975
+ if (v2) {
976
+ await adbSyncWriteRequest(locked, AdbSyncRequestId.LstatV2, path);
977
+ return await adbSyncReadResponse(locked, AdbSyncResponseId.Lstat2, AdbSyncStatResponse);
978
+ }
979
+ else {
980
+ await adbSyncWriteRequest(locked, AdbSyncRequestId.Lstat, path);
981
+ const response = await adbSyncReadResponse(locked, AdbSyncResponseId.Lstat, AdbSyncLstatResponse);
982
+ return {
983
+ mode: response.mode,
984
+ // Convert to `BigInt` to make it compatible with `AdbSyncStatResponse`
985
+ size: BigInt(response.size),
986
+ mtime: BigInt(response.mtime),
987
+ get type() {
988
+ return response.type;
989
+ },
990
+ get permission() {
991
+ return response.permission;
992
+ },
993
+ };
994
+ }
995
+ }
996
+ finally {
997
+ locked.release();
998
+ }
999
+ }
1000
+ async function adbSyncStat(socket, path) {
1001
+ const locked = await socket.lock();
1002
+ try {
1003
+ await adbSyncWriteRequest(locked, AdbSyncRequestId.Stat, path);
1004
+ return await adbSyncReadResponse(locked, AdbSyncResponseId.Stat, AdbSyncStatResponse);
1005
+ }
1006
+ finally {
1007
+ locked.release();
1008
+ }
1009
+ }
1010
+ //# sourceMappingURL=stat.js.map
1011
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/sync/list.js
1012
+
1013
+
1014
+
1015
+
1016
+ const AdbSyncEntryResponse = (0,extend/* .extend */.X)(AdbSyncLstatResponse, {
1017
+ name: (0,string/* .string */.Y)(number/* .u32 */.DH),
1018
+ });
1019
+ const AdbSyncEntry2Response = (0,extend/* .extend */.X)(AdbSyncStatResponse, {
1020
+ name: (0,string/* .string */.Y)(number/* .u32 */.DH),
1021
+ });
1022
+ async function* adbSyncOpenDirV2(socket, path) {
1023
+ const locked = await socket.lock();
1024
+ try {
1025
+ await adbSyncWriteRequest(locked, AdbSyncRequestId.ListV2, path);
1026
+ for await (const item of adbSyncReadResponses(locked, AdbSyncResponseId.Entry2, AdbSyncEntry2Response)) {
1027
+ // `LST2` can return error codes for failed `lstat` calls.
1028
+ // `LIST` just ignores them.
1029
+ // But they only contain `name` so still pretty useless.
1030
+ if (item.error !== AdbSyncStatErrorCode.SUCCESS) {
1031
+ continue;
1032
+ }
1033
+ yield item;
1034
+ }
1035
+ }
1036
+ finally {
1037
+ locked.release();
1038
+ }
1039
+ }
1040
+ async function* adbSyncOpenDirV1(socket, path) {
1041
+ const locked = await socket.lock();
1042
+ try {
1043
+ await adbSyncWriteRequest(locked, AdbSyncRequestId.List, path);
1044
+ for await (const item of adbSyncReadResponses(locked, AdbSyncResponseId.Entry, AdbSyncEntryResponse)) {
1045
+ yield item;
1046
+ }
1047
+ }
1048
+ finally {
1049
+ locked.release();
1050
+ }
1051
+ }
1052
+ async function* adbSyncOpenDir(socket, path, v2) {
1053
+ if (v2) {
1054
+ yield* adbSyncOpenDirV2(socket, path);
1055
+ }
1056
+ else {
1057
+ for await (const item of adbSyncOpenDirV1(socket, path)) {
1058
+ // Convert to same format as `AdbSyncEntry2Response` for easier consumption.
1059
+ // However it will add some overhead.
1060
+ yield {
1061
+ mode: item.mode,
1062
+ size: BigInt(item.size),
1063
+ mtime: BigInt(item.mtime),
1064
+ get type() {
1065
+ return item.type;
1066
+ },
1067
+ get permission() {
1068
+ return item.permission;
1069
+ },
1070
+ name: item.name,
1071
+ };
1072
+ }
1073
+ }
1074
+ }
1075
+ //# sourceMappingURL=list.js.map
1076
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/sync/pull.js
1077
+
1078
+
1079
+
1080
+
1081
+ const AdbSyncDataResponse = (0,struct/* .struct */.w3)({ data: (0,esm_buffer/* .buffer */.r)(number/* .u32 */.DH) }, { littleEndian: true });
1082
+ async function* adbSyncPullGenerator(socket, path) {
1083
+ const locked = await socket.lock();
1084
+ let done = false;
1085
+ try {
1086
+ await adbSyncWriteRequest(locked, AdbSyncRequestId.Receive, path);
1087
+ for await (const packet of adbSyncReadResponses(locked, AdbSyncResponseId.Data, AdbSyncDataResponse)) {
1088
+ yield packet.data;
1089
+ }
1090
+ done = true;
1091
+ }
1092
+ catch (e) {
1093
+ done = true;
1094
+ throw e;
1095
+ }
1096
+ finally {
1097
+ if (!done) {
1098
+ // sync pull can't be cancelled, so we have to read all data
1099
+ for await (const packet of adbSyncReadResponses(locked, AdbSyncResponseId.Data, AdbSyncDataResponse)) {
1100
+ void packet;
1101
+ }
1102
+ }
1103
+ locked.release();
1104
+ }
1105
+ }
1106
+ function adbSyncPull(socket, path) {
1107
+ return esm_stream/* .ReadableStream.from */.ZY.from(adbSyncPullGenerator(socket, path));
1108
+ }
1109
+ //# sourceMappingURL=pull.js.map
1110
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/consumable.js + 5 modules
1111
+ var consumable = __webpack_require__("../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/consumable.js");
1112
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/maybe-consumable/utils.js
1113
+ var maybe_consumable_utils = __webpack_require__("../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/maybe-consumable/utils.js");
1114
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/distribution.js
1115
+
1116
+
1117
+
1118
+ /**
1119
+ * Splits or combines buffers to specified size.
1120
+ */
1121
+ class BufferCombiner {
1122
+ #capacity;
1123
+ #buffer;
1124
+ #offset;
1125
+ #available;
1126
+ constructor(size) {
1127
+ this.#capacity = size;
1128
+ this.#buffer = new Uint8Array(size);
1129
+ this.#offset = 0;
1130
+ this.#available = size;
1131
+ }
1132
+ /**
1133
+ * Pushes data to the combiner.
1134
+ * @param data The input data to be split or combined.
1135
+ * @returns
1136
+ * A generator that yields buffers of specified size.
1137
+ * It may yield the same buffer multiple times, consume the data before calling `next`.
1138
+ */
1139
+ *push(data) {
1140
+ let offset = 0;
1141
+ let available = data.length;
1142
+ if (this.#offset !== 0) {
1143
+ if (available >= this.#available) {
1144
+ this.#buffer.set(data.subarray(0, this.#available), this.#offset);
1145
+ offset += this.#available;
1146
+ available -= this.#available;
1147
+ yield this.#buffer;
1148
+ this.#offset = 0;
1149
+ this.#available = this.#capacity;
1150
+ if (available === 0) {
1151
+ return;
1152
+ }
1153
+ }
1154
+ else {
1155
+ this.#buffer.set(data, this.#offset);
1156
+ this.#offset += available;
1157
+ this.#available -= available;
1158
+ return;
1159
+ }
1160
+ }
1161
+ while (available >= this.#capacity) {
1162
+ const end = offset + this.#capacity;
1163
+ yield data.subarray(offset, end);
1164
+ offset = end;
1165
+ available -= this.#capacity;
1166
+ }
1167
+ if (available > 0) {
1168
+ this.#buffer.set(data.subarray(offset), this.#offset);
1169
+ this.#offset += available;
1170
+ this.#available -= available;
1171
+ }
1172
+ }
1173
+ flush() {
1174
+ if (this.#offset === 0) {
1175
+ return undefined;
1176
+ }
1177
+ const output = this.#buffer.subarray(0, this.#offset);
1178
+ this.#offset = 0;
1179
+ this.#available = this.#capacity;
1180
+ return output;
1181
+ }
1182
+ }
1183
+ class DistributionStream extends esm_stream/* .TransformStream */.Rv {
1184
+ constructor(size, combine = false) {
1185
+ const combiner = combine ? new BufferCombiner(size) : undefined;
1186
+ super({
1187
+ async transform(chunk, controller) {
1188
+ await maybe_consumable_utils/* .tryConsume */.W(chunk, async (chunk) => {
1189
+ if (combiner) {
1190
+ for (const buffer of combiner.push(chunk)) {
1191
+ await consumable/* .Consumable.ReadableStream.enqueue */.G.ReadableStream.enqueue(controller, buffer);
1192
+ }
1193
+ }
1194
+ else {
1195
+ let offset = 0;
1196
+ let available = chunk.length;
1197
+ while (available > 0) {
1198
+ const end = offset + size;
1199
+ await consumable/* .Consumable.ReadableStream.enqueue */.G.ReadableStream.enqueue(controller, chunk.subarray(offset, end));
1200
+ offset = end;
1201
+ available -= size;
1202
+ }
1203
+ }
1204
+ });
1205
+ },
1206
+ flush(controller) {
1207
+ if (combiner) {
1208
+ const data = combiner.flush();
1209
+ if (data) {
1210
+ controller.enqueue(data);
1211
+ }
1212
+ }
1213
+ },
1214
+ });
1215
+ }
1216
+ }
1217
+ //# sourceMappingURL=distribution.js.map
1218
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/sync/push.js
1219
+
1220
+
1221
+
1222
+
1223
+
1224
+
1225
+ const ADB_SYNC_MAX_PACKET_SIZE = 64 * 1024;
1226
+ const AdbSyncOkResponse = (0,struct/* .struct */.w3)({ unused: number/* .u32 */.DH }, { littleEndian: true });
1227
+ async function pipeFileData(locked, file, packetSize, mtime) {
1228
+ // Read and write in parallel,
1229
+ // allow error response to abort the write.
1230
+ const abortController = new esm_stream/* .AbortController */.z1();
1231
+ file.pipeThrough(new DistributionStream(packetSize, true))
1232
+ .pipeTo(new maybe_consumable_writable/* .MaybeConsumableWritableStream */.g({
1233
+ write(chunk) {
1234
+ return adbSyncWriteRequest(locked, AdbSyncRequestId.Data, chunk);
1235
+ },
1236
+ }), { signal: abortController.signal })
1237
+ .then(async () => {
1238
+ await adbSyncWriteRequest(locked, AdbSyncRequestId.Done, mtime);
1239
+ await locked.flush();
1240
+ }, no_op/* .NOOP */.t);
1241
+ await adbSyncReadResponse(locked, AdbSyncResponseId.Ok, AdbSyncOkResponse).catch((e) => {
1242
+ abortController.abort();
1243
+ throw e;
1244
+ });
1245
+ }
1246
+ async function adbSyncPushV1({ socket, filename, file, type = LinuxFileType.File, permission = 0o666, mtime = (Date.now() / 1000) | 0, packetSize = ADB_SYNC_MAX_PACKET_SIZE, }) {
1247
+ const locked = await socket.lock();
1248
+ try {
1249
+ const mode = (type << 12) | permission;
1250
+ const pathAndMode = `${filename},${mode.toString()}`;
1251
+ await adbSyncWriteRequest(locked, AdbSyncRequestId.Send, pathAndMode);
1252
+ await pipeFileData(locked, file, packetSize, mtime);
1253
+ }
1254
+ finally {
1255
+ locked.release();
1256
+ }
1257
+ }
1258
+ const AdbSyncSendV2Flags = {
1259
+ None: 0,
1260
+ Brotli: 1,
1261
+ /**
1262
+ * 2
1263
+ */
1264
+ Lz4: 1 << 1,
1265
+ /**
1266
+ * 4
1267
+ */
1268
+ Zstd: 1 << 2,
1269
+ DryRun: 0x80000000,
1270
+ };
1271
+ const AdbSyncSendV2Request = (0,struct/* .struct */.w3)({ id: number/* .u32 */.DH, mode: number/* .u32 */.DH, flags: (0,number/* .u32 */.DH)() }, { littleEndian: true });
1272
+ async function adbSyncPushV2({ socket, filename, file, type = LinuxFileType.File, permission = 0o666, mtime = (Date.now() / 1000) | 0, packetSize = ADB_SYNC_MAX_PACKET_SIZE, dryRun = false, }) {
1273
+ const locked = await socket.lock();
1274
+ try {
1275
+ await adbSyncWriteRequest(locked, AdbSyncRequestId.SendV2, filename);
1276
+ const mode = (type << 12) | permission;
1277
+ let flags = AdbSyncSendV2Flags.None;
1278
+ if (dryRun) {
1279
+ flags |= AdbSyncSendV2Flags.DryRun;
1280
+ }
1281
+ await locked.write(AdbSyncSendV2Request.serialize({
1282
+ id: AdbSyncRequestId.SendV2,
1283
+ mode,
1284
+ flags,
1285
+ }));
1286
+ await pipeFileData(locked, file, packetSize, mtime);
1287
+ }
1288
+ finally {
1289
+ locked.release();
1290
+ }
1291
+ }
1292
+ function adbSyncPush(options) {
1293
+ if (options.v2) {
1294
+ return adbSyncPushV2(options);
1295
+ }
1296
+ if (options.dryRun) {
1297
+ throw new Error("dryRun is not supported in v1");
1298
+ }
1299
+ return adbSyncPushV1(options);
1300
+ }
1301
+ //# sourceMappingURL=push.js.map
1302
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/buffered.js
1303
+ var buffered = __webpack_require__("../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/buffered.js");
1304
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/utils/auto-reset-event.js
1305
+
1306
+ class AutoResetEvent {
1307
+ #set;
1308
+ #queue = [];
1309
+ constructor(initialSet = false) {
1310
+ this.#set = initialSet;
1311
+ }
1312
+ wait() {
1313
+ if (!this.#set) {
1314
+ this.#set = true;
1315
+ if (this.#queue.length === 0) {
1316
+ return Promise.resolve();
1317
+ }
1318
+ }
1319
+ const resolver = new promise_resolver/* .PromiseResolver */.O();
1320
+ this.#queue.push(resolver);
1321
+ return resolver.promise;
1322
+ }
1323
+ notifyOne() {
1324
+ if (this.#queue.length !== 0) {
1325
+ this.#queue.pop().resolve();
1326
+ }
1327
+ else {
1328
+ this.#set = false;
1329
+ }
1330
+ }
1331
+ dispose() {
1332
+ for (const item of this.#queue) {
1333
+ item.reject(new Error("The AutoResetEvent has been disposed"));
1334
+ }
1335
+ this.#queue.length = 0;
1336
+ }
1337
+ }
1338
+ //# sourceMappingURL=auto-reset-event.js.map
1339
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/sync/socket.js
1340
+
1341
+
1342
+ class AdbSyncSocketLocked {
1343
+ #writer;
1344
+ #readable;
1345
+ #socketLock;
1346
+ #writeLock = new AutoResetEvent();
1347
+ #combiner;
1348
+ get position() {
1349
+ return this.#readable.position;
1350
+ }
1351
+ constructor(writer, readable, bufferSize, lock) {
1352
+ this.#writer = writer;
1353
+ this.#readable = readable;
1354
+ this.#socketLock = lock;
1355
+ this.#combiner = new BufferCombiner(bufferSize);
1356
+ }
1357
+ #write(buffer) {
1358
+ // `#combiner` will reuse the buffer, so we need to use the Consumable pattern
1359
+ return consumable/* .Consumable.WritableStream.write */.G.WritableStream.write(this.#writer, buffer);
1360
+ }
1361
+ async flush() {
1362
+ try {
1363
+ await this.#writeLock.wait();
1364
+ const buffer = this.#combiner.flush();
1365
+ if (buffer) {
1366
+ await this.#write(buffer);
1367
+ }
1368
+ }
1369
+ finally {
1370
+ this.#writeLock.notifyOne();
1371
+ }
1372
+ }
1373
+ async write(data) {
1374
+ try {
1375
+ await this.#writeLock.wait();
1376
+ for (const buffer of this.#combiner.push(data)) {
1377
+ await this.#write(buffer);
1378
+ }
1379
+ }
1380
+ finally {
1381
+ this.#writeLock.notifyOne();
1382
+ }
1383
+ }
1384
+ async readExactly(length) {
1385
+ // The request may still be in the internal buffer.
1386
+ // Call `flush` to send it before starting reading
1387
+ await this.flush();
1388
+ return await this.#readable.readExactly(length);
1389
+ }
1390
+ release() {
1391
+ // In theory, the writer shouldn't leave anything in the buffer,
1392
+ // but to be safe, call `flush` to throw away any remaining data.
1393
+ this.#combiner.flush();
1394
+ this.#socketLock.notifyOne();
1395
+ }
1396
+ async close() {
1397
+ await this.#readable.cancel();
1398
+ }
1399
+ }
1400
+ class AdbSyncSocket {
1401
+ #lock = new AutoResetEvent();
1402
+ #socket;
1403
+ #locked;
1404
+ constructor(socket, bufferSize) {
1405
+ this.#socket = socket;
1406
+ this.#locked = new AdbSyncSocketLocked(socket.writable.getWriter(), new buffered/* .BufferedReadableStream */.y(socket.readable), bufferSize, this.#lock);
1407
+ }
1408
+ async lock() {
1409
+ await this.#lock.wait();
1410
+ return this.#locked;
1411
+ }
1412
+ async close() {
1413
+ await this.#locked.close();
1414
+ await this.#socket.close();
1415
+ }
1416
+ }
1417
+ //# sourceMappingURL=socket.js.map
1418
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/sync/sync.js
1419
+
1420
+
1421
+
1422
+
1423
+
1424
+
1425
+
1426
+ /**
1427
+ * A simplified `dirname` function that only handles absolute unix paths.
1428
+ * @param path an absolute unix path
1429
+ * @returns the directory name of the input path
1430
+ */
1431
+ function dirname(path) {
1432
+ const end = path.lastIndexOf("/");
1433
+ if (end === -1) {
1434
+ throw new Error(`Invalid path`);
1435
+ }
1436
+ if (end === 0) {
1437
+ return "/";
1438
+ }
1439
+ return path.substring(0, end);
1440
+ }
1441
+ class AdbSync {
1442
+ _adb;
1443
+ _socket;
1444
+ #supportsStat;
1445
+ #supportsListV2;
1446
+ #fixedPushMkdir;
1447
+ #supportsSendReceiveV2;
1448
+ #needPushMkdirWorkaround;
1449
+ get supportsStat() {
1450
+ return this.#supportsStat;
1451
+ }
1452
+ get supportsListV2() {
1453
+ return this.#supportsListV2;
1454
+ }
1455
+ get fixedPushMkdir() {
1456
+ return this.#fixedPushMkdir;
1457
+ }
1458
+ get supportsSendReceiveV2() {
1459
+ return this.#supportsSendReceiveV2;
1460
+ }
1461
+ get needPushMkdirWorkaround() {
1462
+ return this.#needPushMkdirWorkaround;
1463
+ }
1464
+ constructor(adb, socket) {
1465
+ this._adb = adb;
1466
+ this._socket = new AdbSyncSocket(socket, adb.maxPayloadSize);
1467
+ this.#supportsStat = adb.canUseFeature(AdbFeature.StatV2);
1468
+ this.#supportsListV2 = adb.canUseFeature(AdbFeature.ListV2);
1469
+ this.#fixedPushMkdir = adb.canUseFeature(AdbFeature.FixedPushMkdir);
1470
+ this.#supportsSendReceiveV2 = adb.canUseFeature(AdbFeature.SendReceiveV2);
1471
+ // https://android.googlesource.com/platform/packages/modules/adb/+/91768a57b7138166e0a3d11f79cd55909dda7014/client/file_sync_client.cpp#1361
1472
+ this.#needPushMkdirWorkaround =
1473
+ this._adb.canUseFeature(AdbFeature.ShellV2) && !this.fixedPushMkdir;
1474
+ }
1475
+ /**
1476
+ * Gets information of a file or folder.
1477
+ *
1478
+ * If `path` points to a symbolic link, the returned information is about the link itself (with `type` being `LinuxFileType.Link`).
1479
+ */
1480
+ async lstat(path) {
1481
+ return await adbSyncLstat(this._socket, path, this.#supportsStat);
1482
+ }
1483
+ /**
1484
+ * Gets the information of a file or folder.
1485
+ *
1486
+ * If `path` points to a symbolic link, it will be resolved and the returned information is about the target (with `type` being `LinuxFileType.File` or `LinuxFileType.Directory`).
1487
+ */
1488
+ async stat(path) {
1489
+ if (!this.#supportsStat) {
1490
+ throw new Error("Not supported");
1491
+ }
1492
+ return await adbSyncStat(this._socket, path);
1493
+ }
1494
+ /**
1495
+ * Checks if `path` is a directory, or a symbolic link to a directory.
1496
+ *
1497
+ * This uses `lstat` internally, thus works on all Android versions.
1498
+ */
1499
+ async isDirectory(path) {
1500
+ try {
1501
+ await this.lstat(path + "/");
1502
+ return true;
1503
+ }
1504
+ catch {
1505
+ return false;
1506
+ }
1507
+ }
1508
+ opendir(path) {
1509
+ return adbSyncOpenDir(this._socket, path, this.supportsListV2);
1510
+ }
1511
+ async readdir(path) {
1512
+ const results = [];
1513
+ for await (const entry of this.opendir(path)) {
1514
+ results.push(entry);
1515
+ }
1516
+ return results;
1517
+ }
1518
+ /**
1519
+ * Reads the content of a file on device.
1520
+ *
1521
+ * @param filename The full path of the file on device to read.
1522
+ * @returns A `ReadableStream` that contains the file content.
1523
+ */
1524
+ read(filename) {
1525
+ return adbSyncPull(this._socket, filename);
1526
+ }
1527
+ /**
1528
+ * Writes a file on device. If the file name already exists, it will be overwritten.
1529
+ *
1530
+ * @param options The content and options of the file to write.
1531
+ */
1532
+ async write(options) {
1533
+ if (this.needPushMkdirWorkaround) {
1534
+ // It may fail if `filename` already exists.
1535
+ // Ignore the result.
1536
+ // TODO: sync: test push mkdir workaround (need an Android 8 device)
1537
+ await this._adb.subprocess.noneProtocol.spawnWait([
1538
+ "mkdir",
1539
+ "-p",
1540
+ escapeArg(dirname(options.filename)),
1541
+ ]);
1542
+ }
1543
+ await adbSyncPush({
1544
+ v2: this.supportsSendReceiveV2,
1545
+ socket: this._socket,
1546
+ ...options,
1547
+ });
1548
+ }
1549
+ lockSocket() {
1550
+ return this._socket.lock();
1551
+ }
1552
+ dispose() {
1553
+ return this._socket.close();
1554
+ }
1555
+ }
1556
+ //# sourceMappingURL=sync.js.map
1557
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/commands/framebuffer.js
1558
+
1559
+
1560
+ const Version = (0,struct/* .struct */.w3)({ version: number/* .u32 */.DH }, { littleEndian: true });
1561
+ const AdbFrameBufferV1 = (0,struct/* .struct */.w3)({
1562
+ bpp: number/* .u32 */.DH,
1563
+ size: number/* .u32 */.DH,
1564
+ width: number/* .u32 */.DH,
1565
+ height: number/* .u32 */.DH,
1566
+ red_offset: number/* .u32 */.DH,
1567
+ red_length: number/* .u32 */.DH,
1568
+ blue_offset: number/* .u32 */.DH,
1569
+ blue_length: number/* .u32 */.DH,
1570
+ green_offset: number/* .u32 */.DH,
1571
+ green_length: number/* .u32 */.DH,
1572
+ alpha_offset: number/* .u32 */.DH,
1573
+ alpha_length: number/* .u32 */.DH,
1574
+ data: (0,esm_buffer/* .buffer */.r)("size"),
1575
+ }, { littleEndian: true });
1576
+ const AdbFrameBufferV2 = (0,struct/* .struct */.w3)({
1577
+ bpp: number/* .u32 */.DH,
1578
+ colorSpace: number/* .u32 */.DH,
1579
+ size: number/* .u32 */.DH,
1580
+ width: number/* .u32 */.DH,
1581
+ height: number/* .u32 */.DH,
1582
+ red_offset: number/* .u32 */.DH,
1583
+ red_length: number/* .u32 */.DH,
1584
+ blue_offset: number/* .u32 */.DH,
1585
+ blue_length: number/* .u32 */.DH,
1586
+ green_offset: number/* .u32 */.DH,
1587
+ green_length: number/* .u32 */.DH,
1588
+ alpha_offset: number/* .u32 */.DH,
1589
+ alpha_length: number/* .u32 */.DH,
1590
+ data: (0,esm_buffer/* .buffer */.r)("size"),
1591
+ }, { littleEndian: true });
1592
+ class AdbFrameBufferError extends Error {
1593
+ constructor(message, options) {
1594
+ super(message, options);
1595
+ }
1596
+ }
1597
+ class AdbFrameBufferUnsupportedVersionError extends AdbFrameBufferError {
1598
+ constructor(version) {
1599
+ super(`Unsupported FrameBuffer version ${version}`);
1600
+ }
1601
+ }
1602
+ class AdbFrameBufferForbiddenError extends AdbFrameBufferError {
1603
+ constructor() {
1604
+ super("FrameBuffer is disabled by current app");
1605
+ }
1606
+ }
1607
+ async function framebuffer(adb) {
1608
+ const socket = await adb.createSocket("framebuffer:");
1609
+ const stream = new buffered/* .BufferedReadableStream */.y(socket.readable);
1610
+ let version;
1611
+ try {
1612
+ ({ version } = await Version.deserialize(stream));
1613
+ }
1614
+ catch (e) {
1615
+ if (e instanceof struct/* .StructEmptyError */.r1) {
1616
+ throw new AdbFrameBufferForbiddenError();
1617
+ }
1618
+ throw e;
1619
+ }
1620
+ switch (version) {
1621
+ case 1:
1622
+ // TODO: AdbFrameBuffer: does all v1 responses uses the same color space? Add it so the command returns same format for all versions.
1623
+ return await AdbFrameBufferV1.deserialize(stream);
1624
+ case 2:
1625
+ return await AdbFrameBufferV2.deserialize(stream);
1626
+ default:
1627
+ throw new AdbFrameBufferUnsupportedVersionError(version);
1628
+ }
1629
+ }
1630
+ //# sourceMappingURL=framebuffer.js.map
1631
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/adb.js
1632
+
1633
+
1634
+ class Adb {
1635
+ #transport;
1636
+ get transport() {
1637
+ return this.#transport;
1638
+ }
1639
+ get serial() {
1640
+ return this.#transport.serial;
1641
+ }
1642
+ get maxPayloadSize() {
1643
+ return this.#transport.maxPayloadSize;
1644
+ }
1645
+ get banner() {
1646
+ return this.#transport.banner;
1647
+ }
1648
+ get disconnected() {
1649
+ return this.#transport.disconnected;
1650
+ }
1651
+ get clientFeatures() {
1652
+ return this.#transport.clientFeatures;
1653
+ }
1654
+ get deviceFeatures() {
1655
+ return this.banner.features;
1656
+ }
1657
+ subprocess;
1658
+ power;
1659
+ reverse;
1660
+ tcpip;
1661
+ constructor(transport) {
1662
+ this.#transport = transport;
1663
+ this.subprocess = new AdbSubprocessService(this);
1664
+ this.power = new AdbPower(this);
1665
+ this.reverse = new reverse/* .AdbReverseService */.nQ(this);
1666
+ this.tcpip = new AdbTcpIpService(this);
1667
+ }
1668
+ canUseFeature(feature) {
1669
+ return (this.clientFeatures.includes(feature) &&
1670
+ this.deviceFeatures.includes(feature));
1671
+ }
1672
+ /**
1673
+ * Creates a new ADB Socket to the specified service or socket address.
1674
+ */
1675
+ async createSocket(service) {
1676
+ return this.#transport.connect(service);
1677
+ }
1678
+ async createSocketAndWait(service) {
1679
+ const socket = await this.createSocket(service);
1680
+ return await socket.readable
1681
+ .pipeThrough(new encoding/* .TextDecoderStream */.W())
1682
+ .pipeThrough(new ConcatStringStream());
1683
+ }
1684
+ getProp(key) {
1685
+ return this.subprocess.noneProtocol
1686
+ .spawnWaitText(["getprop", key])
1687
+ .then((output) => output.trim());
1688
+ }
1689
+ rm(filenames, options) {
1690
+ const args = ["rm"];
1691
+ if (options?.recursive) {
1692
+ args.push("-r");
1693
+ }
1694
+ if (options?.force) {
1695
+ args.push("-f");
1696
+ }
1697
+ if (Array.isArray(filenames)) {
1698
+ for (const filename of filenames) {
1699
+ // https://github.com/microsoft/typescript/issues/17002
1700
+ args.push(escapeArg(filename));
1701
+ }
1702
+ }
1703
+ else {
1704
+ // https://github.com/microsoft/typescript/issues/17002
1705
+ args.push(escapeArg(filenames));
1706
+ }
1707
+ // https://android.googlesource.com/platform/packages/modules/adb/+/1a0fb8846d4e6b671c8aa7f137a8c21d7b248716/client/adb_install.cpp#984
1708
+ args.push("</dev/null");
1709
+ return this.subprocess.noneProtocol.spawnWaitText(args);
1710
+ }
1711
+ async sync() {
1712
+ const socket = await this.createSocket("sync:");
1713
+ return new AdbSync(this, socket);
1714
+ }
1715
+ async framebuffer() {
1716
+ return framebuffer(this);
1717
+ }
1718
+ async close() {
1719
+ await this.#transport.close();
1720
+ }
1721
+ }
1722
+ //# sourceMappingURL=adb.js.map
1723
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+no-data-view@2.0.0/node_modules/@yume-chan/no-data-view/esm/uint64.js
1724
+ var uint64 = __webpack_require__("../../node_modules/.pnpm/@yume-chan+no-data-view@2.0.0/node_modules/@yume-chan/no-data-view/esm/uint64.js");
1725
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/banner.js
1726
+ const AdbBannerKey = {
1727
+ Product: "ro.product.name",
1728
+ Model: "ro.product.model",
1729
+ Device: "ro.product.device",
1730
+ Features: "features",
1731
+ };
1732
+ class AdbBanner {
1733
+ static parse(banner) {
1734
+ let product;
1735
+ let model;
1736
+ let device;
1737
+ let features = [];
1738
+ const pieces = banner.split("::");
1739
+ if (pieces.length > 1) {
1740
+ const props = pieces[1];
1741
+ for (const prop of props.split(";")) {
1742
+ // istanbul ignore if
1743
+ if (!prop) {
1744
+ continue;
1745
+ }
1746
+ const keyValue = prop.split("=");
1747
+ if (keyValue.length !== 2) {
1748
+ continue;
1749
+ }
1750
+ const [key, value] = keyValue;
1751
+ switch (key) {
1752
+ case AdbBannerKey.Product:
1753
+ product = value;
1754
+ break;
1755
+ case AdbBannerKey.Model:
1756
+ model = value;
1757
+ break;
1758
+ case AdbBannerKey.Device:
1759
+ device = value;
1760
+ break;
1761
+ case AdbBannerKey.Features:
1762
+ features = value.split(",");
1763
+ break;
1764
+ }
1765
+ }
1766
+ }
1767
+ return new AdbBanner(product, model, device, features);
1768
+ }
1769
+ #product;
1770
+ get product() {
1771
+ return this.#product;
1772
+ }
1773
+ #model;
1774
+ get model() {
1775
+ return this.#model;
1776
+ }
1777
+ #device;
1778
+ get device() {
1779
+ return this.#device;
1780
+ }
1781
+ #features = [];
1782
+ get features() {
1783
+ return this.#features;
1784
+ }
1785
+ constructor(product, model, device, features) {
1786
+ this.#product = product;
1787
+ this.#model = model;
1788
+ this.#device = device;
1789
+ this.#features = features;
1790
+ }
1791
+ }
1792
+ //# sourceMappingURL=banner.js.map
1793
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/utils/hex.js
1794
+ var hex = __webpack_require__("../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/utils/hex.js");
1795
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/utils/sequence-equal.js
1796
+ var sequence_equal = __webpack_require__("../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/utils/sequence-equal.js");
1797
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/try-close.js
1798
+ var try_close = __webpack_require__("../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/try-close.js");
1799
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/bipedal.js
1800
+ var bipedal = __webpack_require__("../../node_modules/.pnpm/@yume-chan+struct@2.3.2/node_modules/@yume-chan/struct/esm/bipedal.js");
1801
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/server/stream.js
1802
+
1803
+
1804
+
1805
+ const OKAY = (0,utils/* .encodeUtf8 */.Af)("OKAY");
1806
+ const FAIL = (0,utils/* .encodeUtf8 */.Af)("FAIL");
1807
+ class AdbServerStream {
1808
+ #connection;
1809
+ #buffered;
1810
+ #writer;
1811
+ constructor(connection) {
1812
+ this.#connection = connection;
1813
+ this.#buffered = new buffered/* .BufferedReadableStream */.y(connection.readable);
1814
+ this.#writer = connection.writable.getWriter();
1815
+ }
1816
+ readExactly(length) {
1817
+ return this.#buffered.readExactly(length);
1818
+ }
1819
+ readString = (0,bipedal/* .bipedal */.q)(function* (then) {
1820
+ const data = yield* then(this.readExactly(4));
1821
+ const length = (0,hex/* .hexToNumber */.M)(data);
1822
+ if (length === 0) {
1823
+ return "";
1824
+ }
1825
+ else {
1826
+ const decoder = new utils/* .TextDecoder */.Ay();
1827
+ let result = "";
1828
+ const iterator = this.#buffered.iterateExactly(length);
1829
+ while (true) {
1830
+ const { done, value } = iterator.next();
1831
+ if (done) {
1832
+ break;
1833
+ }
1834
+ result += decoder.decode(yield* then(value), { stream: true });
1835
+ }
1836
+ result += decoder.decode();
1837
+ return result;
1838
+ }
1839
+ });
1840
+ async readOkay() {
1841
+ const response = await this.readExactly(4);
1842
+ if ((0,sequence_equal/* .sequenceEqual */.m)(response, OKAY)) {
1843
+ // `OKAY` is followed by data length and data
1844
+ // But different services want to parse the data differently
1845
+ // So don't read the data here
1846
+ return;
1847
+ }
1848
+ if ((0,sequence_equal/* .sequenceEqual */.m)(response, FAIL)) {
1849
+ const reason = await this.readString();
1850
+ throw new Error(reason);
1851
+ }
1852
+ throw new Error(`Unexpected response: ${(0,utils/* .decodeUtf8 */._6)(response)}`);
1853
+ }
1854
+ async writeString(value) {
1855
+ // TODO: investigate using `encodeUtf8("0000" + value)` then modifying the length
1856
+ // That way allocates a new string (hopefully only a rope) instead of a new buffer
1857
+ const encoded = (0,utils/* .encodeUtf8 */.Af)(value);
1858
+ const buffer = new Uint8Array(4 + encoded.length);
1859
+ (0,hex/* .write4HexDigits */.h)(buffer, 0, encoded.length);
1860
+ buffer.set(encoded, 4);
1861
+ await this.#writer.write(buffer);
1862
+ }
1863
+ release() {
1864
+ this.#writer.releaseLock();
1865
+ return {
1866
+ readable: this.#buffered.release(),
1867
+ writable: this.#connection.writable,
1868
+ closed: this.#connection.closed,
1869
+ close: () => this.#connection.close(),
1870
+ };
1871
+ }
1872
+ async dispose() {
1873
+ void (0,try_close/* .tryCancel */.S)(this.#buffered);
1874
+ void (0,try_close/* .tryClose */.i)(this.#writer);
1875
+ await this.#connection.close();
1876
+ }
1877
+ }
1878
+ //# sourceMappingURL=stream.js.map
1879
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/server/commands/wireless.js
1880
+ // cspell:ignore tport
1881
+
1882
+
1883
+ class NetworkError extends Error {
1884
+ constructor(message) {
1885
+ super(message);
1886
+ this.name = "NetworkError";
1887
+ }
1888
+ }
1889
+ class UnauthorizedError extends Error {
1890
+ constructor(message) {
1891
+ super(message);
1892
+ this.name = "UnauthorizedError";
1893
+ }
1894
+ }
1895
+ class AlreadyConnectedError extends Error {
1896
+ constructor(message) {
1897
+ super(message);
1898
+ this.name = "AlreadyConnectedError";
1899
+ }
1900
+ }
1901
+ class WirelessCommands {
1902
+ #client;
1903
+ constructor(client) {
1904
+ this.#client = client;
1905
+ }
1906
+ /**
1907
+ * `adb pair <password> <address>`
1908
+ */
1909
+ async pair(address, password) {
1910
+ const connection = await this.#client.createConnection(`host:pair:${password}:${address}`);
1911
+ try {
1912
+ const response = await connection.readExactly(4);
1913
+ // `response` is either `FAIL`, or 4 hex digits for length of the string
1914
+ if ((0,sequence_equal/* .sequenceEqual */.m)(response, FAIL)) {
1915
+ throw new Error(await connection.readString());
1916
+ }
1917
+ const length = (0,hex/* .hexToNumber */.M)(response);
1918
+ // Ignore the string as it's always `Successful ...`
1919
+ await connection.readExactly(length);
1920
+ }
1921
+ finally {
1922
+ await connection.dispose();
1923
+ }
1924
+ }
1925
+ /**
1926
+ * `adb connect <address>`
1927
+ */
1928
+ async connect(address) {
1929
+ const connection = await this.#client.createConnection(`host:connect:${address}`);
1930
+ try {
1931
+ const response = await connection.readString();
1932
+ switch (response) {
1933
+ case `already connected to ${address}`:
1934
+ throw new AlreadyConnectedError(response);
1935
+ case `failed to connect to ${address}`: // `adb pair` mode not authorized
1936
+ case `failed to authenticate to ${address}`: // `adb tcpip` mode not authorized
1937
+ throw new UnauthorizedError(response);
1938
+ case `connected to ${address}`:
1939
+ return;
1940
+ default:
1941
+ throw new NetworkError(response);
1942
+ }
1943
+ }
1944
+ finally {
1945
+ await connection.dispose();
1946
+ }
1947
+ }
1948
+ /**
1949
+ * `adb disconnect <address>`
1950
+ */
1951
+ async disconnect(address) {
1952
+ const connection = await this.#client.createConnection(`host:disconnect:${address}`);
1953
+ try {
1954
+ await connection.readString();
1955
+ }
1956
+ finally {
1957
+ await connection.dispose();
1958
+ }
1959
+ }
1960
+ }
1961
+ //# sourceMappingURL=wireless.js.map
1962
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/server/commands/m-dns.js
1963
+ // cspell:ignore mdns
1964
+ class MDnsCommands {
1965
+ #client;
1966
+ constructor(client) {
1967
+ this.#client = client;
1968
+ }
1969
+ async check() {
1970
+ const connection = await this.#client.createConnection("host:mdns:check");
1971
+ try {
1972
+ const response = await connection.readString();
1973
+ return !response.startsWith("ERROR:");
1974
+ }
1975
+ finally {
1976
+ await connection.dispose();
1977
+ }
1978
+ }
1979
+ async getServices() {
1980
+ const connection = await this.#client.createConnection("host:mdns:services");
1981
+ try {
1982
+ const response = await connection.readString();
1983
+ return response
1984
+ .split("\n")
1985
+ .filter(Boolean)
1986
+ .map((line) => {
1987
+ const parts = line.split("\t");
1988
+ return {
1989
+ name: parts[0],
1990
+ service: parts[1],
1991
+ address: parts[2],
1992
+ };
1993
+ });
1994
+ }
1995
+ finally {
1996
+ await connection.dispose();
1997
+ }
1998
+ }
1999
+ }
2000
+ //# sourceMappingURL=m-dns.js.map
2001
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+event@2.0.0/node_modules/@yume-chan/event/esm/event-emitter.js
2002
+ var event_emitter = __webpack_require__("../../node_modules/.pnpm/@yume-chan+event@2.0.0/node_modules/@yume-chan/event/esm/event-emitter.js");
2003
+ // EXTERNAL MODULE: ../../node_modules/.pnpm/@yume-chan+event@2.0.0/node_modules/@yume-chan/event/esm/sticky-event-emitter.js
2004
+ var sticky_event_emitter = __webpack_require__("../../node_modules/.pnpm/@yume-chan+event@2.0.0/node_modules/@yume-chan/event/esm/sticky-event-emitter.js");
2005
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/utils/ref.js
2006
+ const { setInterval: ref_setInterval, clearInterval: ref_clearInterval } = globalThis;
2007
+ /**
2008
+ * An object to keep current Node.js process alive even when no code is running.
2009
+ *
2010
+ * Does nothing in Web environments.
2011
+ *
2012
+ * Note that it does't have reference counting. Calling `unref` will
2013
+ * remove the ref no matter how many times `ref` has been previously called, and vice versa.
2014
+ * This is the same as how Node.js works.
2015
+ */
2016
+ class Ref {
2017
+ #intervalId;
2018
+ constructor(options) {
2019
+ if (!options?.unref) {
2020
+ this.ref();
2021
+ }
2022
+ }
2023
+ ref() {
2024
+ // `setInterval` can keep current Node.js alive, the delay value doesn't matter
2025
+ this.#intervalId = ref_setInterval(() => { }, 60 * 1000);
2026
+ }
2027
+ unref() {
2028
+ if (this.#intervalId) {
2029
+ ref_clearInterval(this.#intervalId);
2030
+ this.#intervalId = undefined;
2031
+ }
2032
+ }
2033
+ }
2034
+ //# sourceMappingURL=ref.js.map
2035
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/server/observer.js
2036
+
2037
+
2038
+
2039
+ function unorderedRemove(array, index) {
2040
+ if (index < 0 || index >= array.length) {
2041
+ return;
2042
+ }
2043
+ array[index] = array[array.length - 1];
2044
+ array.length -= 1;
2045
+ }
2046
+ function filterDeviceStates(devices, states) {
2047
+ return devices.filter((device) => states.includes(device.state));
2048
+ }
2049
+ class AdbServerDeviceObserverOwner {
2050
+ current = [];
2051
+ #client;
2052
+ #stream;
2053
+ #observers = [];
2054
+ constructor(client) {
2055
+ this.#client = client;
2056
+ }
2057
+ async #receive(stream) {
2058
+ const response = await stream.readString();
2059
+ const next = AdbServerClient.parseDeviceList(response);
2060
+ const removed = this.current.slice();
2061
+ const added = [];
2062
+ for (const nextDevice of next) {
2063
+ const index = removed.findIndex((device) => device.transportId === nextDevice.transportId);
2064
+ if (index === -1) {
2065
+ added.push(nextDevice);
2066
+ continue;
2067
+ }
2068
+ unorderedRemove(removed, index);
2069
+ }
2070
+ this.current = next;
2071
+ if (added.length) {
2072
+ for (const observer of this.#observers) {
2073
+ const filtered = filterDeviceStates(added, observer.includeStates);
2074
+ if (filtered.length) {
2075
+ observer.onDeviceAdd.fire(filtered);
2076
+ }
2077
+ }
2078
+ }
2079
+ if (removed.length) {
2080
+ for (const observer of this.#observers) {
2081
+ const filtered = filterDeviceStates(removed, observer.includeStates);
2082
+ if (filtered.length) {
2083
+ observer.onDeviceRemove.fire(removed);
2084
+ }
2085
+ }
2086
+ }
2087
+ for (const observer of this.#observers) {
2088
+ const filtered = filterDeviceStates(this.current, observer.includeStates);
2089
+ observer.onListChange.fire(filtered);
2090
+ }
2091
+ }
2092
+ async #receiveLoop(stream) {
2093
+ try {
2094
+ while (true) {
2095
+ await this.#receive(stream);
2096
+ }
2097
+ }
2098
+ catch (e) {
2099
+ this.#stream = undefined;
2100
+ for (const observer of this.#observers) {
2101
+ observer.onError.fire(e);
2102
+ }
2103
+ }
2104
+ }
2105
+ async #connect() {
2106
+ const stream = await this.#client.createConnection("host:track-devices-l",
2107
+ // Each individual observer will ref depending on their options
2108
+ { unref: true });
2109
+ // Set `current` and `onListChange` value before returning
2110
+ await this.#receive(stream);
2111
+ // Then start receive loop
2112
+ void this.#receiveLoop(stream);
2113
+ return stream;
2114
+ }
2115
+ async #handleObserverStop(stream) {
2116
+ if (this.#observers.length === 0) {
2117
+ this.#stream = undefined;
2118
+ await stream.dispose();
2119
+ }
2120
+ }
2121
+ async createObserver(options) {
2122
+ options?.signal?.throwIfAborted();
2123
+ let current = [];
2124
+ const onDeviceAdd = new event_emitter/* .EventEmitter */.b();
2125
+ const onDeviceRemove = new event_emitter/* .EventEmitter */.b();
2126
+ const onListChange = new sticky_event_emitter/* .StickyEventEmitter */.O();
2127
+ const onError = new sticky_event_emitter/* .StickyEventEmitter */.O();
2128
+ const includeStates = options?.includeStates ?? [
2129
+ "device",
2130
+ "unauthorized",
2131
+ ];
2132
+ const observer = {
2133
+ includeStates,
2134
+ onDeviceAdd,
2135
+ onDeviceRemove,
2136
+ onListChange,
2137
+ onError,
2138
+ };
2139
+ // Register `observer` before `#connect`.
2140
+ // So `#handleObserverStop` knows if there is any observer.
2141
+ this.#observers.push(observer);
2142
+ // Read the filtered `current` value from `onListChange` event
2143
+ onListChange.event((value) => (current = value));
2144
+ let stream;
2145
+ if (!this.#stream) {
2146
+ // `#connect` will initialize `onListChange` and `current`
2147
+ this.#stream = this.#connect();
2148
+ try {
2149
+ stream = await this.#stream;
2150
+ }
2151
+ catch (e) {
2152
+ this.#stream = undefined;
2153
+ throw e;
2154
+ }
2155
+ }
2156
+ else {
2157
+ stream = await this.#stream;
2158
+ // Initialize `onListChange` and `current` ourselves
2159
+ onListChange.fire(filterDeviceStates(this.current, includeStates));
2160
+ }
2161
+ const ref = new Ref(options);
2162
+ const stop = async () => {
2163
+ unorderedRemove(this.#observers, this.#observers.indexOf(observer));
2164
+ await this.#handleObserverStop(stream);
2165
+ ref.unref();
2166
+ };
2167
+ if (options?.signal) {
2168
+ if (options.signal.aborted) {
2169
+ await stop();
2170
+ throw options.signal.reason;
2171
+ }
2172
+ options.signal.addEventListener("abort", () => void stop());
2173
+ }
2174
+ return {
2175
+ onDeviceAdd: onDeviceAdd.event,
2176
+ onDeviceRemove: onDeviceRemove.event,
2177
+ onListChange: onListChange.event,
2178
+ onError: onError.event,
2179
+ get current() {
2180
+ return current;
2181
+ },
2182
+ stop,
2183
+ };
2184
+ }
2185
+ }
2186
+ //# sourceMappingURL=observer.js.map
2187
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/server/transport.js
2188
+
2189
+
2190
+ const ADB_SERVER_DEFAULT_FEATURES = /* #__PURE__ */ (() => [
2191
+ AdbFeature.ShellV2,
2192
+ AdbFeature.Cmd,
2193
+ AdbFeature.StatV2,
2194
+ AdbFeature.ListV2,
2195
+ AdbFeature.FixedPushMkdir,
2196
+ "apex",
2197
+ AdbFeature.Abb,
2198
+ // only tells the client the symlink timestamp issue in `adb push --sync` has been fixed.
2199
+ // No special handling required.
2200
+ "fixed_push_symlink_timestamp",
2201
+ AdbFeature.AbbExec,
2202
+ "remount_shell",
2203
+ "track_app",
2204
+ AdbFeature.SendReceiveV2,
2205
+ "sendrecv_v2_brotli",
2206
+ "sendrecv_v2_lz4",
2207
+ "sendrecv_v2_zstd",
2208
+ "sendrecv_v2_dry_run_send",
2209
+ ])();
2210
+ class AdbServerTransport {
2211
+ #client;
2212
+ serial;
2213
+ transportId;
2214
+ maxPayloadSize = 1 * 1024 * 1024;
2215
+ banner;
2216
+ #sockets = [];
2217
+ #closed = new promise_resolver/* .PromiseResolver */.O();
2218
+ #disconnected;
2219
+ get disconnected() {
2220
+ return this.#disconnected;
2221
+ }
2222
+ get clientFeatures() {
2223
+ // No need to get host features (features supported by ADB server)
2224
+ // Because we create all ADB packets ourselves
2225
+ return ADB_SERVER_DEFAULT_FEATURES;
2226
+ }
2227
+ // eslint-disable-next-line @typescript-eslint/max-params
2228
+ constructor(client, serial, banner, transportId, disconnected) {
2229
+ this.#client = client;
2230
+ this.serial = serial;
2231
+ this.banner = banner;
2232
+ this.transportId = transportId;
2233
+ this.#disconnected = Promise.race([this.#closed.promise, disconnected]);
2234
+ }
2235
+ async connect(service) {
2236
+ const socket = await this.#client.createDeviceConnection({ transportId: this.transportId }, service);
2237
+ this.#sockets.push(socket);
2238
+ return socket;
2239
+ }
2240
+ async addReverseTunnel(handler, address) {
2241
+ return await this.#client.connector.addReverseTunnel(handler, address);
2242
+ }
2243
+ async removeReverseTunnel(address) {
2244
+ await this.#client.connector.removeReverseTunnel(address);
2245
+ }
2246
+ async clearReverseTunnels() {
2247
+ await this.#client.connector.clearReverseTunnels();
2248
+ }
2249
+ async close() {
2250
+ for (const socket of this.#sockets) {
2251
+ await socket.close();
2252
+ }
2253
+ this.#sockets.length = 0;
2254
+ this.#closed.resolve();
2255
+ }
2256
+ }
2257
+ //# sourceMappingURL=transport.js.map
2258
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/server/client.js
2259
+ // cspell:ignore tport
2260
+
2261
+
2262
+
2263
+
2264
+
2265
+
2266
+
2267
+
2268
+
2269
+
2270
+ /**
2271
+ * Client for the ADB Server.
2272
+ */
2273
+ class AdbServerClient {
2274
+ static NetworkError = NetworkError;
2275
+ static UnauthorizedError = UnauthorizedError;
2276
+ static AlreadyConnectedError = AlreadyConnectedError;
2277
+ static parseDeviceList(value, includeStates = [
2278
+ "device",
2279
+ "unauthorized",
2280
+ ]) {
2281
+ const devices = [];
2282
+ for (const line of value.split("\n")) {
2283
+ if (!line) {
2284
+ continue;
2285
+ }
2286
+ const parts = line.split(" ").filter(Boolean);
2287
+ const serial = parts[0];
2288
+ const state = parts[1];
2289
+ if (!includeStates.includes(state)) {
2290
+ continue;
2291
+ }
2292
+ let product;
2293
+ let model;
2294
+ let device;
2295
+ let transportId;
2296
+ for (let i = 2; i < parts.length; i += 1) {
2297
+ const [key, value] = parts[i].split(":");
2298
+ switch (key) {
2299
+ case "product":
2300
+ product = value;
2301
+ break;
2302
+ case "model":
2303
+ model = value;
2304
+ break;
2305
+ case "device":
2306
+ device = value;
2307
+ break;
2308
+ case "transport_id":
2309
+ transportId = BigInt(value);
2310
+ break;
2311
+ }
2312
+ }
2313
+ if (!transportId) {
2314
+ throw new Error(`No transport id for device ${serial}`);
2315
+ }
2316
+ devices.push({
2317
+ serial,
2318
+ state,
2319
+ authenticating: state === "unauthorized",
2320
+ product,
2321
+ model,
2322
+ device,
2323
+ transportId,
2324
+ });
2325
+ }
2326
+ return devices;
2327
+ }
2328
+ static formatDeviceService(device, command) {
2329
+ if (!device) {
2330
+ return `host:${command}`;
2331
+ }
2332
+ if ("transportId" in device) {
2333
+ return `host-transport-id:${device.transportId}:${command}`;
2334
+ }
2335
+ if ("serial" in device) {
2336
+ return `host-serial:${device.serial}:${command}`;
2337
+ }
2338
+ if ("usb" in device) {
2339
+ return `host-usb:${command}`;
2340
+ }
2341
+ if ("tcp" in device) {
2342
+ return `host-local:${command}`;
2343
+ }
2344
+ throw new TypeError("Invalid device selector");
2345
+ }
2346
+ connector;
2347
+ wireless = new WirelessCommands(this);
2348
+ mDns = new MDnsCommands(this);
2349
+ #observerOwner = new AdbServerDeviceObserverOwner(this);
2350
+ constructor(connector) {
2351
+ this.connector = connector;
2352
+ }
2353
+ async createConnection(request, options) {
2354
+ const connection = await this.connector.connect(options);
2355
+ const stream = new AdbServerStream(connection);
2356
+ try {
2357
+ await stream.writeString(request);
2358
+ }
2359
+ catch (e) {
2360
+ await stream.dispose();
2361
+ throw e;
2362
+ }
2363
+ try {
2364
+ // `raceSignal` throws when the signal is aborted,
2365
+ // so the `catch` block can close the connection.
2366
+ await raceSignal(() => stream.readOkay(), options?.signal);
2367
+ return stream;
2368
+ }
2369
+ catch (e) {
2370
+ await stream.dispose();
2371
+ throw e;
2372
+ }
2373
+ }
2374
+ /**
2375
+ * `adb version`
2376
+ */
2377
+ async getVersion() {
2378
+ const connection = await this.createConnection("host:version");
2379
+ try {
2380
+ const length = (0,hex/* .hexToNumber */.M)(await connection.readExactly(4));
2381
+ const version = (0,hex/* .hexToNumber */.M)(await connection.readExactly(length));
2382
+ return version;
2383
+ }
2384
+ finally {
2385
+ await connection.dispose();
2386
+ }
2387
+ }
2388
+ async validateVersion(minimalVersion) {
2389
+ const version = await this.getVersion();
2390
+ if (version < minimalVersion) {
2391
+ throw new Error(`adb server version (${version}) doesn't match this client (${minimalVersion})`);
2392
+ }
2393
+ }
2394
+ /**
2395
+ * `adb kill-server`
2396
+ */
2397
+ async killServer() {
2398
+ const connection = await this.createConnection("host:kill");
2399
+ await connection.dispose();
2400
+ }
2401
+ /**
2402
+ * `adb host-features`
2403
+ */
2404
+ async getServerFeatures() {
2405
+ const connection = await this.createConnection("host:host-features");
2406
+ try {
2407
+ const response = await connection.readString();
2408
+ return response.split(",");
2409
+ }
2410
+ finally {
2411
+ await connection.dispose();
2412
+ }
2413
+ }
2414
+ /**
2415
+ * Get a list of connected devices from ADB Server.
2416
+ *
2417
+ * Equivalent ADB Command: `adb devices -l`
2418
+ */
2419
+ async getDevices(includeStates = [
2420
+ "device",
2421
+ "unauthorized",
2422
+ ]) {
2423
+ const connection = await this.createConnection("host:devices-l");
2424
+ try {
2425
+ const response = await connection.readString();
2426
+ return AdbServerClient.parseDeviceList(response, includeStates);
2427
+ }
2428
+ finally {
2429
+ await connection.dispose();
2430
+ }
2431
+ }
2432
+ /**
2433
+ * Monitors device list changes.
2434
+ */
2435
+ async trackDevices(options) {
2436
+ return this.#observerOwner.createObserver(options);
2437
+ }
2438
+ /**
2439
+ * `adb -s <device> reconnect` or `adb reconnect offline`
2440
+ */
2441
+ async reconnectDevice(device) {
2442
+ const connection = await this.createConnection(device === "offline"
2443
+ ? "host:reconnect-offline"
2444
+ : AdbServerClient.formatDeviceService(device, "reconnect"));
2445
+ try {
2446
+ await connection.readString();
2447
+ }
2448
+ finally {
2449
+ await connection.dispose();
2450
+ }
2451
+ }
2452
+ /**
2453
+ * Gets the features supported by the device.
2454
+ * The transport ID of the selected device is also returned,
2455
+ * so the caller can execute other commands against the same device.
2456
+ * @param device The device selector
2457
+ * @returns The transport ID of the selected device, and the features supported by the device.
2458
+ */
2459
+ async getDeviceFeatures(device) {
2460
+ // On paper, `host:features` is a host service (device features are cached in host),
2461
+ // so it shouldn't use `createDeviceConnection`,
2462
+ // which is used to forward the service to the device.
2463
+ //
2464
+ // However, `createDeviceConnection` is a two step process:
2465
+ //
2466
+ // 1. Send a switch device service to host, to switch the connection to the device.
2467
+ // 2. Send the actual service to host, let it forward the service to the device.
2468
+ //
2469
+ // In step 2, the host only forward the service to device if the service is unknown to host.
2470
+ // If the service is a host service, it's still handled by host.
2471
+ //
2472
+ // Even better, if the service needs a device selector, but the selector is not provided,
2473
+ // the service will be executed against the device selected by the switch device service.
2474
+ // So we can use all device selector formats for the host service,
2475
+ // and get the transport ID in the same time.
2476
+ const connection = await this.createDeviceConnection(device, "host:features");
2477
+ // Luckily `AdbServerClient.Socket` is compatible with `AdbServerClient.ServerConnection`
2478
+ const stream = new AdbServerStream(connection);
2479
+ try {
2480
+ const featuresString = await stream.readString();
2481
+ const features = featuresString.split(",");
2482
+ return { transportId: connection.transportId, features };
2483
+ }
2484
+ finally {
2485
+ await stream.dispose();
2486
+ }
2487
+ }
2488
+ /**
2489
+ * Creates a connection that will forward the service to device.
2490
+ * @param device The device selector
2491
+ * @param service The service to forward
2492
+ * @returns An `AdbServerClient.Socket` that can be used to communicate with the service
2493
+ */
2494
+ async createDeviceConnection(device, service) {
2495
+ let switchService;
2496
+ let transportId;
2497
+ if (!device) {
2498
+ await this.validateVersion(41);
2499
+ switchService = `host:tport:any`;
2500
+ }
2501
+ else if ("transportId" in device) {
2502
+ switchService = `host:transport-id:${device.transportId}`;
2503
+ transportId = device.transportId;
2504
+ }
2505
+ else if ("serial" in device) {
2506
+ await this.validateVersion(41);
2507
+ switchService = `host:tport:serial:${device.serial}`;
2508
+ }
2509
+ else if ("usb" in device) {
2510
+ await this.validateVersion(41);
2511
+ switchService = `host:tport:usb`;
2512
+ }
2513
+ else if ("tcp" in device) {
2514
+ await this.validateVersion(41);
2515
+ switchService = `host:tport:local`;
2516
+ }
2517
+ else {
2518
+ throw new TypeError("Invalid device selector");
2519
+ }
2520
+ const connection = await this.createConnection(switchService);
2521
+ try {
2522
+ await connection.writeString(service);
2523
+ }
2524
+ catch (e) {
2525
+ await connection.dispose();
2526
+ throw e;
2527
+ }
2528
+ try {
2529
+ if (transportId === undefined) {
2530
+ const array = await connection.readExactly(8);
2531
+ transportId = (0,uint64/* .getUint64LittleEndian */.gw)(array, 0);
2532
+ }
2533
+ await connection.readOkay();
2534
+ const socket = connection.release();
2535
+ return {
2536
+ transportId,
2537
+ service,
2538
+ readable: socket.readable,
2539
+ writable: socket.writable,
2540
+ get closed() {
2541
+ return socket.closed;
2542
+ },
2543
+ async close() {
2544
+ await socket.close();
2545
+ },
2546
+ };
2547
+ }
2548
+ catch (e) {
2549
+ await connection.dispose();
2550
+ throw e;
2551
+ }
2552
+ }
2553
+ async #waitForUnchecked(device, state, options) {
2554
+ let type;
2555
+ if (!device) {
2556
+ type = "any";
2557
+ }
2558
+ else if ("transportId" in device) {
2559
+ type = "any";
2560
+ }
2561
+ else if ("serial" in device) {
2562
+ type = "any";
2563
+ }
2564
+ else if ("usb" in device) {
2565
+ type = "usb";
2566
+ }
2567
+ else if ("tcp" in device) {
2568
+ type = "local";
2569
+ }
2570
+ else {
2571
+ throw new TypeError("Invalid device selector");
2572
+ }
2573
+ // `waitFor` can't use `connectDevice`, because the device
2574
+ // might not be available yet.
2575
+ const service = AdbServerClient.formatDeviceService(device, `wait-for-${type}-${state}`);
2576
+ const connection = await this.createConnection(service, options);
2577
+ try {
2578
+ await connection.readOkay();
2579
+ }
2580
+ finally {
2581
+ await connection.dispose();
2582
+ }
2583
+ }
2584
+ /**
2585
+ * Wait for a device to be connected or disconnected.
2586
+ *
2587
+ * `adb wait-for-<state>`
2588
+ *
2589
+ * @param device The device selector
2590
+ * @param state The state to wait for
2591
+ * @param options The options
2592
+ * @returns A promise that resolves when the condition is met.
2593
+ */
2594
+ async waitFor(device, state, options) {
2595
+ if (state === "disconnect") {
2596
+ await this.validateVersion(41);
2597
+ }
2598
+ return this.#waitForUnchecked(device, state, options);
2599
+ }
2600
+ async waitForDisconnect(transportId, options) {
2601
+ const serverVersion = await this.getVersion();
2602
+ if (serverVersion >= 41) {
2603
+ return this.#waitForUnchecked({ transportId }, "disconnect", options);
2604
+ }
2605
+ else {
2606
+ const observer = await this.trackDevices(options);
2607
+ return new Promise((resolve, reject) => {
2608
+ observer.onDeviceRemove((devices) => {
2609
+ if (devices.some((device) => device.transportId === transportId)) {
2610
+ observer.stop();
2611
+ resolve();
2612
+ }
2613
+ });
2614
+ observer.onError((e) => {
2615
+ observer.stop();
2616
+ reject(e);
2617
+ });
2618
+ });
2619
+ }
2620
+ }
2621
+ /**
2622
+ * Creates an ADB Transport for the specified device.
2623
+ */
2624
+ async createTransport(device) {
2625
+ const { transportId, features } = await this.getDeviceFeatures(device);
2626
+ const devices = await this.getDevices();
2627
+ const info = devices.find((device) => device.transportId === transportId);
2628
+ const banner = new AdbBanner(info?.product, info?.model, info?.device, features);
2629
+ const waitAbortController = new esm_stream/* .AbortController */.z1();
2630
+ const disconnected = this.waitForDisconnect(transportId, {
2631
+ unref: true,
2632
+ signal: waitAbortController.signal,
2633
+ });
2634
+ const transport = new AdbServerTransport(this, info?.serial ?? "", banner, transportId, disconnected);
2635
+ void transport.disconnected.finally(() => waitAbortController.abort());
2636
+ return transport;
2637
+ }
2638
+ async createAdb(device) {
2639
+ const transport = await this.createTransport(device);
2640
+ return new Adb(transport);
2641
+ }
2642
+ }
2643
+ async function raceSignal(callback, ...signals) {
2644
+ const abortPromise = new promise_resolver/* .PromiseResolver */.O();
2645
+ function abort() {
2646
+ abortPromise.reject(this.reason);
2647
+ }
2648
+ try {
2649
+ for (const signal of signals) {
2650
+ if (!signal) {
2651
+ continue;
2652
+ }
2653
+ if (signal.aborted) {
2654
+ throw signal.reason;
2655
+ }
2656
+ signal.addEventListener("abort", abort);
2657
+ }
2658
+ return await Promise.race([callback(), abortPromise.promise]);
2659
+ }
2660
+ finally {
2661
+ for (const signal of signals) {
2662
+ if (!signal) {
2663
+ continue;
2664
+ }
2665
+ signal.removeEventListener("abort", abort);
2666
+ }
2667
+ }
2668
+ }
2669
+ //# sourceMappingURL=client.js.map
2670
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/server/index.js
2671
+
2672
+
2673
+
2674
+
2675
+ //# sourceMappingURL=index.js.map
2676
+ ;// CONCATENATED MODULE: ../../node_modules/.pnpm/@yume-chan+adb@2.5.1/node_modules/@yume-chan/adb/esm/index.js
2677
+
2678
+
2679
+
2680
+
2681
+
2682
+
2683
+
2684
+
2685
+ //# sourceMappingURL=index.js.map
2686
+
2687
+ },
2688
+ "../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/maybe-consumable/utils.js"(__unused_rspack___webpack_module__, __webpack_exports__, __webpack_require__) {
2689
+ __webpack_require__.d(__webpack_exports__, {
2690
+ W: () => (tryConsume)
2691
+ });
2692
+ /* import */ var _consumable_js__rspack_import_0 = __webpack_require__("../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/consumable.js");
2693
+
2694
+ function getValue(value) {
2695
+ return value instanceof Consumable ? value.value : value;
2696
+ }
2697
+ function tryConsume(value, callback) {
2698
+ if (value instanceof _consumable_js__rspack_import_0/* .Consumable */.G) {
2699
+ return value.tryConsume(callback);
2700
+ }
2701
+ else {
2702
+ return callback(value);
2703
+ }
2704
+ }
2705
+ //# sourceMappingURL=utils.js.map
2706
+
2707
+ },
2708
+ "../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/maybe-consumable/writable.js"(__unused_rspack___webpack_module__, __webpack_exports__, __webpack_require__) {
2709
+ __webpack_require__.d(__webpack_exports__, {
2710
+ g: () => (MaybeConsumableWritableStream)
2711
+ });
2712
+ /* import */ var _consumable_js__rspack_import_1 = __webpack_require__("../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/consumable.js");
2713
+ /* import */ var _stream_js__rspack_import_0 = __webpack_require__("../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/stream.js");
2714
+ /* import */ var _utils_js__rspack_import_2 = __webpack_require__("../../node_modules/.pnpm/@yume-chan+stream-extra@2.1.0/node_modules/@yume-chan/stream-extra/esm/maybe-consumable/utils.js");
2715
+
2716
+
2717
+
2718
+ class MaybeConsumableWritableStream extends _stream_js__rspack_import_0/* .WritableStream */.ho {
2719
+ constructor(sink, strategy) {
2720
+ let wrappedStrategy;
2721
+ if (strategy) {
2722
+ wrappedStrategy = {};
2723
+ if ("highWaterMark" in strategy) {
2724
+ wrappedStrategy.highWaterMark = strategy.highWaterMark;
2725
+ }
2726
+ if ("size" in strategy) {
2727
+ wrappedStrategy.size = (chunk) => {
2728
+ return strategy.size(chunk instanceof _consumable_js__rspack_import_1/* .Consumable */.G ? chunk.value : chunk);
2729
+ };
2730
+ }
2731
+ }
2732
+ super({
2733
+ start(controller) {
2734
+ return sink.start?.(controller);
2735
+ },
2736
+ write(chunk, controller) {
2737
+ return (0,_utils_js__rspack_import_2/* .tryConsume */.W)(chunk, (chunk) => sink.write?.(chunk, controller));
2738
+ },
2739
+ abort(reason) {
2740
+ return sink.abort?.(reason);
2741
+ },
2742
+ close() {
2743
+ return sink.close?.();
2744
+ },
2745
+ }, wrappedStrategy);
2746
+ }
2747
+ }
2748
+ //# sourceMappingURL=writable.js.map
2749
+
2750
+ },
2751
+
2752
+ };
2753
+ ;