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

Unverified Commit 7056feb3 authored by Simon Chan's avatar Simon Chan
Browse files

refactor: migrate to ES private fields

parent 433f9b98
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ export default class AdbWebCredentialStore implements AdbCredentialStore {
     *
     * @returns The private key in PKCS #8 format.
     */
    public async generateKey(): Promise<Uint8Array> {
    async generateKey(): Promise<Uint8Array> {
        const { privateKey: cryptoKey } = await crypto.subtle.generateKey(
            {
                name: "RSASSA-PKCS1-v1_5",
@@ -97,7 +97,7 @@ export default class AdbWebCredentialStore implements AdbCredentialStore {
     *
     * This method returns a generator, so `for await...of...` loop should be used to read the key.
     */
    public async *iterateKeys(): AsyncGenerator<Uint8Array, void, void> {
    async *iterateKeys(): AsyncGenerator<Uint8Array, void, void> {
        for (const key of await getAllKeys()) {
            yield key;
        }
+7 −7
Original line number Diff line number Diff line
@@ -46,26 +46,26 @@ declare global {
}

export default class AdbDaemonDirectSocketsDevice implements AdbDaemonDevice {
    public static isSupported(): boolean {
    static isSupported(): boolean {
        return typeof globalThis.TCPSocket !== "undefined";
    }

    public readonly serial: string;
    readonly serial: string;

    public readonly host: string;
    readonly host: string;

    public readonly port: number;
    readonly port: number;

    public name: string | undefined;
    name: string | undefined;

    public constructor(host: string, port = 5555, name?: string) {
    constructor(host: string, port = 5555, name?: string) {
        this.host = host;
        this.port = port;
        this.serial = `${host}:${port}`;
        this.name = name;
    }

    public async connect() {
    async connect() {
        const socket = new globalThis.TCPSocket(this.host, this.port, {
            noDelay: true,
        });
+11 −11
Original line number Diff line number Diff line
@@ -77,16 +77,16 @@ class Uint8ArrayExactReadable implements ExactReadable {
    #data: Uint8Array;
    #position: number;

    public get position() {
    get position() {
        return this.#position;
    }

    public constructor(data: Uint8Array) {
    constructor(data: Uint8Array) {
        this.#data = data;
        this.#position = 0;
    }

    public readExactly(length: number): Uint8Array {
    readExactly(length: number): Uint8Array {
        const result = this.#data.subarray(
            this.#position,
            this.#position + length,
@@ -100,16 +100,16 @@ export class AdbDaemonWebUsbConnection
    implements ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>>
{
    #readable: ReadableStream<AdbPacketData>;
    public get readable() {
    get readable() {
        return this.#readable;
    }

    #writable: WritableStream<Consumable<AdbPacketInit>>;
    public get writable() {
    get writable() {
        return this.#writable;
    }

    public constructor(
    constructor(
        device: USBDevice,
        inEndpoint: USBEndpoint,
        outEndpoint: USBEndpoint,
@@ -249,15 +249,15 @@ export class AdbDaemonWebUsbDevice implements AdbDaemonDevice {
    #usbManager: USB;

    #raw: USBDevice;
    public get raw() {
    get raw() {
        return this.#raw;
    }

    public get serial(): string {
    get serial(): string {
        return this.#raw.serialNumber!;
    }

    public get name(): string {
    get name(): string {
        return this.#raw.productName!;
    }

@@ -267,7 +267,7 @@ export class AdbDaemonWebUsbDevice implements AdbDaemonDevice {
     * @param device The `USBDevice` instance obtained elsewhere.
     * @param filters The filters to use when searching for ADB interface. Defaults to {@link ADB_DEFAULT_DEVICE_FILTER}.
     */
    public constructor(
    constructor(
        device: USBDevice,
        filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER],
        usbManager: USB,
@@ -281,7 +281,7 @@ export class AdbDaemonWebUsbDevice implements AdbDaemonDevice {
     * Claim the device and create a pair of `AdbPacket` streams to the ADB interface.
     * @returns The pair of `AdbPacket` streams.
     */
    public async connect(): Promise<
    async connect(): Promise<
        ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>>
    > {
        if (!this.#raw.opened) {
+4 −4
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ export class AdbDaemonWebUsbDeviceManager {
     *
     * May be `undefined` if current runtime does not support WebUSB.
     */
    public static readonly BROWSER =
    static readonly BROWSER =
        typeof globalThis.navigator !== "undefined" &&
        !!globalThis.navigator.usb
            ? new AdbDaemonWebUsbDeviceManager(globalThis.navigator.usb)
@@ -20,7 +20,7 @@ export class AdbDaemonWebUsbDeviceManager {
     * Create a new instance of {@link AdbDaemonWebUsbDeviceManager} using the specified WebUSB implementation.
     * @param usbManager A WebUSB compatible interface.
     */
    public constructor(usbManager: USB) {
    constructor(usbManager: USB) {
        this.#usbManager = usbManager;
    }

@@ -37,7 +37,7 @@ export class AdbDaemonWebUsbDeviceManager {
     * @returns An {@link AdbDaemonWebUsbDevice} instance if the user selected a device,
     * or `undefined` if the user cancelled the device picker.
     */
    public async requestDevice(
    async requestDevice(
        filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER],
    ): Promise<AdbDaemonWebUsbDevice | undefined> {
        try {
@@ -67,7 +67,7 @@ export class AdbDaemonWebUsbDeviceManager {
     * Defaults to {@link ADB_DEFAULT_DEVICE_FILTER}.
     * @returns An array of {@link AdbDaemonWebUsbDevice} instances for all connected and authenticated devices.
     */
    public async getDevices(
    async getDevices(
        filters: AdbDeviceFilter[] = [ADB_DEFAULT_DEVICE_FILTER],
    ): Promise<AdbDaemonWebUsbDevice[]> {
        const devices = await this.#usbManager.getDevices();
+8 −8
Original line number Diff line number Diff line
@@ -2,27 +2,27 @@ export class AdbDaemonWebUsbDeviceWatcher {
    #callback: (newDeviceSerial?: string) => void;
    #usbManager: USB;

    public constructor(callback: (newDeviceSerial?: string) => void, usb: USB) {
    constructor(callback: (newDeviceSerial?: string) => void, usb: USB) {
        this.#callback = callback;
        this.#usbManager = usb;

        this.#usbManager.addEventListener("connect", this.handleConnect);
        this.#usbManager.addEventListener("disconnect", this.handleDisconnect);
        this.#usbManager.addEventListener("connect", this.#handleConnect);
        this.#usbManager.addEventListener("disconnect", this.#handleDisconnect);
    }

    public dispose(): void {
        this.#usbManager.removeEventListener("connect", this.handleConnect);
    dispose(): void {
        this.#usbManager.removeEventListener("connect", this.#handleConnect);
        this.#usbManager.removeEventListener(
            "disconnect",
            this.handleDisconnect,
            this.#handleDisconnect,
        );
    }

    private handleConnect = (e: USBConnectionEvent) => {
    #handleConnect = (e: USBConnectionEvent) => {
        this.#callback(e.device.serialNumber);
    };

    private handleDisconnect = () => {
    #handleDisconnect = () => {
        this.#callback();
    };
}
Loading