Skip to content

Commit b6575c5

Browse files
laurensvalkdlech
authored andcommitted
firmware/alerts: Add button to install USB driver.
1 parent ef2d01a commit b6575c5

File tree

3 files changed

+45
-17
lines changed

3 files changed

+45
-17
lines changed

src/firmware/alerts/NoDfuHub.tsx

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
// SPDX-License-Identifier: MIT
22
// Copyright (c) 2022 The Pybricks Authors
33

4-
import { AnchorButton, Intent } from '@blueprintjs/core';
4+
import { AnchorButton, Button, Intent } from '@blueprintjs/core';
55
import React from 'react';
66
import { pybricksUsbDfuTroubleshootingUrl } from '../../app/constants';
77
import ExternalLinkIcon from '../../components/ExternalLinkIcon';
88
import type { CreateToast } from '../../toasterTypes';
99
import { isLinux, isWindows } from '../../utils/os';
1010
import { useI18n } from './i18n';
1111

12-
const NoDfuHub: React.VoidFunctionComponent = () => {
12+
type NoDfuHubProps = {
13+
onInstallWindowsDriver: () => void;
14+
};
15+
16+
const NoDfuHub: React.VoidFunctionComponent<NoDfuHubProps> = ({
17+
onInstallWindowsDriver,
18+
}) => {
1319
const i18n = useI18n();
1420

1521
return (
@@ -18,23 +24,31 @@ const NoDfuHub: React.VoidFunctionComponent = () => {
1824

1925
{isWindows() && <p>{i18n.translate('noDfuHub.suggestion1.windows')}</p>}
2026
{isLinux() && <p>{i18n.translate('noDfuHub.suggestion1.linux')}</p>}
21-
22-
<p>{i18n.translate('noDfuHub.suggestion2')}</p>
23-
24-
<AnchorButton
25-
icon="help"
26-
href={pybricksUsbDfuTroubleshootingUrl}
27-
target="_blank"
28-
>
29-
{i18n.translate('noDfuHub.troubleshootButton')}
30-
<ExternalLinkIcon />
31-
</AnchorButton>
27+
<div className="pb-ble-alerts-buttons">
28+
{isWindows() && (
29+
<Button icon="download" onClick={onInstallWindowsDriver}>
30+
{i18n.translate('noDfuHub.installUsbDriverButton')}
31+
</Button>
32+
)}
33+
<AnchorButton
34+
icon="help"
35+
href={pybricksUsbDfuTroubleshootingUrl}
36+
target="_blank"
37+
>
38+
{i18n.translate('noDfuHub.troubleshootButton')}
39+
<ExternalLinkIcon />
40+
</AnchorButton>
41+
</div>
3242
</>
3343
);
3444
};
3545

36-
export const noDfuHub: CreateToast = (onAction) => ({
37-
message: <NoDfuHub />,
46+
export const noDfuHub: CreateToast<never, 'dismiss' | 'installWindowsDriver'> = (
47+
onAction,
48+
) => ({
49+
message: (
50+
<NoDfuHub onInstallWindowsDriver={() => onAction('installWindowsDriver')} />
51+
),
3852
icon: 'info-sign',
3953
intent: Intent.PRIMARY,
4054
onDismiss: () => onAction('dismiss'),

src/firmware/alerts/translations/en.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"windows": "You may need to manually install a USB driver before you can connect to your hub.",
1515
"linux": "You may need to add udev rules before you can connect to your hub."
1616
},
17-
"suggestion2": "Click the button below for more information.",
18-
"troubleshootButton": "Troubleshooting Tips"
17+
"troubleshootButton": "Troubleshooting Tips",
18+
"installUsbDriverButton": "Install USB Driver"
1919
},
2020
"noDfuInterface": {
2121
"message": "This is very unusual. The USB device did not contain the expected interface."

src/firmware/sagas.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import {
8080
firmwareRestoreOfficialDfu,
8181
flashFirmware,
8282
} from './actions';
83+
import { firmwareDfuWindowsDriverInstallDialogDialogShow } from './dfuWindowsDriverInstallDialog/actions';
8384
import {
8485
firmwareInstallPybricksDialogAccept,
8586
firmwareInstallPybricksDialogCancel,
@@ -713,6 +714,19 @@ function* handleFlashUsbDfu(action: ReturnType<typeof firmwareFlashUsbDfu>): Gen
713714
if (!device) {
714715
yield* put(alertsShowAlert('firmware', 'noDfuHub'));
715716
yield* put(firmwareDidFailToFlashUsbDfu());
717+
718+
const { action } = yield* take<
719+
ReturnType<typeof alertsDidShowAlert<'firmware', 'noDfuHub'>>
720+
>(
721+
alertsDidShowAlert.when(
722+
(a) => a.domain === 'firmware' && a.specific === 'noDfuHub',
723+
),
724+
);
725+
726+
if (action === 'installWindowsDriver') {
727+
yield* put(firmwareDfuWindowsDriverInstallDialogDialogShow());
728+
}
729+
716730
return;
717731
}
718732

0 commit comments

Comments
 (0)