Skip to content

Commit

Permalink
refactor: migrate to ES private fields
Browse files Browse the repository at this point in the history
  • Loading branch information
yume-chan committed Jul 11, 2023
1 parent 433f9b9 commit 7056feb
Show file tree
Hide file tree
Showing 108 changed files with 1,265 additions and 1,295 deletions.
4 changes: 2 additions & 2 deletions libraries/adb-credential-web/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions libraries/adb-daemon-direct-sockets/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
22 changes: 11 additions & 11 deletions libraries/adb-daemon-webusb/src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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!;
}

Expand All @@ -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,
Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions libraries/adb-daemon-webusb/src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions libraries/adb-daemon-webusb/src/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
}
8 changes: 4 additions & 4 deletions libraries/adb-daemon-ws/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ import {
} from "@yume-chan/stream-extra";

export default class AdbDaemonWebSocketDevice implements AdbDaemonDevice {
public readonly serial: string;
readonly serial: string;

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

public constructor(url: string, name?: string) {
constructor(url: string, name?: string) {
this.serial = url;
this.name = name;
}

public async connect() {
async connect() {
const socket = new WebSocket(this.serial);
socket.binaryType = "arraybuffer";

Expand Down
Loading

1 comment on commit 7056feb

@vercel
Copy link

@vercel vercel bot commented on 7056feb Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.