Skip to content

Commit b3db76b

Browse files
committed
fix(scrcpy): options.setListDisplays not work for some versions
fixes #567
1 parent 7056feb commit b3db76b

File tree

10 files changed

+126
-2
lines changed

10 files changed

+126
-2
lines changed

.prettierrc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
trailingComma: all
2+
tabWidth: 4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from "./1_16.js";
22
export * from "./1_22.js";
33
export * from "./2_0.js";
4+
export * from "./2_1.js";
45
export * from "./latest.js";
56
export * from "./types.js";
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { AdbScrcpyOptions2_0 } from "./2_0.js";
1+
import { AdbScrcpyOptions2_1 } from "./2_1.js";
22

3-
export class AdbScrcpyOptionsLatest extends AdbScrcpyOptions2_0 {}
3+
export class AdbScrcpyOptionsLatest extends AdbScrcpyOptions2_1 {}

libraries/scrcpy/src/options/1_16/options.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,12 @@ describe("ScrcpyOptions1_16", () => {
2222
]);
2323
});
2424
});
25+
26+
describe("setListDisplays", () => {
27+
it("should set `display` to `-1`", () => {
28+
const options = new ScrcpyOptions1_16({});
29+
options.setListDisplays();
30+
expect(options.value.displayId).toBe(-1);
31+
});
32+
});
2533
});
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { describe, expect, it } from "@jest/globals";
2+
3+
import { ScrcpyOptions1_17 } from "./1_17.js";
4+
5+
describe("ScrcpyOptions1_17", () => {
6+
it("should share `value` with `base`", () => {
7+
const options = new ScrcpyOptions1_17({});
8+
expect(options.value).toBe(options["_base"].value);
9+
});
10+
11+
describe("setListDisplays", () => {
12+
it("should set `displayId` to `-1`", () => {
13+
const options = new ScrcpyOptions1_17({});
14+
options.setListDisplays();
15+
expect(options.value.displayId).toBe(-1);
16+
});
17+
});
18+
19+
describe("setListEncoders", () => {
20+
it("should set `encoderName` to `_`", () => {
21+
const options = new ScrcpyOptions1_17({});
22+
options.setListEncoders();
23+
expect(options.value.encoderName).toBe("_");
24+
});
25+
});
26+
});
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { describe, expect, it } from "@jest/globals";
2+
3+
import { ScrcpyOptions1_18 } from "./1_18.js";
4+
5+
describe("ScrcpyOptions1_18", () => {
6+
it("should share `value` with `base`", () => {
7+
const options = new ScrcpyOptions1_18({});
8+
expect(options.value).toBe(options["_base"].value);
9+
});
10+
11+
describe("setListDisplays", () => {
12+
it("should set `displayId` to `-1`", () => {
13+
const options = new ScrcpyOptions1_18({});
14+
options.setListDisplays();
15+
expect(options.value.displayId).toBe(-1);
16+
});
17+
});
18+
19+
describe("setListEncoders", () => {
20+
it("should set `encoderName` to `_`", () => {
21+
const options = new ScrcpyOptions1_18({});
22+
options.setListEncoders();
23+
expect(options.value.encoderName).toBe("_");
24+
});
25+
});
26+
});

libraries/scrcpy/src/options/1_25/options.spec.ts

+8
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@ describe("ScrcpyOptions1_25", () => {
1414
).createScrollController();
1515
expect(controller1_25).not.toBe(controller1_24);
1616
});
17+
18+
describe("setListDisplays", () => {
19+
it("should set `display` to `-1`", () => {
20+
const options = new ScrcpyOptions1_25({});
21+
options.setListDisplays();
22+
expect(options.value.displayId).toBe(-1);
23+
});
24+
});
1725
});
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { describe, expect, it } from "@jest/globals";
2+
3+
import { ScrcpyOptions2_0 } from "./2_0.js";
4+
5+
describe("ScrcpyOptions2_0", () => {
6+
describe("setListDisplays", () => {
7+
it("should set `listDisplays` to `true`", () => {
8+
const options = new ScrcpyOptions2_0({});
9+
options.setListDisplays();
10+
expect(options.value.listDisplays).toBe(true);
11+
});
12+
});
13+
14+
describe("setListEncoders", () => {
15+
it("should set `listEncoders` to `true`", () => {
16+
const options = new ScrcpyOptions2_0({});
17+
options.setListEncoders();
18+
expect(options.value.listEncoders).toBe(true);
19+
});
20+
});
21+
});
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { describe, expect, it } from "@jest/globals";
2+
3+
import { ScrcpyOptions2_1 } from "./2_1.js";
4+
5+
describe("ScrcpyOptions2_1", () => {
6+
describe("setListDisplays", () => {
7+
it("should set `listDisplays` to `true`", () => {
8+
const options = new ScrcpyOptions2_1({});
9+
options.setListDisplays();
10+
expect(options.value.listDisplays).toBe(true);
11+
});
12+
});
13+
14+
describe("setListEncoders", () => {
15+
it("should set `listEncoders` to `true`", () => {
16+
const options = new ScrcpyOptions2_1({});
17+
options.setListEncoders();
18+
expect(options.value.listEncoders).toBe(true);
19+
});
20+
});
21+
});

libraries/scrcpy/src/options/types.ts

+11
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ export abstract class ScrcpyOptionsBase<
141141
constructor(base: B, value: Required<T>) {
142142
this._base = base;
143143
this.value = value;
144+
this.#setValue();
145+
}
146+
147+
#setValue() {
148+
// Share `value` with `_base` class,
149+
// so updating `_base.value` in `_base.setListEncoders()`/
150+
// `_base.setListDisplays()` will also update `this.value`.
151+
Object.assign(this._base, { value: this.value });
152+
if (this._base instanceof ScrcpyOptionsBase) {
153+
this._base.#setValue();
154+
}
144155
}
145156

146157
abstract serialize(): string[];

0 commit comments

Comments
 (0)