feat(bin): add PackageManager.prototype.getPackages method

This commit is contained in:
Simon Chan 2025-03-02 18:15:33 +08:00
parent 5a1f41766c
commit 0f29501c5f
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD
2 changed files with 21 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
"@yume-chan/android-bin": minor
---
Add `PackageManager.prototype.getPackages` method to get apk paths

View file

@ -475,6 +475,22 @@ export class PackageManager extends AdbCommandBase {
}
}
async getPackages(packageName: string): Promise<string[]> {
const args = ["pm", "-p", packageName];
const process = await this.#cmdOrSubprocess(args);
const result: string[] = [];
for await (const line of process.stdout
.pipeThrough(new TextDecoderStream())
.pipeThrough(new SplitStringStream("\n"))) {
if (line.startsWith("package:")) {
result.push(line.substring("package:".length));
}
}
return result;
}
async uninstall(
packageName: string,
options?: Partial<PackageManagerUninstallOptions>,