Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit e3bfd159 authored by Simon Chan's avatar Simon Chan
Browse files

feat(bin): use `cmd` in `settings`

parent 9b0e06cd
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -33,12 +33,14 @@
    "dependencies": {
        "@yume-chan/adb": "workspace:^0.0.20",
        "@yume-chan/adb-server-node-tcp": "workspace:^0.0.19",
        "@yume-chan/android-bin": "workspace:^0.0.20",
        "@yume-chan/stream-extra": "workspace:^0.0.20",
        "commander": "^10.0.1",
        "source-map-support": "^0.5.21",
        "tslib": "^2.5.2"
    },
    "devDependencies": {
        "@types/node": "^20.2.1",
        "@yume-chan/eslint-config": "workspace:^1.0.0",
        "@yume-chan/tsconfig": "workspace:^1.0.0",
        "eslint": "^8.41.0",
+1332 −1423

File changed.

Preview size limit exceeded, changes collapsed.

+1 −1
Original line number Diff line number Diff line
// DO NOT MODIFY THIS FILE MANUALLY BUT DO COMMIT IT. It is generated and used by Rush.
{
  "pnpmShrinkwrapHash": "44a16b54cd6e6ab0bca0baf63df4de9d614e3857",
  "pnpmShrinkwrapHash": "749c0b292fb7bef0d2e3e177d6dc093da3453d0c",
  "preferredVersionsHash": "bf21a9e8fbc5a3846fb05b4fa0859e0917b2202f"
}
+4 −4
Original line number Diff line number Diff line
@@ -108,15 +108,15 @@ export class AdbSubprocess extends AdbCommandBase {
        command: string | string[],
        options?: Partial<AdbSubprocessOptions>
    ): Promise<AdbSubprocessWaitResult> {
        const shell = await this.spawn(command, options);
        const process = await this.spawn(command, options);

        const stdout = new GatherStringStream();
        const stderr = new GatherStringStream();

        const [, , exitCode] = await Promise.all([
            shell.stdout.pipeThrough(new DecodeUtf8Stream()).pipeTo(stdout),
            shell.stderr.pipeThrough(new DecodeUtf8Stream()).pipeTo(stderr),
            shell.exit,
            process.stdout.pipeThrough(new DecodeUtf8Stream()).pipeTo(stdout),
            process.stderr.pipeThrough(new DecodeUtf8Stream()).pipeTo(stderr),
            process.exit,
        ]);

        return {
+57 −24
Original line number Diff line number Diff line
import type { Adb, AdbSubprocessProtocolConstructor } from "@yume-chan/adb";
import type {
    Adb,
    AdbSubprocessProtocol,
    AdbSubprocessProtocolConstructor,
    AdbSubprocessWaitResult,
} from "@yume-chan/adb";
import {
    AdbCommandBase,
    AdbFeature,
    AdbSubprocessNoneProtocol,
    AdbSubprocessShellProtocol,
} from "@yume-chan/adb";
import { DecodeUtf8Stream, GatherStringStream } from "@yume-chan/stream-extra";

export class Cmd extends AdbCommandBase {
    private _supportsShellV2: boolean;
    private _supportsCmd: boolean;
    private _supportsAbb: boolean;
    private _supportsAbbExec: boolean;

    #supportsShellV2: boolean;
    public get supportsShellV2() {
        return this._supportsShellV2;
        return this.#supportsShellV2;
    }

    #supportsCmd: boolean;
    public get supportsCmd() {
        return this._supportsCmd;
        return this.#supportsCmd;
    }

    #supportsAbb: boolean;
    public get supportsAbb() {
        return this._supportsAbb;
        return this.#supportsAbb;
    }

    #supportsAbbExec: boolean;
    public get supportsAbbExec() {
        return this._supportsAbbExec;
        return this.#supportsAbbExec;
    }

    public constructor(adb: Adb) {
        super(adb);
        this._supportsShellV2 = adb.supportsFeature(AdbFeature.ShellV2);
        this._supportsCmd = adb.supportsFeature(AdbFeature.Cmd);
        this._supportsAbb = adb.supportsFeature(AdbFeature.Abb);
        this._supportsAbbExec = adb.supportsFeature(AdbFeature.AbbExec);
        this.#supportsShellV2 = adb.supportsFeature(AdbFeature.ShellV2);
        this.#supportsCmd = adb.supportsFeature(AdbFeature.Cmd);
        this.#supportsAbb = adb.supportsFeature(AdbFeature.Abb);
        this.#supportsAbbExec = adb.supportsFeature(AdbFeature.AbbExec);
    }

    public async spawn(
        shellProtocol: boolean,
        command: string,
        ...args: string[]
    ) {
    ): Promise<AdbSubprocessProtocol> {
        let supportsAbb: boolean;
        let supportsCmd: boolean = this.supportsCmd;
        let supportsCmd: boolean = this.#supportsCmd;
        let service: string;
        let Protocol: AdbSubprocessProtocolConstructor;
        if (shellProtocol) {
            supportsAbb = this._supportsAbb;
            supportsAbb = this.#supportsAbb;
            supportsCmd &&= this.supportsShellV2;
            service = "abb";
            Protocol = AdbSubprocessShellProtocol;
        } else {
            supportsAbb = this._supportsAbbExec;
            supportsAbb = this.#supportsAbbExec;
            service = "abb_exec";
            Protocol = AdbSubprocessNoneProtocol;
        }

        if (supportsAbb) {
            const socket = await this.adb.createSocket(
            return new Protocol(
                await this.adb.createSocket(
                    `${service}:${command}\0${args.join("\0")}\0`
                )
            );
            return new Protocol(socket);
        } else if (supportsCmd) {
        }

        if (supportsCmd) {
            return Protocol.raw(this.adb, `cmd ${command} ${args.join(" ")}`);
        } else {
        }

        throw new Error("Not supported");
    }

    public async spawnAndWait(
        command: string,
        ...args: string[]
    ): Promise<AdbSubprocessWaitResult> {
        const process = await this.spawn(true, command, ...args);

        const stdout = new GatherStringStream();
        const stderr = new GatherStringStream();

        const [, , exitCode] = await Promise.all([
            process.stdout.pipeThrough(new DecodeUtf8Stream()).pipeTo(stdout),
            process.stderr.pipeThrough(new DecodeUtf8Stream()).pipeTo(stderr),
            process.exit,
        ]);

        return {
            stdout: stdout.result,
            stderr: stderr.result,
            exitCode,
        };
    }
}
Loading