@yume-chan/adb 1.1.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/LICENSE +1 -1
- package/esm/adb.d.ts +7 -6
- package/esm/adb.d.ts.map +1 -1
- package/esm/adb.js +22 -22
- package/esm/adb.js.map +1 -1
- package/esm/banner.js.map +1 -1
- package/esm/commands/base.d.ts +3 -2
- package/esm/commands/base.d.ts.map +1 -1
- package/esm/commands/base.js +6 -3
- package/esm/commands/base.js.map +1 -1
- package/esm/commands/framebuffer.d.ts +6 -6
- package/esm/commands/power.d.ts +2 -2
- package/esm/commands/power.d.ts.map +1 -1
- package/esm/commands/power.js +4 -4
- package/esm/commands/power.js.map +1 -1
- package/esm/commands/reverse.d.ts +3 -4
- package/esm/commands/reverse.d.ts.map +1 -1
- package/esm/commands/reverse.js +5 -10
- package/esm/commands/reverse.js.map +1 -1
- package/esm/commands/subprocess/index.d.ts +3 -2
- package/esm/commands/subprocess/index.d.ts.map +1 -1
- package/esm/commands/subprocess/index.js +3 -2
- package/esm/commands/subprocess/index.js.map +1 -1
- package/esm/commands/subprocess/none/index.d.ts +5 -0
- package/esm/commands/subprocess/none/index.d.ts.map +1 -0
- package/esm/commands/subprocess/none/index.js +5 -0
- package/esm/commands/subprocess/none/index.js.map +1 -0
- package/esm/commands/subprocess/none/process.d.ts +13 -0
- package/esm/commands/subprocess/none/process.d.ts.map +1 -0
- package/esm/commands/subprocess/none/process.js +36 -0
- package/esm/commands/subprocess/none/process.js.map +1 -0
- package/esm/commands/subprocess/none/pty.d.ts +15 -0
- package/esm/commands/subprocess/none/pty.d.ts.map +1 -0
- package/esm/commands/subprocess/none/pty.js +29 -0
- package/esm/commands/subprocess/none/pty.js.map +1 -0
- package/esm/commands/subprocess/none/service.d.ts +10 -0
- package/esm/commands/subprocess/none/service.d.ts.map +1 -0
- package/esm/commands/subprocess/none/service.js +32 -0
- package/esm/commands/subprocess/none/service.js.map +1 -0
- package/esm/commands/subprocess/none/spawner.d.ts +19 -0
- package/esm/commands/subprocess/none/spawner.d.ts.map +1 -0
- package/esm/commands/subprocess/none/spawner.js +26 -0
- package/esm/commands/subprocess/none/spawner.js.map +1 -0
- package/esm/commands/subprocess/pty.d.ts +10 -0
- package/esm/commands/subprocess/pty.d.ts.map +1 -0
- package/esm/commands/subprocess/pty.js +2 -0
- package/esm/commands/subprocess/pty.js.map +1 -0
- package/esm/commands/subprocess/service.d.ts +11 -0
- package/esm/commands/subprocess/service.d.ts.map +1 -0
- package/esm/commands/subprocess/service.js +25 -0
- package/esm/commands/subprocess/service.js.map +1 -0
- package/esm/commands/subprocess/shell/index.d.ts +6 -0
- package/esm/commands/subprocess/shell/index.d.ts.map +1 -0
- package/esm/commands/subprocess/shell/index.js +6 -0
- package/esm/commands/subprocess/shell/index.js.map +1 -0
- package/esm/commands/subprocess/shell/process.d.ts +15 -0
- package/esm/commands/subprocess/shell/process.d.ts.map +1 -0
- package/esm/commands/subprocess/{protocols/shell.js → shell/process.js} +27 -54
- package/esm/commands/subprocess/shell/process.js.map +1 -0
- package/esm/commands/subprocess/shell/pty.d.ts +15 -0
- package/esm/commands/subprocess/shell/pty.d.ts.map +1 -0
- package/esm/commands/subprocess/shell/pty.js +76 -0
- package/esm/commands/subprocess/shell/pty.js.map +1 -0
- package/esm/commands/subprocess/shell/service.d.ts +14 -0
- package/esm/commands/subprocess/shell/service.d.ts.map +1 -0
- package/esm/commands/subprocess/shell/service.js +41 -0
- package/esm/commands/subprocess/shell/service.js.map +1 -0
- package/esm/commands/subprocess/shell/shared.d.ts +19 -0
- package/esm/commands/subprocess/shell/shared.d.ts.map +1 -0
- package/esm/commands/subprocess/shell/shared.js +15 -0
- package/esm/commands/subprocess/shell/shared.js.map +1 -0
- package/esm/commands/subprocess/shell/spawner.d.ts +24 -0
- package/esm/commands/subprocess/shell/spawner.d.ts.map +1 -0
- package/esm/commands/subprocess/shell/spawner.js +38 -0
- package/esm/commands/subprocess/shell/spawner.js.map +1 -0
- package/esm/commands/subprocess/utils.d.ts +1 -0
- package/esm/commands/subprocess/utils.d.ts.map +1 -1
- package/esm/commands/subprocess/utils.js +37 -0
- package/esm/commands/subprocess/utils.js.map +1 -1
- package/esm/commands/sync/list.d.ts +12 -8
- package/esm/commands/sync/list.d.ts.map +1 -1
- package/esm/commands/sync/list.js +5 -7
- package/esm/commands/sync/list.js.map +1 -1
- package/esm/commands/sync/pull.d.ts +4 -4
- package/esm/commands/sync/pull.d.ts.map +1 -1
- package/esm/commands/sync/pull.js +2 -7
- package/esm/commands/sync/pull.js.map +1 -1
- package/esm/commands/sync/push.d.ts +4 -4
- package/esm/commands/sync/request.d.ts +1 -1
- package/esm/commands/sync/response.d.ts +5 -5
- package/esm/commands/sync/response.d.ts.map +1 -1
- package/esm/commands/sync/response.js +2 -1
- package/esm/commands/sync/response.js.map +1 -1
- package/esm/commands/sync/stat.d.ts +4 -4
- package/esm/commands/sync/sync.d.ts +2 -2
- package/esm/commands/sync/sync.js +1 -1
- package/esm/commands/sync/sync.js.map +1 -1
- package/esm/commands/tcpip.d.ts +2 -2
- package/esm/commands/tcpip.js +2 -2
- package/esm/daemon/dispatcher.d.ts.map +1 -1
- package/esm/daemon/dispatcher.js.map +1 -1
- package/esm/daemon/packet.d.ts +6 -4
- package/esm/daemon/packet.d.ts.map +1 -1
- package/esm/daemon/packet.js +3 -5
- package/esm/daemon/packet.js.map +1 -1
- package/esm/daemon/socket.d.ts +2 -2
- package/esm/daemon/socket.d.ts.map +1 -1
- package/esm/daemon/socket.js +1 -1
- package/esm/daemon/socket.js.map +1 -1
- package/esm/device-observer.d.ts +4 -4
- package/esm/device-observer.d.ts.map +1 -1
- package/esm/server/client.d.ts +10 -38
- package/esm/server/client.d.ts.map +1 -1
- package/esm/server/client.js +9 -126
- package/esm/server/client.js.map +1 -1
- package/esm/server/commands/index.d.ts +3 -0
- package/esm/server/commands/index.d.ts.map +1 -0
- package/esm/server/commands/index.js +3 -0
- package/esm/server/commands/index.js.map +1 -0
- package/esm/server/commands/m-dns.d.ts +12 -0
- package/esm/server/commands/m-dns.d.ts.map +1 -0
- package/esm/server/commands/m-dns.js +38 -0
- package/esm/server/commands/m-dns.js.map +1 -0
- package/esm/server/commands/wireless.d.ts +27 -0
- package/esm/server/commands/wireless.d.ts.map +1 -0
- package/esm/server/commands/wireless.js +82 -0
- package/esm/server/commands/wireless.js.map +1 -0
- package/esm/server/observer.d.ts +2 -1
- package/esm/server/observer.d.ts.map +1 -1
- package/esm/server/observer.js +69 -47
- package/esm/server/observer.js.map +1 -1
- package/esm/server/stream.d.ts +1 -1
- package/esm/server/transport.d.ts.map +1 -1
- package/esm/server/transport.js +2 -2
- package/esm/server/transport.js.map +1 -1
- package/package.json +10 -10
- package/src/adb.ts +29 -28
- package/src/banner.ts +4 -4
- package/src/commands/base.ts +6 -3
- package/src/commands/power.ts +6 -6
- package/src/commands/reverse.ts +9 -12
- package/src/commands/subprocess/index.ts +3 -2
- package/src/commands/subprocess/none/index.ts +4 -0
- package/src/commands/subprocess/none/process.ts +56 -0
- package/src/commands/subprocess/none/pty.ts +45 -0
- package/src/commands/subprocess/none/service.ts +42 -0
- package/src/commands/subprocess/none/spawner.ts +68 -0
- package/src/commands/subprocess/pty.ts +15 -0
- package/src/commands/subprocess/service.ts +32 -0
- package/src/commands/subprocess/shell/index.ts +5 -0
- package/src/commands/subprocess/shell/process.ts +127 -0
- package/src/commands/subprocess/shell/pty.ts +112 -0
- package/src/commands/subprocess/shell/service.ts +58 -0
- package/src/commands/subprocess/shell/shared.ts +25 -0
- package/src/commands/subprocess/shell/spawner.ts +90 -0
- package/src/commands/subprocess/utils.ts +41 -0
- package/src/commands/sync/list.ts +7 -17
- package/src/commands/sync/pull.ts +2 -8
- package/src/commands/sync/response.ts +6 -4
- package/src/commands/sync/sync.ts +1 -1
- package/src/commands/tcpip.ts +2 -2
- package/src/daemon/dispatcher.ts +7 -4
- package/src/daemon/packet.ts +4 -8
- package/src/daemon/socket.ts +6 -6
- package/src/device-observer.ts +4 -4
- package/src/server/client.ts +23 -142
- package/src/server/commands/index.ts +2 -0
- package/src/server/commands/m-dns.ts +43 -0
- package/src/server/commands/wireless.ts +94 -0
- package/src/server/observer.ts +94 -66
- package/src/server/transport.ts +21 -20
- package/tsconfig.build.tsbuildinfo +1 -1
- package/esm/commands/subprocess/command.d.ts +0 -58
- package/esm/commands/subprocess/command.d.ts.map +0 -1
- package/esm/commands/subprocess/command.js +0 -89
- package/esm/commands/subprocess/command.js.map +0 -1
- package/esm/commands/subprocess/protocols/index.d.ts +0 -4
- package/esm/commands/subprocess/protocols/index.d.ts.map +0 -1
- package/esm/commands/subprocess/protocols/index.js +0 -4
- package/esm/commands/subprocess/protocols/index.js.map +0 -1
- package/esm/commands/subprocess/protocols/none.d.ts +0 -32
- package/esm/commands/subprocess/protocols/none.d.ts.map +0 -1
- package/esm/commands/subprocess/protocols/none.js +0 -61
- package/esm/commands/subprocess/protocols/none.js.map +0 -1
- package/esm/commands/subprocess/protocols/shell.d.ts +0 -42
- package/esm/commands/subprocess/protocols/shell.d.ts.map +0 -1
- package/esm/commands/subprocess/protocols/shell.js.map +0 -1
- package/esm/commands/subprocess/protocols/types.d.ts +0 -49
- package/esm/commands/subprocess/protocols/types.d.ts.map +0 -1
- package/esm/commands/subprocess/protocols/types.js +0 -2
- package/esm/commands/subprocess/protocols/types.js.map +0 -1
- package/src/commands/subprocess/command.ts +0 -141
- package/src/commands/subprocess/protocols/index.ts +0 -3
- package/src/commands/subprocess/protocols/none.ts +0 -81
- package/src/commands/subprocess/protocols/shell.ts +0 -171
- package/src/commands/subprocess/protocols/types.ts +0 -63
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { ConcatStringStream, TextDecoderStream } from "@yume-chan/stream-extra";
|
|
2
|
-
import { AdbCommandBase } from "../base.js";
|
|
3
|
-
import { AdbSubprocessNoneProtocol, AdbSubprocessShellProtocol, } from "./protocols/index.js";
|
|
4
|
-
const DEFAULT_OPTIONS = {
|
|
5
|
-
protocols: [AdbSubprocessShellProtocol, AdbSubprocessNoneProtocol],
|
|
6
|
-
};
|
|
7
|
-
export class AdbSubprocess extends AdbCommandBase {
|
|
8
|
-
async #createProtocol(mode, command, options) {
|
|
9
|
-
const { protocols } = { ...DEFAULT_OPTIONS, ...options };
|
|
10
|
-
let Constructor;
|
|
11
|
-
for (const item of protocols) {
|
|
12
|
-
// It's async so can't use `Array#find`
|
|
13
|
-
if (await item.isSupported(this.adb)) {
|
|
14
|
-
Constructor = item;
|
|
15
|
-
break;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
if (!Constructor) {
|
|
19
|
-
throw new Error("No specified protocol is supported by the device");
|
|
20
|
-
}
|
|
21
|
-
if (Array.isArray(command)) {
|
|
22
|
-
command = command.join(" ");
|
|
23
|
-
}
|
|
24
|
-
else if (command === undefined) {
|
|
25
|
-
// spawn the default shell
|
|
26
|
-
command = "";
|
|
27
|
-
}
|
|
28
|
-
return await Constructor[mode](this.adb, command);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Spawns an executable in PTY mode.
|
|
32
|
-
*
|
|
33
|
-
* Redirection mode is enough for most simple commands, but PTY mode is required for
|
|
34
|
-
* commands that manipulate the terminal, such as `vi` and `less`.
|
|
35
|
-
* @param command The command to run. If omitted, the default shell will be spawned.
|
|
36
|
-
* @param options The options for creating the `AdbSubprocessProtocol`
|
|
37
|
-
* @returns A new `AdbSubprocessProtocol` instance connecting to the spawned process.
|
|
38
|
-
*/
|
|
39
|
-
shell(command, options) {
|
|
40
|
-
return this.#createProtocol("pty", command, options);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Spawns an executable and redirect the standard input/output stream.
|
|
44
|
-
*
|
|
45
|
-
* Redirection mode is enough for most simple commands, but PTY mode is required for
|
|
46
|
-
* commands that manipulate the terminal, such as `vi` and `less`.
|
|
47
|
-
* @param command The command to run, or an array of strings containing both command and args.
|
|
48
|
-
* @param options The options for creating the `AdbSubprocessProtocol`
|
|
49
|
-
* @returns A new `AdbSubprocessProtocol` instance connecting to the spawned process.
|
|
50
|
-
*/
|
|
51
|
-
spawn(command, options) {
|
|
52
|
-
return this.#createProtocol("raw", command, options);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Spawns a new process, waits until it exits, and returns the entire output.
|
|
56
|
-
* @param command The command to run
|
|
57
|
-
* @param options The options for creating the `AdbSubprocessProtocol`
|
|
58
|
-
* @returns The entire output of the command
|
|
59
|
-
*/
|
|
60
|
-
async spawnAndWait(command, options) {
|
|
61
|
-
const process = await this.spawn(command, options);
|
|
62
|
-
const [stdout, stderr, exitCode] = await Promise.all([
|
|
63
|
-
process.stdout
|
|
64
|
-
.pipeThrough(new TextDecoderStream())
|
|
65
|
-
.pipeThrough(new ConcatStringStream()),
|
|
66
|
-
process.stderr
|
|
67
|
-
.pipeThrough(new TextDecoderStream())
|
|
68
|
-
.pipeThrough(new ConcatStringStream()),
|
|
69
|
-
process.exit,
|
|
70
|
-
]);
|
|
71
|
-
return {
|
|
72
|
-
stdout,
|
|
73
|
-
stderr,
|
|
74
|
-
exitCode,
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Spawns a new process, waits until it exits, and returns the entire output.
|
|
79
|
-
* @param command The command to run
|
|
80
|
-
* @returns The entire output of the command
|
|
81
|
-
*/
|
|
82
|
-
async spawnAndWaitLegacy(command) {
|
|
83
|
-
const { stdout } = await this.spawnAndWait(command, {
|
|
84
|
-
protocols: [AdbSubprocessNoneProtocol],
|
|
85
|
-
});
|
|
86
|
-
return stdout;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
//# sourceMappingURL=command.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command.js","sourceRoot":"","sources":["../../../src/commands/subprocess/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,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D,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CACD,OAA0B,EAC1B,OAAuC;QAEvC,OAAO,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;IACzD,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,YAAY,CACd,OAA0B,EAC1B,OAAuC;QAEvC,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAEnD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACjD,OAAO,CAAC,MAAM;iBACT,WAAW,CAAC,IAAI,iBAAiB,EAAE,CAAC;iBACpC,WAAW,CAAC,IAAI,kBAAkB,EAAE,CAAC;YAC1C,OAAO,CAAC,MAAM;iBACT,WAAW,CAAC,IAAI,iBAAiB,EAAE,CAAC;iBACpC,WAAW,CAAC,IAAI,kBAAkB,EAAE,CAAC;YAC1C,OAAO,CAAC,IAAI;SACf,CAAC,CAAC;QAEH,OAAO;YACH,MAAM;YACN,MAAM;YACN,QAAQ;SACX,CAAC;IACN,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,kBAAkB,CAAC,OAA0B;QAC/C,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;YAChD,SAAS,EAAE,CAAC,yBAAyB,CAAC;SACzC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAClB,CAAC;CACJ"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/commands/subprocess/protocols/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/commands/subprocess/protocols/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { MaybeConsumable, WritableStream } from "@yume-chan/stream-extra";
|
|
2
|
-
import { ReadableStream } from "@yume-chan/stream-extra";
|
|
3
|
-
import type { Adb, AdbSocket } from "../../../adb.js";
|
|
4
|
-
import type { AdbSubprocessProtocol } from "./types.js";
|
|
5
|
-
/**
|
|
6
|
-
* The legacy shell
|
|
7
|
-
*
|
|
8
|
-
* Features:
|
|
9
|
-
* * `stderr`: No
|
|
10
|
-
* * `exit` exit code: No
|
|
11
|
-
* * `resize`: No
|
|
12
|
-
*/
|
|
13
|
-
export declare class AdbSubprocessNoneProtocol implements AdbSubprocessProtocol {
|
|
14
|
-
#private;
|
|
15
|
-
static isSupported(): boolean;
|
|
16
|
-
static pty(adb: Adb, command: string): Promise<AdbSubprocessNoneProtocol>;
|
|
17
|
-
static raw(adb: Adb, command: string): Promise<AdbSubprocessNoneProtocol>;
|
|
18
|
-
get stdin(): WritableStream<MaybeConsumable<Uint8Array>>;
|
|
19
|
-
/**
|
|
20
|
-
* Legacy shell mixes stdout and stderr.
|
|
21
|
-
*/
|
|
22
|
-
get stdout(): ReadableStream<Uint8Array>;
|
|
23
|
-
/**
|
|
24
|
-
* `stderr` will always be empty.
|
|
25
|
-
*/
|
|
26
|
-
get stderr(): ReadableStream<Uint8Array>;
|
|
27
|
-
get exit(): Promise<number>;
|
|
28
|
-
constructor(socket: AdbSocket);
|
|
29
|
-
resize(): void;
|
|
30
|
-
kill(): Promise<void>;
|
|
31
|
-
}
|
|
32
|
-
//# sourceMappingURL=none.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"none.d.ts","sourceRoot":"","sources":["../../../../src/commands/subprocess/protocols/none.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAEzD,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD;;;;;;;GAOG;AACH,qBAAa,yBAA0B,YAAW,qBAAqB;;IACnE,MAAM,CAAC,WAAW;WAIL,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;WAM7B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;IAW1C,IAAI,KAAK,IAAI,cAAc,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAEvD;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,cAAc,CAAC,UAAU,CAAC,CAEvC;IAGD;;OAEG;IACH,IAAI,MAAM,IAAI,cAAc,CAAC,UAAU,CAAC,CAEvC;IAGD,IAAI,IAAI,oBAEP;gBAEW,MAAM,EAAE,SAAS;IAY7B,MAAM;IAIA,IAAI;CAGb"}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { ReadableStream } from "@yume-chan/stream-extra";
|
|
2
|
-
/**
|
|
3
|
-
* The legacy shell
|
|
4
|
-
*
|
|
5
|
-
* Features:
|
|
6
|
-
* * `stderr`: No
|
|
7
|
-
* * `exit` exit code: No
|
|
8
|
-
* * `resize`: No
|
|
9
|
-
*/
|
|
10
|
-
export class AdbSubprocessNoneProtocol {
|
|
11
|
-
static isSupported() {
|
|
12
|
-
return true;
|
|
13
|
-
}
|
|
14
|
-
static async pty(adb, command) {
|
|
15
|
-
return new AdbSubprocessNoneProtocol(await adb.createSocket(`shell:${command}`));
|
|
16
|
-
}
|
|
17
|
-
static async raw(adb, command) {
|
|
18
|
-
// `shell,raw:${command}` also triggers raw mode,
|
|
19
|
-
// But is not supported on Android version <7.
|
|
20
|
-
return new AdbSubprocessNoneProtocol(await adb.createSocket(`exec:${command}`));
|
|
21
|
-
}
|
|
22
|
-
#socket;
|
|
23
|
-
// Legacy shell forwards all data to stdin.
|
|
24
|
-
get stdin() {
|
|
25
|
-
return this.#socket.writable;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Legacy shell mixes stdout and stderr.
|
|
29
|
-
*/
|
|
30
|
-
get stdout() {
|
|
31
|
-
return this.#socket.readable;
|
|
32
|
-
}
|
|
33
|
-
#stderr;
|
|
34
|
-
/**
|
|
35
|
-
* `stderr` will always be empty.
|
|
36
|
-
*/
|
|
37
|
-
get stderr() {
|
|
38
|
-
return this.#stderr;
|
|
39
|
-
}
|
|
40
|
-
#exit;
|
|
41
|
-
get exit() {
|
|
42
|
-
return this.#exit;
|
|
43
|
-
}
|
|
44
|
-
constructor(socket) {
|
|
45
|
-
this.#socket = socket;
|
|
46
|
-
this.#stderr = new ReadableStream({
|
|
47
|
-
start: async (controller) => {
|
|
48
|
-
await this.#socket.closed;
|
|
49
|
-
controller.close();
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
this.#exit = socket.closed.then(() => 0);
|
|
53
|
-
}
|
|
54
|
-
resize() {
|
|
55
|
-
// Not supported, but don't throw.
|
|
56
|
-
}
|
|
57
|
-
async kill() {
|
|
58
|
-
await this.#socket.close();
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
//# sourceMappingURL=none.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"none.js","sourceRoot":"","sources":["../../../../src/commands/subprocess/protocols/none.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAMzD;;;;;;;GAOG;AACH,MAAM,OAAO,yBAAyB;IAClC,MAAM,CAAC,WAAW;QACd,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,GAAQ,EAAE,OAAe;Q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 +0,0 @@
|
|
|
1
|
-
import type { ReadableStream } from "@yume-chan/stream-extra";
|
|
2
|
-
import { MaybeConsumable, WritableStream } from "@yume-chan/stream-extra";
|
|
3
|
-
import type { Adb, AdbSocket } from "../../../adb.js";
|
|
4
|
-
import type { AdbSubprocessProtocol } from "./types.js";
|
|
5
|
-
export declare const AdbShellProtocolId: {
|
|
6
|
-
readonly Stdin: 0;
|
|
7
|
-
readonly Stdout: 1;
|
|
8
|
-
readonly Stderr: 2;
|
|
9
|
-
readonly Exit: 3;
|
|
10
|
-
readonly CloseStdin: 4;
|
|
11
|
-
readonly WindowSizeChange: 5;
|
|
12
|
-
};
|
|
13
|
-
export type AdbShellProtocolId = (typeof AdbShellProtocolId)[keyof typeof AdbShellProtocolId];
|
|
14
|
-
export declare const AdbShellProtocolPacket: import("@yume-chan/struct").Struct<{
|
|
15
|
-
id: import("@yume-chan/struct").Field<AdbShellProtocolId, never, never>;
|
|
16
|
-
data: import("@yume-chan/struct").Field<Uint8Array<ArrayBufferLike>, never, never>;
|
|
17
|
-
}, {}, import("@yume-chan/struct").FieldsType<{
|
|
18
|
-
id: import("@yume-chan/struct").Field<AdbShellProtocolId, never, never>;
|
|
19
|
-
data: import("@yume-chan/struct").Field<Uint8Array<ArrayBufferLike>, never, never>;
|
|
20
|
-
}>>;
|
|
21
|
-
/**
|
|
22
|
-
* Shell v2 a.k.a Shell Protocol
|
|
23
|
-
*
|
|
24
|
-
* Features:
|
|
25
|
-
* * `stderr`: Yes
|
|
26
|
-
* * `exit` exit code: Yes
|
|
27
|
-
* * `resize`: Yes
|
|
28
|
-
*/
|
|
29
|
-
export declare class AdbSubprocessShellProtocol implements AdbSubprocessProtocol {
|
|
30
|
-
#private;
|
|
31
|
-
static isSupported(adb: Adb): boolean;
|
|
32
|
-
static pty(adb: Adb, command: string): Promise<AdbSubprocessShellProtocol>;
|
|
33
|
-
static raw(adb: Adb, command: string): Promise<AdbSubprocessShellProtocol>;
|
|
34
|
-
get stdin(): WritableStream<MaybeConsumable<Uint8Array<ArrayBufferLike>>>;
|
|
35
|
-
get stdout(): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
36
|
-
get stderr(): ReadableStream<Uint8Array<ArrayBufferLike>>;
|
|
37
|
-
get exit(): Promise<number>;
|
|
38
|
-
constructor(socket: AdbSocket);
|
|
39
|
-
resize(rows: number, cols: number): Promise<void>;
|
|
40
|
-
kill(): import("@yume-chan/async").MaybePromiseLike<void>;
|
|
41
|
-
}
|
|
42
|
-
//# sourceMappingURL=shell.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"shell.d.ts","sourceRoot":"","sources":["../../../../src/commands/subprocess/protocols/shell.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAER,cAAc,EAEjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACH,eAAe,EAGf,cAAc,EACjB,MAAM,yBAAyB,CAAC;AAIjC,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAItD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAExD,eAAO,MAAM,kBAAkB;;;;;;;CAOrB,CAAC;AAEX,MAAM,MAAM,kBAAkB,GAC1B,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC;AAGjE,eAAO,MAAM,sBAAsB;;;;;;GAMlC,CAAC;AAIF;;;;;;;GAOG;AACH,qBAAa,0BAA2B,YAAW,qBAAqB;;IACpE,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG;WAId,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;WAO7B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;IAU1C,IAAI,KAAK,iEAER;IAGD,IAAI,MAAM,gDAET;IAGD,IAAI,MAAM,gDAET;IAGD,IAAI,IAAI,oBAEP;gBAEW,MAAM,EAAE,S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IAED,KAAK,CAAC,MAAM,CAAC,IAAY,EAAE,IAAY;QACnC,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,CACpB,sBAAsB,CAAC,SAAS,CAAC;YAC7B,EAAE,EAAE,kBAAkB,CAAC,gBAAgB;YACvC,oEAAoE;YACpE,8DAA8D;YAC9D,8EAA8E;YAC9E,IAAI,EAAE,UAAU,CAAC,GAAG,IAAI,IAAI,IAAI,QAAQ,CAAC;SAC5C,CAAC,CACL,CAAC;IACN,CAAC;IAED,IAAI;QACA,OAAO,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IAChC,CAAC;CACJ"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import type { MaybePromiseLike } from "@yume-chan/async";
|
|
2
|
-
import type { MaybeConsumable, ReadableStream, WritableStream } from "@yume-chan/stream-extra";
|
|
3
|
-
import type { Adb, AdbSocket } from "../../../adb.js";
|
|
4
|
-
export interface AdbSubprocessProtocol {
|
|
5
|
-
/**
|
|
6
|
-
* A WritableStream that writes to the `stdin` stream.
|
|
7
|
-
*/
|
|
8
|
-
readonly stdin: WritableStream<MaybeConsumable<Uint8Array>>;
|
|
9
|
-
/**
|
|
10
|
-
* The `stdout` stream of the process.
|
|
11
|
-
*/
|
|
12
|
-
readonly stdout: ReadableStream<Uint8Array>;
|
|
13
|
-
/**
|
|
14
|
-
* The `stderr` stream of the process.
|
|
15
|
-
*
|
|
16
|
-
* Note: Some `AdbSubprocessProtocol` doesn't separate `stdout` and `stderr`,
|
|
17
|
-
* All output will be sent to `stdout`.
|
|
18
|
-
*/
|
|
19
|
-
readonly stderr: ReadableStream<Uint8Array>;
|
|
20
|
-
/**
|
|
21
|
-
* A `Promise` that resolves to the exit code of the process.
|
|
22
|
-
*
|
|
23
|
-
* Note: Some `AdbSubprocessProtocol` doesn't support exit code,
|
|
24
|
-
* They will always resolve it with `0`.
|
|
25
|
-
*/
|
|
26
|
-
readonly exit: Promise<number>;
|
|
27
|
-
/**
|
|
28
|
-
* Resizes the current shell.
|
|
29
|
-
*
|
|
30
|
-
* Some `AdbSubprocessProtocol`s may not support resizing
|
|
31
|
-
* and will ignore calls to this method.
|
|
32
|
-
*/
|
|
33
|
-
resize(rows: number, cols: number): MaybePromiseLike<void>;
|
|
34
|
-
/**
|
|
35
|
-
* Kills the current process.
|
|
36
|
-
*/
|
|
37
|
-
kill(): MaybePromiseLike<void>;
|
|
38
|
-
}
|
|
39
|
-
export interface AdbSubprocessProtocolConstructor {
|
|
40
|
-
/** Returns `true` if the `adb` instance supports this shell */
|
|
41
|
-
isSupported(adb: Adb): MaybePromiseLike<boolean>;
|
|
42
|
-
/** Spawns an executable in PTY (interactive) mode. */
|
|
43
|
-
pty(adb: Adb, command: string): MaybePromiseLike<AdbSubprocessProtocol>;
|
|
44
|
-
/** Spawns an executable and pipe the output. */
|
|
45
|
-
raw(adb: Adb, command: string): MaybePromiseLike<AdbSubprocessProtocol>;
|
|
46
|
-
/** Creates a new `AdbShell` by attaching to an exist `AdbSocket` */
|
|
47
|
-
new (socket: AdbSocket): AdbSubprocessProtocol;
|
|
48
|
-
}
|
|
49
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/commands/subprocess/protocols/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EACR,eAAe,EACf,cAAc,EACd,cAAc,EACjB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,GAAG,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEtD,MAAM,WAAW,qBAAqB;IAClC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;IAE5D;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAE5C;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,CAAC;IAE5C;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;IAE/B;;;;;OAKG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IAE3D;;OAEG;IACH,IAAI,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,gCAAgC;IAC7C,+DAA+D;IAC/D,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAEjD,sDAAsD;IACtD,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IAExE,gDAAgD;IAChD,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAAC,qBAAqB,CAAC,CAAC;IAExE,oEAAoE;IACpE,KAAK,MAAM,EAAE,SAAS,GAAG,qBAAqB,CAAC;CAClD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/commands/subprocess/protocols/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { ConcatStringStream, TextDecoderStream } from "@yume-chan/stream-extra";
|
|
2
|
-
|
|
3
|
-
import { AdbCommandBase } from "../base.js";
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
AdbSubprocessProtocol,
|
|
7
|
-
AdbSubprocessProtocolConstructor,
|
|
8
|
-
} from "./protocols/index.js";
|
|
9
|
-
import {
|
|
10
|
-
AdbSubprocessNoneProtocol,
|
|
11
|
-
AdbSubprocessShellProtocol,
|
|
12
|
-
} from "./protocols/index.js";
|
|
13
|
-
|
|
14
|
-
export interface AdbSubprocessOptions {
|
|
15
|
-
/**
|
|
16
|
-
* A list of `AdbSubprocessProtocolConstructor`s to be used.
|
|
17
|
-
*
|
|
18
|
-
* Different `AdbSubprocessProtocol` has different capabilities, thus requires specific adaptations.
|
|
19
|
-
* Check their documentations for details.
|
|
20
|
-
*
|
|
21
|
-
* The first protocol whose `isSupported` returns `true` will be used.
|
|
22
|
-
* If no `AdbSubprocessProtocol` is supported, an error will be thrown.
|
|
23
|
-
*
|
|
24
|
-
* @default [AdbSubprocessShellProtocol, AdbSubprocessNoneProtocol]
|
|
25
|
-
*/
|
|
26
|
-
protocols: AdbSubprocessProtocolConstructor[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const DEFAULT_OPTIONS: AdbSubprocessOptions = {
|
|
30
|
-
protocols: [AdbSubprocessShellProtocol, AdbSubprocessNoneProtocol],
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export interface AdbSubprocessWaitResult {
|
|
34
|
-
stdout: string;
|
|
35
|
-
stderr: string;
|
|
36
|
-
exitCode: number;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class AdbSubprocess extends AdbCommandBase {
|
|
40
|
-
async #createProtocol(
|
|
41
|
-
mode: "pty" | "raw",
|
|
42
|
-
command?: string | string[],
|
|
43
|
-
options?: Partial<AdbSubprocessOptions>,
|
|
44
|
-
): Promise<AdbSubprocessProtocol> {
|
|
45
|
-
const { protocols } = { ...DEFAULT_OPTIONS, ...options };
|
|
46
|
-
|
|
47
|
-
let Constructor: AdbSubprocessProtocolConstructor | undefined;
|
|
48
|
-
for (const item of protocols) {
|
|
49
|
-
// It's async so can't use `Array#find`
|
|
50
|
-
if (await item.isSupported(this.adb)) {
|
|
51
|
-
Constructor = item;
|
|
52
|
-
break;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (!Constructor) {
|
|
57
|
-
throw new Error("No specified protocol is supported by the device");
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (Array.isArray(command)) {
|
|
61
|
-
command = command.join(" ");
|
|
62
|
-
} else if (command === undefined) {
|
|
63
|
-
// spawn the default shell
|
|
64
|
-
command = "";
|
|
65
|
-
}
|
|
66
|
-
return await Constructor[mode](this.adb, command);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Spawns an executable in PTY mode.
|
|
71
|
-
*
|
|
72
|
-
* Redirection mode is enough for most simple commands, but PTY mode is required for
|
|
73
|
-
* commands that manipulate the terminal, such as `vi` and `less`.
|
|
74
|
-
* @param command The command to run. If omitted, the default shell will be spawned.
|
|
75
|
-
* @param options The options for creating the `AdbSubprocessProtocol`
|
|
76
|
-
* @returns A new `AdbSubprocessProtocol` instance connecting to the spawned process.
|
|
77
|
-
*/
|
|
78
|
-
shell(
|
|
79
|
-
command?: string | string[],
|
|
80
|
-
options?: Partial<AdbSubprocessOptions>,
|
|
81
|
-
): Promise<AdbSubprocessProtocol> {
|
|
82
|
-
return this.#createProtocol("pty", command, options);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Spawns an executable and redirect the standard input/output stream.
|
|
87
|
-
*
|
|
88
|
-
* Redirection mode is enough for most simple commands, but PTY mode is required for
|
|
89
|
-
* commands that manipulate the terminal, such as `vi` and `less`.
|
|
90
|
-
* @param command The command to run, or an array of strings containing both command and args.
|
|
91
|
-
* @param options The options for creating the `AdbSubprocessProtocol`
|
|
92
|
-
* @returns A new `AdbSubprocessProtocol` instance connecting to the spawned process.
|
|
93
|
-
*/
|
|
94
|
-
spawn(
|
|
95
|
-
command: string | string[],
|
|
96
|
-
options?: Partial<AdbSubprocessOptions>,
|
|
97
|
-
): Promise<AdbSubprocessProtocol> {
|
|
98
|
-
return this.#createProtocol("raw", command, options);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Spawns a new process, waits until it exits, and returns the entire output.
|
|
103
|
-
* @param command The command to run
|
|
104
|
-
* @param options The options for creating the `AdbSubprocessProtocol`
|
|
105
|
-
* @returns The entire output of the command
|
|
106
|
-
*/
|
|
107
|
-
async spawnAndWait(
|
|
108
|
-
command: string | string[],
|
|
109
|
-
options?: Partial<AdbSubprocessOptions>,
|
|
110
|
-
): Promise<AdbSubprocessWaitResult> {
|
|
111
|
-
const process = await this.spawn(command, options);
|
|
112
|
-
|
|
113
|
-
const [stdout, stderr, exitCode] = await Promise.all([
|
|
114
|
-
process.stdout
|
|
115
|
-
.pipeThrough(new TextDecoderStream())
|
|
116
|
-
.pipeThrough(new ConcatStringStream()),
|
|
117
|
-
process.stderr
|
|
118
|
-
.pipeThrough(new TextDecoderStream())
|
|
119
|
-
.pipeThrough(new ConcatStringStream()),
|
|
120
|
-
process.exit,
|
|
121
|
-
]);
|
|
122
|
-
|
|
123
|
-
return {
|
|
124
|
-
stdout,
|
|
125
|
-
stderr,
|
|
126
|
-
exitCode,
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Spawns a new process, waits until it exits, and returns the entire output.
|
|
132
|
-
* @param command The command to run
|
|
133
|
-
* @returns The entire output of the command
|
|
134
|
-
*/
|
|
135
|
-
async spawnAndWaitLegacy(command: string | string[]): Promise<string> {
|
|
136
|
-
const { stdout } = await this.spawnAndWait(command, {
|
|
137
|
-
protocols: [AdbSubprocessNoneProtocol],
|
|
138
|
-
});
|
|
139
|
-
return stdout;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import type { MaybeConsumable, WritableStream } from "@yume-chan/stream-extra";
|
|
2
|
-
import { ReadableStream } from "@yume-chan/stream-extra";
|
|
3
|
-
|
|
4
|
-
import type { Adb, AdbSocket } from "../../../adb.js";
|
|
5
|
-
|
|
6
|
-
import type { AdbSubprocessProtocol } from "./types.js";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* The legacy shell
|
|
10
|
-
*
|
|
11
|
-
* Features:
|
|
12
|
-
* * `stderr`: No
|
|
13
|
-
* * `exit` exit code: No
|
|
14
|
-
* * `resize`: No
|
|
15
|
-
*/
|
|
16
|
-
export class AdbSubprocessNoneProtocol implements AdbSubprocessProtocol {
|
|
17
|
-
static isSupported() {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static async pty(adb: Adb, command: string) {
|
|
22
|
-
return new AdbSubprocessNoneProtocol(
|
|
23
|
-
await adb.createSocket(`shell:${command}`),
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
static async raw(adb: Adb, command: string) {
|
|
28
|
-
// `shell,raw:${command}` also triggers raw mode,
|
|
29
|
-
// But is not supported on Android version <7.
|
|
30
|
-
return new AdbSubprocessNoneProtocol(
|
|
31
|
-
await adb.createSocket(`exec:${command}`),
|
|
32
|
-
);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
readonly #socket: AdbSocket;
|
|
36
|
-
|
|
37
|
-
// Legacy shell forwards all data to stdin.
|
|
38
|
-
get stdin(): WritableStream<MaybeConsumable<Uint8Array>> {
|
|
39
|
-
return this.#socket.writable;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Legacy shell mixes stdout and stderr.
|
|
44
|
-
*/
|
|
45
|
-
get stdout(): ReadableStream<Uint8Array> {
|
|
46
|
-
return this.#socket.readable;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
#stderr: ReadableStream<Uint8Array>;
|
|
50
|
-
/**
|
|
51
|
-
* `stderr` will always be empty.
|
|
52
|
-
*/
|
|
53
|
-
get stderr(): ReadableStream<Uint8Array> {
|
|
54
|
-
return this.#stderr;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
#exit: Promise<number>;
|
|
58
|
-
get exit() {
|
|
59
|
-
return this.#exit;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
constructor(socket: AdbSocket) {
|
|
63
|
-
this.#socket = socket;
|
|
64
|
-
|
|
65
|
-
this.#stderr = new ReadableStream({
|
|
66
|
-
start: async (controller) => {
|
|
67
|
-
await this.#socket.closed;
|
|
68
|
-
controller.close();
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
this.#exit = socket.closed.then(() => 0);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
resize() {
|
|
75
|
-
// Not supported, but don't throw.
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async kill() {
|
|
79
|
-
await this.#socket.close();
|
|
80
|
-
}
|
|
81
|
-
}
|