mirror of
https://github.com/yume-chan/ya-webadb.git
synced 2025-10-06 03:50:18 +02:00
fix(pm): throw error when install fails
This commit is contained in:
parent
cbee5a151e
commit
22f0329136
1 changed files with 30 additions and 12 deletions
|
@ -9,7 +9,7 @@ import {
|
||||||
escapeArg,
|
escapeArg,
|
||||||
} from "@yume-chan/adb";
|
} from "@yume-chan/adb";
|
||||||
import type { Consumable, ReadableStream } from "@yume-chan/stream-extra";
|
import type { Consumable, ReadableStream } from "@yume-chan/stream-extra";
|
||||||
import { DecodeUtf8Stream, WrapReadableStream } from "@yume-chan/stream-extra";
|
import { ConcatStringStream, DecodeUtf8Stream } from "@yume-chan/stream-extra";
|
||||||
|
|
||||||
import { Cmd } from "./cmd.js";
|
import { Cmd } from "./cmd.js";
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ export class PackageManager extends AdbCommandBase {
|
||||||
async pushAndInstallStream(
|
async pushAndInstallStream(
|
||||||
stream: ReadableStream<Consumable<Uint8Array>>,
|
stream: ReadableStream<Consumable<Uint8Array>>,
|
||||||
options?: Partial<PackageManagerInstallOptions>,
|
options?: Partial<PackageManagerInstallOptions>,
|
||||||
): Promise<ReadableStream<string>> {
|
): Promise<void> {
|
||||||
const sync = await this.adb.sync();
|
const sync = await this.adb.sync();
|
||||||
|
|
||||||
const fileName = Math.random().toString().substring(2);
|
const fileName = Math.random().toString().substring(2);
|
||||||
|
@ -301,24 +301,30 @@ export class PackageManager extends AdbCommandBase {
|
||||||
this.adb,
|
this.adb,
|
||||||
args.map(escapeArg).join(" "),
|
args.map(escapeArg).join(" "),
|
||||||
);
|
);
|
||||||
return new WrapReadableStream({
|
|
||||||
start: () => process.stdout.pipeThrough(new DecodeUtf8Stream()),
|
const output = await process.stdout
|
||||||
close: async () => {
|
.pipeThrough(new DecodeUtf8Stream())
|
||||||
await this.adb.rm(filePath);
|
.pipeThrough(new ConcatStringStream())
|
||||||
},
|
.then((output) => output.trim());
|
||||||
});
|
|
||||||
|
await this.adb.rm(filePath);
|
||||||
|
|
||||||
|
if (output !== "Success") {
|
||||||
|
throw new Error(output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async installStream(
|
async installStream(
|
||||||
size: number,
|
size: number,
|
||||||
stream: ReadableStream<Consumable<Uint8Array>>,
|
stream: ReadableStream<Consumable<Uint8Array>>,
|
||||||
options?: Partial<PackageManagerInstallOptions>,
|
options?: Partial<PackageManagerInstallOptions>,
|
||||||
): Promise<ReadableStream<string>> {
|
): Promise<void> {
|
||||||
// Android 7 added both `cmd` command and streaming install support,
|
// Android 7 added both `cmd` command and streaming install support,
|
||||||
// we can't detect whether `pm` supports streaming install,
|
// we can't detect whether `pm` supports streaming install,
|
||||||
// so we detect `cmd` command support instead.
|
// so we detect `cmd` command support instead.
|
||||||
if (!this.#cmd.supportsCmd) {
|
if (!this.#cmd.supportsCmd) {
|
||||||
return this.pushAndInstallStream(stream, options);
|
await this.pushAndInstallStream(stream, options);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const args = this.#buildInstallArguments(options);
|
const args = this.#buildInstallArguments(options);
|
||||||
|
@ -326,8 +332,20 @@ export class PackageManager extends AdbCommandBase {
|
||||||
args.shift();
|
args.shift();
|
||||||
args.push("-S", size.toString());
|
args.push("-S", size.toString());
|
||||||
const process = await this.#cmd.spawn(false, "package", ...args);
|
const process = await this.#cmd.spawn(false, "package", ...args);
|
||||||
await stream.pipeTo(process.stdin);
|
|
||||||
return process.stdout.pipeThrough(new DecodeUtf8Stream());
|
const output = process.stdout
|
||||||
|
.pipeThrough(new DecodeUtf8Stream())
|
||||||
|
.pipeThrough(new ConcatStringStream())
|
||||||
|
.then((output) => output.trim());
|
||||||
|
|
||||||
|
await Promise.all([
|
||||||
|
stream.pipeTo(process.stdin),
|
||||||
|
output.then((output) => {
|
||||||
|
if (output !== "Success") {
|
||||||
|
throw new Error(output);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static parsePackageListItem(
|
static parsePackageListItem(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue