feat(demo): update bugreport usage

This commit is contained in:
Simon Chan 2023-08-25 22:14:09 +08:00
parent 2b9c4f106e
commit c48ffc18db
No known key found for this signature in database
GPG key ID: A8B69F750B9BCEDD

View file

@ -8,11 +8,7 @@ import {
Stack, Stack,
StackItem, StackItem,
} from "@fluentui/react"; } from "@fluentui/react";
import { import { BugReport } from "@yume-chan/android-bin";
BugReport,
BugReportZ,
BugReportZVersion,
} from "@yume-chan/android-bin";
import { import {
action, action,
autorun, autorun,
@ -29,10 +25,6 @@ import { RouteStackProps, saveFile } from "../utils";
class BugReportState { class BugReportState {
bugReport: BugReport | undefined = undefined; bugReport: BugReport | undefined = undefined;
bugReportZ: BugReportZ | undefined = undefined;
bugReportZVersion: BugReportZVersion | undefined = undefined;
bugReportZInProgress = false; bugReportZInProgress = false;
bugReportZProgress: string | undefined = undefined; bugReportZProgress: string | undefined = undefined;
@ -41,7 +33,6 @@ class BugReportState {
constructor() { constructor() {
makeAutoObservable(this, { makeAutoObservable(this, {
bugReportZVersion: observable.deep,
generateBugReport: action.bound, generateBugReport: action.bound,
generateBugReportZStream: action.bound, generateBugReportZStream: action.bound,
generateBugReportZ: action.bound, generateBugReportZ: action.bound,
@ -49,32 +40,30 @@ class BugReportState {
autorun(() => { autorun(() => {
if (GLOBAL_STATE.adb) { if (GLOBAL_STATE.adb) {
runInAction(() => { (async () => {
this.bugReport = new BugReport(GLOBAL_STATE.adb!); const bugreport = await BugReport.queryCapabilities(
this.bugReportZ = new BugReportZ(GLOBAL_STATE.adb!); GLOBAL_STATE.adb!,
this.bugReportZ.version().then(
action((version) => {
this.bugReportZVersion = version;
})
); );
}); runInAction(() => {
this.bugReport = bugreport;
});
})();
} else { } else {
runInAction(() => { runInAction(() => {
this.bugReport = undefined; this.bugReport = undefined;
this.bugReportZ = undefined;
this.bugReportZVersion = undefined;
}); });
} }
}); });
} }
async generateBugReport() { async generateBugReport() {
await this.bugReport!.generate().pipeTo(saveFile("bugreport.txt")); await this.bugReport!.bugReport().pipeTo(saveFile("bugreport.txt"));
} }
async generateBugReportZStream() { async generateBugReportZStream() {
await this.bugReportZ!.stream().pipeTo(saveFile("bugreport.zip")); await this.bugReport!.bugReportZStream().pipeTo(
saveFile("bugreport.zip"),
);
} }
async generateBugReportZ() { async generateBugReportZ() {
@ -82,14 +71,14 @@ class BugReportState {
this.bugReportZInProgress = true; this.bugReportZInProgress = true;
}); });
const filename = await this.bugReportZ!.generate( const filename = await this.bugReport!.bugReportZ({
this.bugReportZVersion!.supportProgress onProgress: this.bugReport!.supportsBugReportZProgress
? action((progress, total) => { ? action((progress, total) => {
this.bugReportZProgress = progress; this.bugReportZProgress = progress;
this.bugReportZTotalSize = total; this.bugReportZTotalSize = total;
}) })
: undefined : undefined,
); });
const sync = await GLOBAL_STATE.adb!.sync(); const sync = await GLOBAL_STATE.adb!.sync();
await sync.read(filename).pipeTo(saveFile("bugreport.zip")); await sync.read(filename).pipeTo(saveFile("bugreport.zip"));
@ -127,7 +116,7 @@ const BugReportPage: NextPage = () => {
<StackItem> <StackItem>
<PrimaryButton <PrimaryButton
disabled={!state.bugReportZVersion?.supportStream} disabled={!state.bugReport?.supportsBugReportZStream}
text="Generate Zipped BugReport (Streaming)" text="Generate Zipped BugReport (Streaming)"
onClick={state.generateBugReportZStream} onClick={state.generateBugReportZStream}
/> />
@ -142,7 +131,7 @@ const BugReportPage: NextPage = () => {
<StackItem> <StackItem>
<PrimaryButton <PrimaryButton
disabled={ disabled={
!state.bugReportZVersion || !state.bugReport?.supportsBugReportZ ||
state.bugReportZInProgress state.bugReportZInProgress
} }
text="Generate Zipped BugReport" text="Generate Zipped BugReport"
@ -160,8 +149,8 @@ const BugReportPage: NextPage = () => {
) : ( ) : (
<span> <span>
Generating... Please wait Generating... Please wait
{!state.bugReportZVersion! {!state.bugReport!
.supportProgress && .supportsBugReportZProgress &&
" (this device does not support progress)"} " (this device does not support progress)"}
</span> </span>
)} )}