Skip to content

Commit

Permalink
feat(scrcpy): move version info to option classes
Browse files Browse the repository at this point in the history
  • Loading branch information
yume-chan committed Dec 23, 2024
1 parent a7a8497 commit cb44b63
Show file tree
Hide file tree
Showing 36 changed files with 189 additions and 116 deletions.
6 changes: 6 additions & 0 deletions .changeset/warm-badgers-burn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@yume-chan/adb-scrcpy": minor
"@yume-chan/scrcpy": minor
---

Move `version` info to option classes and provide default values
3 changes: 1 addition & 2 deletions libraries/adb-scrcpy/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export class AdbScrcpyClient {
static async start(
adb: Adb,
path: string,
version: string,
options: AdbScrcpyOptions<
Pick<ScrcpyOptions1_15.Init, "tunnelForward">
>,
Expand Down Expand Up @@ -151,7 +150,7 @@ export class AdbScrcpyClient {
"app_process",
/* unused */ "/",
"com.genymobile.scrcpy.Server",
version,
options.version,
...options.serialize(),
],
{
Expand Down
27 changes: 6 additions & 21 deletions libraries/adb-scrcpy/src/options/1_16.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ export class AdbScrcpyOptions1_16 extends AdbScrcpyOptions<
static async getEncoders(
adb: Adb,
path: string,
version: string,
options: AdbScrcpyOptions<
Pick<ScrcpyOptions1_16Impl.Init, "tunnelForward">
>,
): Promise<ScrcpyEncoder[]> {
const client = await AdbScrcpyClient.start(adb, path, version, options);
const client = await AdbScrcpyClient.start(adb, path, options);

const encoders: ScrcpyEncoder[] = [];

Expand All @@ -65,20 +64,14 @@ export class AdbScrcpyOptions1_16 extends AdbScrcpyOptions<
static async getDisplays(
adb: Adb,
path: string,
version: string,
options: AdbScrcpyOptions<
Pick<ScrcpyOptions1_16Impl.Init, "tunnelForward">
>,
): Promise<ScrcpyDisplay[]> {
try {
// Server will exit before opening connections when an invalid display id was given
// so `start` will throw an `AdbScrcpyExitedError`
const client = await AdbScrcpyClient.start(
adb,
path,
version,
options,
);
const client = await AdbScrcpyClient.start(adb, path, options);

// If the server didn't exit, manually stop it and throw an error
await client.close();
Expand All @@ -103,20 +96,12 @@ export class AdbScrcpyOptions1_16 extends AdbScrcpyOptions<
}
}

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

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

override createConnection(adb: Adb): AdbScrcpyConnection {
Expand Down
16 changes: 4 additions & 12 deletions libraries/adb-scrcpy/src/options/1_22.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,12 @@ export class AdbScrcpyOptions1_22 extends AdbScrcpyOptions<
"tunnelForward" | "control" | "sendDummyByte"
>
> {
override getEncoders(
adb: Adb,
path: string,
version: string,
): Promise<ScrcpyEncoder[]> {
return AdbScrcpyOptions1_16.getEncoders(adb, path, version, this);
override getEncoders(adb: Adb, path: string): Promise<ScrcpyEncoder[]> {
return AdbScrcpyOptions1_16.getEncoders(adb, path, this);
}

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

override createConnection(adb: Adb): AdbScrcpyConnection {
Expand Down
19 changes: 4 additions & 15 deletions libraries/adb-scrcpy/src/options/2_0.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,14 @@ export class AdbScrcpyOptions2_0 extends AdbScrcpyOptions<
static async getEncoders(
adb: Adb,
path: string,
version: string,
options: AdbScrcpyOptions<
Pick<ScrcpyOptions1_16Impl.Init, "tunnelForward">
>,
): Promise<ScrcpyEncoder[]> {
try {
// Similar to `AdbScrcpyOptions1_16.getDisplays`,
// server start procedure won't complete and `start `will throw
const client = await AdbScrcpyClient.start(
adb,
path,
version,
options,
);
const client = await AdbScrcpyClient.start(adb, path, options);

// If the server didn't exit, manually stop it and throw an error
await client.close();
Expand All @@ -61,17 +55,12 @@ export class AdbScrcpyOptions2_0 extends AdbScrcpyOptions<
override async getEncoders(
adb: Adb,
path: string,
version: string,
): Promise<ScrcpyEncoder[]> {
return AdbScrcpyOptions2_0.getEncoders(adb, path, version, this);
return AdbScrcpyOptions2_0.getEncoders(adb, path, this);
}

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

override createConnection(adb: Adb): AdbScrcpyConnection {
Expand Down
11 changes: 3 additions & 8 deletions libraries/adb-scrcpy/src/options/2_1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ export class AdbScrcpyOptions2_1 extends AdbScrcpyOptions<
override async getEncoders(
adb: Adb,
path: string,
version: string,
): Promise<ScrcpyEncoder[]> {
return AdbScrcpyOptions2_0.getEncoders(adb, path, version, this);
return AdbScrcpyOptions2_0.getEncoders(adb, path, this);
}

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

override createConnection(adb: Adb): AdbScrcpyConnection {
Expand Down
5 changes: 4 additions & 1 deletion libraries/scrcpy/src/1_15/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import {
export class ScrcpyOptions1_15 implements ScrcpyOptions<Init> {
static readonly Defaults = Defaults;

readonly version: string;

readonly value: Required<Init>;

get controlMessageTypes(): readonly ScrcpyControlMessageType[] {
Expand All @@ -47,8 +49,9 @@ export class ScrcpyOptions1_15 implements ScrcpyOptions<Init> {
return this.#clipboard;
}

constructor(init: Init) {
constructor(init: Init, version = "1.15") {
this.value = { ...Defaults, ...init };
this.version = version;

if (this.value.control) {
this.#clipboard = new ClipboardStream();
Expand Down
13 changes: 9 additions & 4 deletions libraries/scrcpy/src/1_15_1.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export {
ScrcpyOptions1_15 as ScrcpyOptions1_15_1,
ScrcpyOptions1_15Impl as ScrcpyOptions1_15_1Impl,
} from "./1_15/index.js";
import { ScrcpyOptions1_15 } from "./1_15/index.js";

export class ScrcpyOptions1_15_1 extends ScrcpyOptions1_15 {
constructor(init: ScrcpyOptions1_15.Init, version = "1.15.1") {
super(init, version);
}
}

export { ScrcpyOptions1_15Impl as ScrcpyOptions1_15_1Impl } from "./1_15/index.js";
13 changes: 9 additions & 4 deletions libraries/scrcpy/src/1_16.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export {
ScrcpyOptions1_15 as ScrcpyOptions1_16,
ScrcpyOptions1_15Impl as ScrcpyOptions1_16Impl,
} from "./1_15/index.js";
import { ScrcpyOptions1_15 } from "./1_15/index.js";

export class ScrcpyOptions1_16 extends ScrcpyOptions1_15 {
constructor(init: ScrcpyOptions1_15.Init, version = "1.16") {
super(init, version);
}
}

export { ScrcpyOptions1_15Impl as ScrcpyOptions1_16Impl } from "./1_15/index.js";
5 changes: 4 additions & 1 deletion libraries/scrcpy/src/1_17/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import {
export class ScrcpyOptions1_17 implements ScrcpyOptions<Init> {
static readonly Defaults = Defaults;

readonly version: string;

readonly value: Required<Init>;

get controlMessageTypes(): readonly ScrcpyControlMessageType[] {
Expand All @@ -51,8 +53,9 @@ export class ScrcpyOptions1_17 implements ScrcpyOptions<Init> {
return this.#clipboard;
}

constructor(init: Init) {
constructor(init: Init, version = "1.17") {
this.value = { ...Defaults, ...init };
this.version = version;

if (this.value.control) {
this.#clipboard = new ClipboardStream();
Expand Down
5 changes: 4 additions & 1 deletion libraries/scrcpy/src/1_18/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import {
export class ScrcpyOptions1_18 implements ScrcpyOptions<Init> {
static readonly Defaults = Defaults;

readonly version: string;

readonly value: Required<Init>;

get controlMessageTypes(): readonly ScrcpyControlMessageType[] {
Expand All @@ -51,8 +53,9 @@ export class ScrcpyOptions1_18 implements ScrcpyOptions<Init> {
return this.#clipboard;
}

constructor(init: Init) {
constructor(init: Init, version = "1.18") {
this.value = { ...Defaults, ...init };
this.version = version;

if (this.value.control) {
this.#clipboard = new ClipboardStream();
Expand Down
13 changes: 9 additions & 4 deletions libraries/scrcpy/src/1_19.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export {
ScrcpyOptions1_18 as ScrcpyOptions1_19,
ScrcpyOptions1_18Impl as ScrcpyOptions1_19Impl,
} from "./1_18/index.js";
import { ScrcpyOptions1_18 } from "./1_18/index.js";

export class ScrcpyOptions1_19 extends ScrcpyOptions1_18 {
constructor(init: ScrcpyOptions1_18.Init, version = "1.19") {
super(init, version);
}
}

export { ScrcpyOptions1_18Impl as ScrcpyOptions1_19Impl } from "./1_18/index.js";
13 changes: 9 additions & 4 deletions libraries/scrcpy/src/1_20.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export {
ScrcpyOptions1_18 as ScrcpyOptions1_20,
ScrcpyOptions1_18Impl as ScrcpyOptions1_20Impl,
} from "./1_18/index.js";
import { ScrcpyOptions1_18 } from "./1_18/index.js";

export class ScrcpyOptions1_20 extends ScrcpyOptions1_18 {
constructor(init: ScrcpyOptions1_18.Init, version = "1.20") {
super(init, version);
}
}

export { ScrcpyOptions1_18Impl as ScrcpyOptions1_20Impl } from "./1_18/index.js";
5 changes: 4 additions & 1 deletion libraries/scrcpy/src/1_21/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
export class ScrcpyOptions1_21 implements ScrcpyOptions<Init> {
static readonly Defaults = Defaults;

readonly version: string;

readonly value: Required<Init>;

get controlMessageTypes(): readonly ScrcpyControlMessageType[] {
Expand All @@ -52,8 +54,9 @@ export class ScrcpyOptions1_21 implements ScrcpyOptions<Init> {

#ackClipboardHandler: AckClipboardHandler | undefined;

constructor(init: Init) {
constructor(init: Init, version = "1.21") {
this.value = { ...Defaults, ...init };
this.version = version;

if (this.value.control && this.value.clipboardAutosync) {
this.#clipboard = new ClipboardStream();
Expand Down
2 changes: 1 addition & 1 deletion libraries/scrcpy/src/1_22/impl/scroll-controller.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { StructInit } from "@yume-chan/struct";
import { s32, struct } from "@yume-chan/struct";

import type { ScrcpyScrollController } from "../../base/index.js";
import type { ScrcpyInjectScrollControlMessage } from "../../latest.js";

import type { ScrcpyScrollController } from "../../base/index.js";
import { PrevImpl } from "./prev.js";

export const InjectScrollControlMessage = /* #__PURE__ */ (() =>
Expand Down
5 changes: 4 additions & 1 deletion libraries/scrcpy/src/1_22/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
export class ScrcpyOptions1_22 implements ScrcpyOptions<Init> {
static readonly Defaults = Defaults;

readonly version: string;

readonly value: Required<Init>;

get controlMessageTypes(): readonly ScrcpyControlMessageType[] {
Expand All @@ -52,8 +54,9 @@ export class ScrcpyOptions1_22 implements ScrcpyOptions<Init> {

#ackClipboardHandler: AckClipboardHandler | undefined;

constructor(init: Init) {
constructor(init: Init, version = "1.22") {
this.value = { ...Defaults, ...init };
this.version = version;

if (this.value.control && this.value.clipboardAutosync) {
this.#clipboard = new ClipboardStream();
Expand Down
5 changes: 4 additions & 1 deletion libraries/scrcpy/src/1_23/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
export class ScrcpyOptions1_23 implements ScrcpyOptions<Init> {
static readonly Defaults = Defaults;

readonly version: string;

readonly value: Required<Init>;

get controlMessageTypes(): readonly ScrcpyControlMessageType[] {
Expand All @@ -52,8 +54,9 @@ export class ScrcpyOptions1_23 implements ScrcpyOptions<Init> {

#ackClipboardHandler: AckClipboardHandler | undefined;

constructor(init: Init) {
constructor(init: Init, version = "1.23") {
this.value = { ...Defaults, ...init };
this.version = version;

if (this.value.control && this.value.clipboardAutosync) {
this.#clipboard = new ClipboardStream();
Expand Down
5 changes: 4 additions & 1 deletion libraries/scrcpy/src/1_24/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import {
export class ScrcpyOptions1_24 implements ScrcpyOptions<Init> {
static readonly Defaults = Defaults;

readonly version: string;

readonly value: Required<Init>;

get controlMessageTypes(): readonly ScrcpyControlMessageType[] {
Expand All @@ -52,8 +54,9 @@ export class ScrcpyOptions1_24 implements ScrcpyOptions<Init> {

#ackClipboardHandler: AckClipboardHandler | undefined;

constructor(init: Init) {
constructor(init: Init, version = "1.24") {
this.value = { ...Defaults, ...init };
this.version = version;

if (this.value.control && this.value.clipboardAutosync) {
this.#clipboard = new ClipboardStream();
Expand Down
Loading

0 comments on commit cb44b63

Please sign in to comment.