Skip to content

Commit b35935b

Browse files
Progress/mock tweaks for library changes
1 parent a770d9d commit b35935b

File tree

4 files changed

+30
-11
lines changed

4 files changed

+30
-11
lines changed

src/common/ProgressDialog.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const doNothing = () => {};
1919
export interface ProgressDialogParameters {
2020
header: ReactNode;
2121
body?: ReactNode;
22-
progress: number | undefined;
22+
progress?: number;
2323
}
2424

2525
interface ProgressDialogProps extends ProgressDialogParameters {
@@ -29,10 +29,15 @@ interface ProgressDialogProps extends ProgressDialogParameters {
2929
/**
3030
* A progress dialog used for the flashing process.
3131
*/
32-
const ProgressDialog = ({ header, body, progress }: ProgressDialogProps) => {
32+
const ProgressDialog = ({
33+
isOpen,
34+
header,
35+
body,
36+
progress,
37+
}: ProgressDialogProps) => {
3338
return (
3439
<Modal
35-
isOpen={progress !== undefined}
40+
isOpen={isOpen}
3641
onClose={doNothing}
3742
isCentered
3843
size={body ? "xl" : "md"}
@@ -53,7 +58,7 @@ const ProgressDialog = ({ header, body, progress }: ProgressDialogProps) => {
5358
alignItems="flex-start"
5459
>
5560
{body}
56-
<Progress value={progress! * 100} width="100%" />
61+
<Progress value={(progress ?? 0) * 100} width="100%" />
5762
</VStack>
5863
</ModalBody>
5964
</ModalContent>

src/common/use-dialogs.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ export class Dialogs {
6565
}
6666

6767
progress(options: ProgressDialogParameters): void {
68-
if (options.progress === undefined) {
69-
this.progressDialogSetState(undefined);
70-
} else {
71-
this.progressDialogSetState(options);
72-
}
68+
this.progressDialogSetState(options);
69+
}
70+
71+
closeProgress(): void {
72+
this.progressDialogSetState(undefined);
7373
}
7474
}
7575

src/device/mock.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
import {
77
BoardVersion,
8+
ConnectionAvailabilityStatus,
89
ConnectionStatus,
910
DeviceConnectionEventMap,
1011
FlashDataSource,
@@ -31,6 +32,7 @@ export class MockDeviceConnection
3132
status: ConnectionStatus = ConnectionStatus.NoAuthorizedDevice;
3233

3334
private connectResults: DeviceErrorCode[] = [];
35+
private availability: ConnectionAvailabilityStatus = "available";
3436

3537
constructor() {
3638
super();
@@ -48,7 +50,7 @@ export class MockDeviceConnection
4850

4951
async initialize(): Promise<void> {}
5052
async checkAvailability() {
51-
return "available" as const;
53+
return this.availability;
5254
}
5355

5456
dispose() {}
@@ -110,4 +112,8 @@ export class MockDeviceConnection
110112
clearDevice(): void {
111113
this.setStatus(ConnectionStatus.NoAuthorizedDevice);
112114
}
115+
116+
mockWebUsbNotSupported(): void {
117+
this.availability = "unsupported";
118+
}
113119
}

src/project/project-actions.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ export class ProjectActions {
135135
type: "connect",
136136
});
137137

138+
const availability = await this.device.checkAvailability();
139+
if (availability !== "available") {
140+
this.webusbNotSupportedError(finalFocusRef);
141+
return false;
142+
}
143+
138144
if (await this.showConnectHelp(forceConnectHelp, finalFocusRef)) {
139145
return this.connectInternal(userAction, finalFocusRef);
140146
}
@@ -514,8 +520,8 @@ export class ProjectActions {
514520
}
515521
}
516522

523+
const flashingCode = this.intl.formatMessage({ id: "flashing-code" });
517524
try {
518-
const flashingCode = this.intl.formatMessage({ id: "flashing-code" });
519525
const firstFlashNotice = (
520526
<Text fontSize="lg">
521527
<FormattedMessage id="flashing-full-flash-detail" />
@@ -546,6 +552,8 @@ export class ProjectActions {
546552
} else {
547553
this.handleWebUSBError(e, ConnectionAction.FLASH, finalFocusRef);
548554
}
555+
} finally {
556+
this.dialogs.closeProgress();
549557
}
550558
};
551559

0 commit comments

Comments
 (0)