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

Unverified Commit 2c8912e9 authored by Simon Chan's avatar Simon Chan
Browse files

refactor: remove TypeScript enum and namespace to improve tree-shaking

parent b1787e8e
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
import type { AdbFeature } from "./features.js";

export enum AdbBannerKey {
    Product = "ro.product.name",
    Model = "ro.product.model",
    Device = "ro.product.device",
    Features = "features",
}
export const AdbBannerKey = {
    Product: "ro.product.name",
    Model: "ro.product.model",
    Device: "ro.product.device",
    Features: "features",
} as const;

export type AdbBannerKey = (typeof AdbBannerKey)[keyof typeof AdbBannerKey];

export class AdbBanner {
    static parse(banner: string) {
+36 −30
Original line number Diff line number Diff line
@@ -3,9 +3,13 @@ import Struct, { StructEmptyError } from "@yume-chan/struct";

import type { Adb } from "../adb.js";

const Version = new Struct({ littleEndian: true }).uint32("version");
const Version =
    /* #__PURE__ */
    new Struct({ littleEndian: true }).uint32("version");

export const AdbFrameBufferV1 = new Struct({ littleEndian: true })
export const AdbFrameBufferV1 =
    /* #__PURE__ */
    new Struct({ littleEndian: true })
        .uint32("bpp")
        .uint32("size")
        .uint32("width")
@@ -22,7 +26,9 @@ export const AdbFrameBufferV1 = new Struct({ littleEndian: true })

export type AdbFrameBufferV1 = (typeof AdbFrameBufferV1)["TDeserializeResult"];

export const AdbFrameBufferV2 = new Struct({ littleEndian: true })
export const AdbFrameBufferV2 =
    /* #__PURE__ */
    new Struct({ littleEndian: true })
        .uint32("bpp")
        .uint32("colorSpace")
        .uint32("size")
+8 −6
Original line number Diff line number Diff line
@@ -14,7 +14,9 @@ export interface AdbForwardListener {
    remoteName: string;
}

const AdbReverseStringResponse = new Struct()
const AdbReverseStringResponse =
    /* #__PURE__ */
    new Struct()
        .string("length", { length: 4 })
        .string("content", { lengthField: "length", lengthFieldRadix: 16 });

@@ -33,9 +35,9 @@ export class AdbReverseNotSupportedError extends AdbReverseError {
    }
}

const AdbReverseErrorResponse = new Struct()
    .concat(AdbReverseStringResponse)
    .postDeserialize((value) => {
const AdbReverseErrorResponse =
    /* #__PURE__ */
    new Struct().concat(AdbReverseStringResponse).postDeserialize((value) => {
        // https://issuetracker.google.com/issues/37066218
        // ADB on Android <9 can't create reverse tunnels when connected wirelessly (ADB over Wi-Fi),
        // and returns this confusing "more than one device/emulator" error.
+17 −12
Original line number Diff line number Diff line
@@ -19,17 +19,22 @@ import { encodeUtf8 } from "../../../utils/index.js";

import type { AdbSubprocessProtocol } from "./types.js";

export enum AdbShellProtocolId {
    Stdin,
    Stdout,
    Stderr,
    Exit,
    CloseStdin,
    WindowSizeChange,
}
export const AdbShellProtocolId = {
    Stdin: 0,
    Stdout: 1,
    Stderr: 2,
    Exit: 3,
    CloseStdin: 4,
    WindowSizeChange: 5,
} as const;

export type AdbShellProtocolId =
    (typeof AdbShellProtocolId)[keyof typeof AdbShellProtocolId];

// This packet format is used in both directions.
export const AdbShellProtocolPacket = new Struct({ littleEndian: true })
export const AdbShellProtocolPacket =
    /* #__PURE__ */
    new Struct({ littleEndian: true })
        .uint8("id", placeholder<AdbShellProtocolId>())
        .uint32("length")
        .uint8Array("data", { lengthField: "length" });
+12 −8
Original line number Diff line number Diff line
@@ -14,7 +14,9 @@ export interface AdbSyncEntry extends AdbSyncStat {
    name: string;
}

export const AdbSyncEntryResponse = new Struct({ littleEndian: true })
export const AdbSyncEntryResponse =
    /* #__PURE__ */
    new Struct({ littleEndian: true })
        .concat(AdbSyncLstatResponse)
        .uint32("nameLength")
        .string("name", { lengthField: "nameLength" });
@@ -22,7 +24,9 @@ export const AdbSyncEntryResponse = new Struct({ littleEndian: true })
export type AdbSyncEntryResponse =
    (typeof AdbSyncEntryResponse)["TDeserializeResult"];

export const AdbSyncEntry2Response = new Struct({ littleEndian: true })
export const AdbSyncEntry2Response =
    /* #__PURE__ */
    new Struct({ littleEndian: true })
        .concat(AdbSyncStatResponse)
        .uint32("nameLength")
        .string("name", { lengthField: "nameLength" });
Loading