Skip to content

Commit

Permalink
Merge branch 'display-orientation'
Browse files Browse the repository at this point in the history
  • Loading branch information
Gasol committed Nov 6, 2024
2 parents 0345719 + bb466e4 commit 76383fa
Show file tree
Hide file tree
Showing 29 changed files with 164 additions and 84 deletions.
26 changes: 13 additions & 13 deletions apps/cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ program
});

function createClient() {
const opts: { H: string; P: number; } = program.opts();
const opts: { H: string; P: number } = program.opts();
const connection = new AdbServerNodeTcpConnector({
host: opts.H,
port: opts.P,
Expand All @@ -43,7 +43,7 @@ program
.usage("[-l]")
.description("list connected devices (-l for long output)")
.option("-l", "long output", false)
.action(async (options: { l: boolean; }) => {
.action(async (options: { l: boolean }) => {
function appendTransportInfo(key: string, value: string | undefined) {
if (value) {
return ` ${key}:${value}`;
Expand Down Expand Up @@ -100,21 +100,21 @@ async function createAdb(options: DeviceCommandOptions) {
const transport = await client.createTransport(
options.d
? {
usb: true,
}
usb: true,
}
: options.e
? {
? {
tcp: true,
}
: options.s !== undefined
? {
serial: options.s,
: options.s !== undefined
? {
serial: options.s,
}
: options.t !== undefined
? {
transportId: options.t,
}
: options.t !== undefined
? {
transportId: options.t,
}
: undefined,
: undefined,
);
const adb = new Adb(transport);
return adb;
Expand Down
11 changes: 4 additions & 7 deletions libraries/adb-daemon-webusb/src/device.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import type {
AdbDaemonDevice,
AdbPacketData,
AdbPacketInit,
} from "@gasol/adb";
import type { AdbDaemonDevice, AdbPacketData, AdbPacketInit } from "@gasol/adb";
import {
AdbPacketHeader,
AdbPacketSerializeStream,
Expand Down Expand Up @@ -83,7 +79,8 @@ class Uint8ArrayExactReadable implements ExactReadable {
}

export class AdbDaemonWebUsbConnection
implements ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>> {
implements ReadableWritablePair<AdbPacketData, Consumable<AdbPacketInit>>
{
#device: AdbDaemonWebUsbDevice;
get device() {
return this.#device;
Expand Down Expand Up @@ -220,7 +217,7 @@ export class AdbDaemonWebUsbConnection
// Add `payload` field to its type, it's assigned below.
const packet = AdbPacketHeader.deserialize(
stream,
) as AdbPacketHeader & { payload: Uint8Array; };
) as AdbPacketHeader & { payload: Uint8Array };

if (packet.magic !== (packet.command ^ 0xffffffff)) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion libraries/adb-scrcpy/src/connection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Adb, AdbSocket } from "@gasol/adb";
import { AdbReverseNotSupportedError, NOOP } from "@gasol/adb";
import { delay } from "@yume-chan/async";
import type { Disposable } from "@gasol/event";
import type {
Consumable,
Expand All @@ -14,6 +13,7 @@ import {
PushReadableStream,
} from "@gasol/stream-extra";
import type { ValueOrPromise } from "@gasol/struct";
import { delay } from "@yume-chan/async";

export interface AdbScrcpyConnectionOptions {
scid: number;
Expand Down
57 changes: 57 additions & 0 deletions libraries/adb-scrcpy/src/options/2_3.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import type { Adb } from "@gasol/adb";
import type {
ScrcpyDisplay,
ScrcpyEncoder,
ScrcpyOptionsInit2_3,
} from "@gasol/scrcpy";

import type { AdbScrcpyConnection } from "../connection.js";

import { AdbScrcpyOptions1_16 } from "./1_16.js";
import { AdbScrcpyOptions2_0 } from "./2_0.js";
import { AdbScrcpyOptions } from "./types.js";

export class AdbScrcpyOptions2_3 extends AdbScrcpyOptions<
// Only pick options that are used in this class,
// so changes in `ScrcpyOptionsInitX_XX` won't affect type assignability with this class
Pick<
ScrcpyOptionsInit2_3,
| "displayOrientation"
| "tunnelForward"
| "control"
| "sendDummyByte"
| "scid"
| "audio"
| "video"
>
> {
override async getEncoders(
adb: Adb,
path: string,
version: string,
): Promise<ScrcpyEncoder[]> {
return AdbScrcpyOptions2_0.getEncoders(adb, path, version, this);
}

override getDisplays(
adb: Adb,
path: string,
version: string,
): Promise<ScrcpyDisplay[]> {
return AdbScrcpyOptions1_16.getDisplays(adb, path, version, this);
}

override createConnection(adb: Adb): AdbScrcpyConnection {
return AdbScrcpyOptions1_16.createConnection(
adb,
{
scid: this.value.scid.value,
video: this.value.video,
audio: this.value.audio,
control: this.value.control,
sendDummyByte: this.value.sendDummyByte,
},
this.tunnelForwardOverride || this.value.tunnelForward,
);
}
}
2 changes: 1 addition & 1 deletion libraries/adb-scrcpy/src/options/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export abstract class AdbScrcpyOptions<
// but we need to pass an instance here.
// A normal `function` can be used as a constructor, and constructors can return
// any object to override the default return value.
function() {
function () {
return base;
} as never,
// HACK: `base.value` contains `SkipDefaultMark`, so it will be used as is,
Expand Down
3 changes: 2 additions & 1 deletion libraries/adb-server-node-tcp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ function nodeSocketToConnection(
* [Online Documentation](https://docs.tangoapp.dev/tango/server/client/)
*/
export class AdbServerNodeTcpConnector
implements AdbServerClient.ServerConnector {
implements AdbServerClient.ServerConnector
{
readonly spec: SocketConnectOpts;

readonly #listeners = new Map<string, Server>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import assert from "node:assert";
import { describe, it, mock } from "node:test";

import { PromiseResolver } from "@yume-chan/async";
import { ReadableStream, WritableStream } from "@gasol/stream-extra";
import { PromiseResolver } from "@yume-chan/async";

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import assert from "node:assert";
import { describe, it } from "node:test";

import { PromiseResolver } from "@yume-chan/async";
import type { ReadableStreamDefaultController } from "@gasol/stream-extra";
import { ReadableStream, WritableStream } from "@gasol/stream-extra";
import { PromiseResolver } from "@yume-chan/async";

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

Expand Down
2 changes: 1 addition & 1 deletion libraries/adb/src/commands/subprocess/protocols/shell.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PromiseResolver } from "@yume-chan/async";
import type {
PushReadableStreamController,
ReadableStream,
Expand All @@ -12,6 +11,7 @@ import {
} from "@gasol/stream-extra";
import type { StructValueType } from "@gasol/struct";
import Struct, { placeholder } from "@gasol/struct";
import { PromiseResolver } from "@yume-chan/async";

import type { Adb, AdbSocket } from "../../../adb.js";
import { AdbFeature } from "../../../features.js";
Expand Down
13 changes: 6 additions & 7 deletions libraries/adb/src/daemon/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { PromiseResolver } from "@yume-chan/async";
import type { Disposable } from "@gasol/event";
import type { ValueOrPromise } from "@gasol/struct";
import { EMPTY_UINT8_ARRAY } from "@gasol/struct";
import { PromiseResolver } from "@yume-chan/async";

import {
calculateBase64EncodedLength,
Expand Down Expand Up @@ -67,11 +67,10 @@ export interface AdbAuthenticator {
): AsyncIterable<AdbPacketData>;
}

export const AdbSignatureAuthenticator: AdbAuthenticator = async function*(
export const AdbSignatureAuthenticator: AdbAuthenticator = async function* (
credentialStore: AdbCredentialStore,
getNextRequest: () => Promise<AdbPacketData>,
): AsyncIterable<AdbPacketData> {
// eslint-disable-next-line @typescript-eslint/await-thenable
for await (const key of credentialStore.iterateKeys()) {
const packet = await getNextRequest();

Expand All @@ -89,7 +88,7 @@ export const AdbSignatureAuthenticator: AdbAuthenticator = async function*(
}
};

export const AdbPublicKeyAuthenticator: AdbAuthenticator = async function*(
export const AdbPublicKeyAuthenticator: AdbAuthenticator = async function* (
credentialStore: AdbCredentialStore,
getNextRequest: () => Promise<AdbPacketData>,
): AsyncIterable<AdbPacketData> {
Expand All @@ -100,7 +99,7 @@ export const AdbPublicKeyAuthenticator: AdbAuthenticator = async function*(
}

let privateKey: AdbPrivateKey | undefined;
// eslint-disable-next-line @typescript-eslint/await-thenable

for await (const key of credentialStore.iterateKeys()) {
privateKey = key;
break;
Expand All @@ -119,8 +118,8 @@ export const AdbPublicKeyAuthenticator: AdbAuthenticator = async function*(
: EMPTY_UINT8_ARRAY;
const publicKeyBuffer = new Uint8Array(
publicKeyBase64Length +
(nameBuffer.length ? nameBuffer.length + 1 : 0) + // Space character + name
1, // Null character
(nameBuffer.length ? nameBuffer.length + 1 : 0) + // Space character + name
1, // Null character
);

adbGeneratePublicKey(privateKey.buffer, publicKeyBuffer);
Expand Down
10 changes: 5 additions & 5 deletions libraries/adb/src/daemon/dispatcher.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import {
AsyncOperationManager,
PromiseResolver,
delay,
} from "@yume-chan/async";
import {
getUint32LittleEndian,
setUint32LittleEndian,
Expand All @@ -17,6 +12,11 @@ import {
WritableStream,
} from "@gasol/stream-extra";
import { EMPTY_UINT8_ARRAY, decodeUtf8, encodeUtf8 } from "@gasol/struct";
import {
AsyncOperationManager,
PromiseResolver,
delay,
} from "@yume-chan/async";

import type { AdbIncomingSocketHandler, AdbSocket, Closeable } from "../adb.js";

Expand Down
5 changes: 3 additions & 2 deletions libraries/adb/src/daemon/socket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PromiseResolver } from "@yume-chan/async";
import type { Disposable } from "@gasol/event";
import type {
PushReadableStreamController,
Expand All @@ -8,6 +7,7 @@ import type {
} from "@gasol/stream-extra";
import { MaybeConsumable, PushReadableStream } from "@gasol/stream-extra";
import { EMPTY_UINT8_ARRAY } from "@gasol/struct";
import { PromiseResolver } from "@yume-chan/async";

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

Expand All @@ -34,7 +34,8 @@ export interface AdbDaemonSocketInit extends AdbDaemonSocketInfo {
}

export class AdbDaemonSocketController
implements AdbDaemonSocketInfo, AdbSocket, Disposable {
implements AdbDaemonSocketInfo, AdbSocket, Disposable
{
readonly #dispatcher!: AdbPacketDispatcher;

readonly localId!: number;
Expand Down
2 changes: 1 addition & 1 deletion libraries/adb/src/daemon/transport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { PromiseResolver } from "@yume-chan/async";
import type { ReadableWritablePair } from "@gasol/stream-extra";
import {
AbortController,
Expand All @@ -7,6 +6,7 @@ import {
} from "@gasol/stream-extra";
import type { ValueOrPromise } from "@gasol/struct";
import { decodeUtf8, encodeUtf8 } from "@gasol/struct";
import { PromiseResolver } from "@yume-chan/async";

import type {
AdbIncomingSocketHandler,
Expand Down
14 changes: 7 additions & 7 deletions libraries/adb/src/server/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// cspell:ignore tport

import { PromiseResolver } from "@yume-chan/async";
import { getUint64LittleEndian } from "@gasol/no-data-view";
import type {
AbortSignal,
Expand All @@ -20,6 +19,7 @@ import {
decodeUtf8,
encodeUtf8,
} from "@gasol/struct";
import { PromiseResolver } from "@yume-chan/async";

import type { AdbIncomingSocketHandler, AdbSocket, Closeable } from "../adb.js";
import { AdbBanner } from "../banner.js";
Expand Down Expand Up @@ -352,7 +352,7 @@ export class AdbServerClient {
*/
async getDeviceFeatures(
device: AdbServerClient.DeviceSelector,
): Promise<{ transportId: bigint; features: AdbFeature[]; }> {
): Promise<{ transportId: bigint; features: AdbFeature[] }> {
// On paper, `host:features` is a host service (device features are cached in host),
// so it shouldn't use `createDeviceConnection`,
// which is used to forward the service to the device.
Expand Down Expand Up @@ -565,7 +565,7 @@ export namespace AdbServerClient {

export interface ServerConnection
extends ReadableWritablePair<Uint8Array, MaybeConsumable<Uint8Array>>,
Closeable {
Closeable {
get closed(): Promise<void>;
}

Expand Down Expand Up @@ -594,10 +594,10 @@ export namespace AdbServerClient {
* [Online Documentation](https://docs.tangoapp.dev/tango/server/selector/)
*/
export type DeviceSelector =
| { transportId: bigint; }
| { serial: string; }
| { usb: true; }
| { tcp: true; }
| { transportId: bigint }
| { serial: string }
| { usb: true }
| { tcp: true }
| undefined;

export interface Device {
Expand Down
2 changes: 1 addition & 1 deletion libraries/adb/src/server/transport.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PromiseResolver } from "@yume-chan/async";
import { AbortController } from "@gasol/stream-extra";
import type { ValueOrPromise } from "@gasol/struct";
import { PromiseResolver } from "@yume-chan/async";

import type {
AdbIncomingSocketHandler,
Expand Down
2 changes: 1 addition & 1 deletion libraries/adb/src/utils/auto-reset-event.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PromiseResolver } from "@yume-chan/async";
import type { Disposable } from "@gasol/event";
import { PromiseResolver } from "@yume-chan/async";

export class AutoResetEvent implements Disposable {
#set: boolean;
Expand Down
8 changes: 4 additions & 4 deletions libraries/android-bin/src/demo-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,10 @@ export class DemoMode extends AdbCommandBase {
command,
...(extra
? Object.entries(extra).flatMap(([key, value]) => [
"-e",
key,
value,
])
"-e",
key,
value,
])
: []),
]);
}
Expand Down
Loading

0 comments on commit 76383fa

Please sign in to comment.