generated from ZanzyTHEbar/SolidJSTauri
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.tsx
More file actions
264 lines (255 loc) · 11.6 KB
/
index.tsx
File metadata and controls
264 lines (255 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import SelectButton from '@components/Buttons/SelectButton'
import Card from '@components/Cards/Card'
import Typography from '@components/Typography'
import {
ACTION,
DEVICE_MODE_WIZARD,
FLASH_WIZARD_STEPS,
INIT_WIZARD_STEPS,
MODAL_TYPE,
SELECT_MODE_WIZARD,
SELECT_PORT_WIZARD,
STEP_ACTION,
UPDATE_NETWORK_WIZARD,
} from '@interfaces/animation/enums'
import { logger } from '@src/logger'
import { detectDeviceMode } from '@store/actions/animation/detectDeviceMode'
import { verifyBoardMode } from '@store/actions/animation/verifyBoardMode'
import { verifyPortConnection } from '@store/actions/animation/verifyPortConnection'
import { downloadAsset } from '@store/actions/firmware/downloadAsset'
import { installOpenIris } from '@store/actions/terminal/installOpenIris'
import { setAction, setStep } from '@store/animation/animation'
import { activeStep } from '@store/animation/selectors'
import { setActivePort } from '@store/esp/esp'
import { activePort } from '@store/esp/selectors'
import { firmwareType } from '@store/firmware/selectors'
import {
restartFirmwareState,
setAbortController,
setProcessStatus,
} from '@store/terminal/terminal'
import { activeStepAction } from '@store/ui/selectors'
import { setOpenModal } from '@store/ui/ui'
import { BiRegularChip, BiRegularLoaderAlt } from 'solid-icons/bi'
import { BsDisplayport } from 'solid-icons/bs'
import { batch, createMemo, Match, Show, Switch } from 'solid-js'
const SelectPortWizard = () => {
const buttonDescription = createMemo(() => {
switch (activeStepAction()) {
case STEP_ACTION.SELECT_MODE: {
return 'Verify connection'
}
default:
return 'Select port'
}
})
const selectPortButtonDescription = createMemo(() => {
switch (activeStepAction()) {
case STEP_ACTION.CHANGE_DEVICE_MODE: {
return 'Detect device'
}
case STEP_ACTION.SELECT_MODE: {
return 'Verify connection'
}
case STEP_ACTION.INSTALL_OPENIRIS: {
return 'Install openiris'
}
case STEP_ACTION.UPDATE_NETWORK: {
return 'Check mode'
}
case STEP_ACTION.SELECT_NETWORK: {
return 'Continue'
}
default:
break
}
})
const selectPortDescription = createMemo(() => {
switch (activeStepAction()) {
case STEP_ACTION.INSTALL_OPENIRIS: {
return 'Choose the port your device is connected to, then click the button below to begin flashing and follow the on-screen instructions.'
}
default: {
return 'Choose the port your device is connected to, then click the button below.'
}
}
})
const beforeProceedingDescription = createMemo(() => {
switch (activeStepAction()) {
case STEP_ACTION.CHANGE_DEVICE_MODE:
case STEP_ACTION.SELECT_MODE:
case STEP_ACTION.SELECT_NETWORK:
case STEP_ACTION.UPDATE_NETWORK: {
return 'Unplug your board, then reconnect it to the PC without pressing any buttons to ensure it starts fresh.'
}
default: {
return undefined
}
}
})
return (
<Switch>
<Match when={activeStep() === SELECT_PORT_WIZARD.SELECT_PORT_BEFORE_PROCEEDING}>
<Card
primaryButtonLabel={buttonDescription()}
isActive
icon={BiRegularChip}
onClickBack={() => {
switch (activeStepAction()) {
case STEP_ACTION.CHANGE_DEVICE_MODE:
case STEP_ACTION.UPDATE_NETWORK:
case STEP_ACTION.SELECT_NETWORK: {
batch(() => {
setStep(INIT_WIZARD_STEPS.ADVANCED_BOARD_OPTIONS, false)
setAction(ACTION.PREV)
})
break
}
case STEP_ACTION.SELECT_MODE: {
batch(() => {
setStep(SELECT_MODE_WIZARD.SELECT_MODE, false)
setAction(ACTION.PREV)
})
break
}
case STEP_ACTION.INSTALL_OPENIRIS: {
batch(() => {
setStep(INIT_WIZARD_STEPS.SELECT_BOARD, false)
setAction(ACTION.PREV)
})
break
}
default:
break
}
}}
onClickPrimary={async () => {
switch (activeStepAction()) {
case STEP_ACTION.CHANGE_DEVICE_MODE:
case STEP_ACTION.INSTALL_OPENIRIS:
case STEP_ACTION.UPDATE_NETWORK:
case STEP_ACTION.SELECT_NETWORK: {
batch(() => {
setActivePort('')
setAction(ACTION.NEXT)
setStep(SELECT_PORT_WIZARD.SELECT_PORT, false)
})
break
}
case STEP_ACTION.SELECT_MODE: {
batch(() => {
setAction(ACTION.NEXT)
setStep(SELECT_PORT_WIZARD.SELECT_CHECK_PORT_CONNECTION, false)
verifyPortConnection().catch(() => {})
})
break
}
default:
break
}
}}
label="Before proceeding"
description={beforeProceedingDescription()}>
<Show when={activeStepAction() === STEP_ACTION.INSTALL_OPENIRIS}>
<div class="flex flex-col gap-14 pb-24">
<Typography color="white" text="caption" class="text-left">
Make sure to follow the steps below 👇
</Typography>
<div class="flex flex-col gap-14">
<Typography color="white" text="caption" class="text-left">
• hold B button while plugging the board in
</Typography>
</div>
</div>
</Show>
</Card>
</Match>
<Match when={activeStep() === SELECT_PORT_WIZARD.SELECT_CHECK_PORT_CONNECTION}>
<Card isLoader icon={BiRegularLoaderAlt} label="Connecting">
<Typography text="caption" color="white" class="leading-[18px]">
Verifying port connection status.
<br /> <code class="text-purple-100">process can take up to (5s)</code>
</Typography>
</Card>
</Match>
<Match when={activeStep() === SELECT_PORT_WIZARD.SELECT_PORT}>
<Card
primaryButtonLabel={selectPortButtonDescription()}
isActive={activePort() !== ''}
icon={BsDisplayport}
onClickBack={() => {
batch(() => {
setAction(ACTION.PREV)
setStep(SELECT_PORT_WIZARD.SELECT_PORT_BEFORE_PROCEEDING, false)
})
}}
onClickPrimary={() => {
switch (activeStepAction()) {
case STEP_ACTION.CHANGE_DEVICE_MODE: {
batch(() => {
detectDeviceMode().catch(() => {})
setStep(DEVICE_MODE_WIZARD.DETECT_DEVICE_MODE, false)
setAction(ACTION.NEXT)
})
break
}
case STEP_ACTION.SELECT_MODE: {
batch(() => {
setAction(ACTION.NEXT)
verifyPortConnection().catch(() => {})
setStep(SELECT_PORT_WIZARD.SELECT_CHECK_PORT_CONNECTION, false)
})
break
}
case STEP_ACTION.UPDATE_NETWORK: {
batch(() => {
setAction(ACTION.NEXT)
verifyBoardMode(['wifi', 'setup']).catch(() => {})
setStep(UPDATE_NETWORK_WIZARD.UPDATE_NETWORK_CHECK_MODE, false)
})
break
}
case STEP_ACTION.SELECT_NETWORK: {
batch(() => {
setAction(ACTION.NEXT)
verifyPortConnection(true).catch(() => {})
setStep(SELECT_PORT_WIZARD.SELECT_CHECK_PORT_CONNECTION, false)
})
break
}
case STEP_ACTION.INSTALL_OPENIRIS: {
batch(() => {
logger.infoStart('INIT_WIZARD_STEPS.SELECT_PORT')
logger.add(`firmware type : ${firmwareType()}`)
logger.add(`active port : ${activePort()}`)
setAction(ACTION.NEXT)
setStep(FLASH_WIZARD_STEPS.FLASH_PROCESS, false)
setAbortController('openiris')
setProcessStatus(true)
restartFirmwareState()
installOpenIris(activePort(), async () => {
await downloadAsset(firmwareType())
}).catch(() => {})
})
break
}
default:
break
}
}}
label="Select Port"
description={selectPortDescription()}>
<SelectButton
tabIndex={0}
type="button"
label={activePort() === '' ? 'Select Port' : activePort()}
onClick={() => {
setOpenModal({ open: true, type: MODAL_TYPE.SELECT_PORT })
}}
/>
</Card>
</Match>
</Switch>
)
}
export default SelectPortWizard