4
4
* SPDX-License-Identifier: MIT
5
5
*/
6
6
import { Button } from "@chakra-ui/button" ;
7
- import { HStack , Text , VStack } from "@chakra-ui/react" ;
8
- import { useCallback } from "react" ;
7
+ import { Flex , HStack , Image , Stack , Text , VStack } from "@chakra-ui/react" ;
8
+ import { ReactNode , useCallback } from "react" ;
9
9
import { FormattedMessage } from "react-intl" ;
10
10
import { GenericDialog } from "../../common/GenericDialog" ;
11
+ import { isChromeOS105 } from "../../device/webusb" ;
12
+ import chromeOSErrorImage from "./chrome-os-105-error.png" ;
11
13
12
14
interface WebUSBDialogProps {
13
15
callback : ( ) => void ;
@@ -25,24 +27,32 @@ export const WebUSBDialog = ({
25
27
< GenericDialog
26
28
finalFocusRef = { finalFocusRef }
27
29
onClose = { handleClose }
28
- body = { < WebUSBDialogBody /> }
30
+ body = {
31
+ isChromeOS105 ( ) ? < Chrome105ErrorBody /> : < NotSupportedErrorBody />
32
+ }
29
33
footer = { < WebUSBDialogFooter onCancel = { handleClose } /> }
30
34
size = "3xl"
31
35
/>
32
36
) ;
33
37
} ;
34
38
35
- const WebUSBDialogBody = ( ) => {
39
+ const DialogBodyWrapper = ( { children } : { children : ReactNode } ) => (
40
+ < VStack
41
+ width = "auto"
42
+ ml = "auto"
43
+ mr = "auto"
44
+ p = { 8 }
45
+ pb = { 0 }
46
+ spacing = { 5 }
47
+ alignItems = "flex-start"
48
+ >
49
+ { children }
50
+ </ VStack >
51
+ ) ;
52
+
53
+ const NotSupportedErrorBody = ( ) => {
36
54
return (
37
- < VStack
38
- width = "auto"
39
- ml = "auto"
40
- mr = "auto"
41
- p = { 8 }
42
- pb = { 0 }
43
- spacing = { 5 }
44
- alignItems = "flex-start"
45
- >
55
+ < DialogBodyWrapper >
46
56
< Text as = "h2" fontSize = "xl" fontWeight = "semibold" >
47
57
< FormattedMessage id = "webusb-not-supported-title" />
48
58
</ Text >
@@ -52,7 +62,43 @@ const WebUSBDialogBody = () => {
52
62
< Text >
53
63
< FormattedMessage id = "webusb-why-use" />
54
64
</ Text >
55
- </ VStack >
65
+ </ DialogBodyWrapper >
66
+ ) ;
67
+ } ;
68
+
69
+ const Chrome105ErrorBody = ( ) => {
70
+ return (
71
+ < DialogBodyWrapper >
72
+ < Text as = "h2" fontSize = "xl" fontWeight = "semibold" >
73
+ There is an issue with Chrome OS version 105 and WebUSB*
74
+ </ Text >
75
+ < HStack spacing = { 5 } >
76
+ < Stack >
77
+ < Text >
78
+ Unfortunately “Send to micro:bit” does not work in this particular
79
+ Chrome OS version due to a bug in the operating system. The next
80
+ version of Chrome OS, version 106, expected October 2022, should
81
+ contain a fix for this.
82
+ </ Text >
83
+ < Text fontSize = "md" >
84
+ Your program will be saved to your computer instead. Follow the
85
+ steps on the next screen to transfer it to your micro:bit.
86
+ </ Text >
87
+ < Text fontSize = "sm" >
88
+ *< FormattedMessage id = "webusb-why-use" />
89
+ </ Text >
90
+ </ Stack >
91
+ < Flex justifyContent = "center" width = "100%" >
92
+ < Image
93
+ width = "100%"
94
+ height = "100%"
95
+ src = { chromeOSErrorImage }
96
+ alt = ""
97
+ pb = { 3 }
98
+ />
99
+ </ Flex >
100
+ </ HStack >
101
+ </ DialogBodyWrapper >
56
102
) ;
57
103
} ;
58
104
@@ -63,7 +109,7 @@ interface WebUSBDialogFooterProps {
63
109
const WebUSBDialogFooter = ( { onCancel } : WebUSBDialogFooterProps ) => {
64
110
return (
65
111
< HStack spacing = { 2.5 } >
66
- < Button onClick = { onCancel } size = "lg" >
112
+ < Button onClick = { onCancel } size = "lg" variant = "solid" >
67
113
< FormattedMessage id = "close-action" />
68
114
</ Button >
69
115
</ HStack >
0 commit comments