mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-03 17:59:50 +02:00
feat(scrcpy): set clipboard stream to undefined when it's disabled by options
This commit is contained in:
parent
dc6dacc84a
commit
e8d59b232e
3 changed files with 21 additions and 9 deletions
|
@ -120,17 +120,20 @@ export class ScrcpyOptions1_16 extends ScrcpyOptions<ScrcpyOptionsInit1_16> {
|
||||||
return SCRCPY_CONTROL_MESSAGE_TYPES_1_16;
|
return SCRCPY_CONTROL_MESSAGE_TYPES_1_16;
|
||||||
}
|
}
|
||||||
|
|
||||||
#clipboardController!: PushReadableStreamController<string>;
|
#clipboardController: PushReadableStreamController<string> | undefined;
|
||||||
#clipboard: ReadableStream<string>;
|
#clipboard: ReadableStream<string> | undefined;
|
||||||
override get clipboard() {
|
override get clipboard() {
|
||||||
return this.#clipboard;
|
return this.#clipboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(init: ScrcpyOptionsInit1_16) {
|
constructor(init: ScrcpyOptionsInit1_16) {
|
||||||
super(ScrcpyOptions0_00, init, ScrcpyOptions1_16.DEFAULTS);
|
super(ScrcpyOptions0_00, init, ScrcpyOptions1_16.DEFAULTS);
|
||||||
this.#clipboard = new PushReadableStream<string>((controller) => {
|
|
||||||
this.#clipboardController = controller;
|
if (this.value.control) {
|
||||||
});
|
this.#clipboard = new PushReadableStream<string>((controller) => {
|
||||||
|
this.#clipboardController = controller;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
serialize(): string[] {
|
serialize(): string[] {
|
||||||
|
@ -181,7 +184,7 @@ export class ScrcpyOptions1_16 extends ScrcpyOptions<ScrcpyOptionsInit1_16> {
|
||||||
|
|
||||||
async #parseClipboardMessage(stream: AsyncExactReadable) {
|
async #parseClipboardMessage(stream: AsyncExactReadable) {
|
||||||
const message = await ScrcpyClipboardDeviceMessage.deserialize(stream);
|
const message = await ScrcpyClipboardDeviceMessage.deserialize(stream);
|
||||||
await this.#clipboardController.enqueue(message.content);
|
await this.#clipboardController?.enqueue(message.content);
|
||||||
}
|
}
|
||||||
|
|
||||||
override async parseDeviceMessage(
|
override async parseDeviceMessage(
|
||||||
|
@ -200,9 +203,9 @@ export class ScrcpyOptions1_16 extends ScrcpyOptions<ScrcpyOptionsInit1_16> {
|
||||||
|
|
||||||
override endDeviceMessageStream(e?: unknown): void {
|
override endDeviceMessageStream(e?: unknown): void {
|
||||||
if (e) {
|
if (e) {
|
||||||
this.#clipboardController.error(e);
|
this.#clipboardController?.error(e);
|
||||||
} else {
|
} else {
|
||||||
this.#clipboardController.close();
|
this.#clipboardController?.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { Struct, string, u32, u64, u8 } from "@yume-chan/struct";
|
||||||
|
|
||||||
import type { ScrcpySetClipboardControlMessage } from "../control/index.js";
|
import type { ScrcpySetClipboardControlMessage } from "../control/index.js";
|
||||||
|
|
||||||
|
import type { ReadableStream } from "@yume-chan/stream-extra";
|
||||||
import type { ScrcpyOptionsInit1_18 } from "./1_18.js";
|
import type { ScrcpyOptionsInit1_18 } from "./1_18.js";
|
||||||
import { ScrcpyOptions1_18 } from "./1_18.js";
|
import { ScrcpyOptions1_18 } from "./1_18.js";
|
||||||
import { ScrcpyOptions, toScrcpyOptionValue } from "./types.js";
|
import { ScrcpyOptions, toScrcpyOptionValue } from "./types.js";
|
||||||
|
@ -74,6 +75,14 @@ export class ScrcpyOptions1_21 extends ScrcpyOptions<ScrcpyOptionsInit1_21> {
|
||||||
|
|
||||||
#clipboardAck = new Map<bigint, PromiseResolver<void>>();
|
#clipboardAck = new Map<bigint, PromiseResolver<void>>();
|
||||||
|
|
||||||
|
override get clipboard(): ReadableStream<string> | undefined {
|
||||||
|
if (this.value.clipboardAutosync) {
|
||||||
|
return super.clipboard;
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
constructor(init: ScrcpyOptionsInit1_21) {
|
constructor(init: ScrcpyOptionsInit1_21) {
|
||||||
super(ScrcpyOptions1_18, init, ScrcpyOptions1_21.DEFAULTS);
|
super(ScrcpyOptions1_18, init, ScrcpyOptions1_21.DEFAULTS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ export abstract class ScrcpyOptions<T extends object> {
|
||||||
|
|
||||||
readonly value: Required<T>;
|
readonly value: Required<T>;
|
||||||
|
|
||||||
get clipboard(): ReadableStream<string> {
|
get clipboard(): ReadableStream<string> | undefined {
|
||||||
return this.#base.clipboard;
|
return this.#base.clipboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue