Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 26fe7834 authored by Simon Chan's avatar Simon Chan
Browse files

feat(adb): make buffers consumable to allow reusing

fixes #513
parent 254b1c0d
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ import {
} from "@yume-chan/scrcpy";
import SCRCPY_SERVER_VERSION from "@yume-chan/scrcpy/bin/version";
import {
    Consumable,
    DistributionStream,
    InspectStream,
    ReadableStream,
@@ -69,9 +70,9 @@ export class ScrcpyPageState {
        const serverBuffer = await fetchServer();
        await AdbScrcpyClient.pushServer(
            GLOBAL_STATE.device!,
            new ReadableStream<Uint8Array>({
            new ReadableStream<Consumable<Uint8Array>>({
                start(controller) {
                    controller.enqueue(serverBuffer);
                    controller.enqueue(new Consumable(serverBuffer));
                    controller.close();
                },
            })
@@ -190,9 +191,9 @@ export class ScrcpyPageState {
            try {
                await AdbScrcpyClient.pushServer(
                    GLOBAL_STATE.device!,
                    new ReadableStream<Uint8Array>({
                    new ReadableStream<Consumable<Uint8Array>>({
                        start(controller) {
                            controller.enqueue(serverBuffer);
                            controller.enqueue(new Consumable(serverBuffer));
                            controller.close();
                        },
                    })
+7 −2
Original line number Diff line number Diff line
@@ -2,7 +2,11 @@

import { AdbSubprocessProtocol, encodeUtf8 } from "@yume-chan/adb";
import { AutoDisposable } from "@yume-chan/event";
import { AbortController, WritableStream } from "@yume-chan/stream-extra";
import {
    AbortController,
    Consumable,
    WritableStream,
} from "@yume-chan/stream-extra";
import { Terminal } from "xterm";
import { FitAddon } from "xterm-addon-fit";
import { SearchAddon } from "xterm-addon-search";
@@ -66,7 +70,8 @@ export class AdbTerminal extends AutoDisposable {
            this.addDisposable(
                this.terminal.onData((data) => {
                    const buffer = encodeUtf8(data);
                    _writer.write(buffer);
                    const output = new Consumable(buffer);
                    _writer.write(output);
                })
            );

+10 −7
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import {
import { useConst } from "@fluentui/react-hooks";
import { getIcon } from "@fluentui/style-utilities";
import { AdbFeature, LinuxFileType, type AdbSyncEntry } from "@yume-chan/adb";
import { ConsumableStream } from "@yume-chan/stream-extra";
import {
    action,
    autorun,
@@ -574,7 +575,9 @@ class FileManagerState {

                await sync.write({
                    filename: itemPath,
                    file: createFileStream(file).pipeThrough(
                    file: createFileStream(file)
                        .pipeThrough(new ConsumableStream())
                        .pipeThrough(
                            new ProgressStream(
                                action((uploaded) => {
                                    this.uploadedSize = uploaded;
+25 −23
Original line number Diff line number Diff line
@@ -8,7 +8,7 @@ import {
    PackageManager,
    PackageManagerInstallOptions,
} from "@yume-chan/android-bin";
import { WritableStream } from "@yume-chan/stream-extra";
import { ConsumableStream, WritableStream } from "@yume-chan/stream-extra";
import { action, makeAutoObservable, observable, runInAction } from "mobx";
import { observer } from "mobx-react-lite";
import { NextPage } from "next";
@@ -82,7 +82,9 @@ class InstallPageState {
        const start = Date.now();
        const log = await pm.installStream(
            file.size,
            createFileStream(file).pipeThrough(
            createFileStream(file)
                .pipeThrough(new ConsumableStream())
                .pipeThrough(
                    new ProgressStream(
                        action((uploaded) => {
                            if (uploaded !== file.size) {
+6 −3
Original line number Diff line number Diff line
@@ -48,9 +48,12 @@ export class GlobalState {
    }

    appendLog(direction: PacketLogItemDirection, packet: AdbPacketData) {
        (packet as PacketLogItem).direction = direction;
        (packet as PacketLogItem).timestamp = new Date();
        this.logs.push(packet as PacketLogItem);
        this.logs.push({
            ...packet,
            direction,
            timestamp: new Date(),
            payload: packet.payload.slice(),
        } as PacketLogItem);
    }

    clearLog() {
Loading