@@ -110,8 +110,13 @@ function setScene(id) {
110110 state . scene = id ;
111111}
112112
113- function resetPort ( ) {
114- void state . port . close ( ) ;
113+ async function resetPort ( ) {
114+ try {
115+ await state . port . close ( ) ;
116+ } catch ( err ) {
117+ console . error ( err ) ;
118+ }
119+
115120 state . port = null ;
116121}
117122
@@ -168,7 +173,7 @@ async function writePassword(value) {
168173 }
169174
170175 if ( value . length > state . maxLen ) {
171- resetPort ( ) ;
176+ await resetPort ( ) ;
172177 throw new Error ( `Password is too long (max: ${ maxLen } )` ) ;
173178 }
174179
@@ -185,6 +190,7 @@ async function writePassword(value) {
185190
186191 setProgress ( "Waiting for device response..." ) ;
187192 const rsp = await waitForResponse ( state . port ) ;
193+ console . log ( "REMOTE: " , rsp ) ;
188194 const { ok, val } = parseResponse ( rsp ) ;
189195 if ( ! ok ) {
190196 throw new Error ( "Device didn't acknowledge. Please try again." ) ;
@@ -197,7 +203,7 @@ async function writePassword(value) {
197203 setScene ( scenes . finish ) ;
198204 setTimeout ( ( ) => setScene ( scenes . start ) , 3000 ) ;
199205 } finally {
200- resetPort ( ) ;
206+ await resetPort ( ) ;
201207 }
202208}
203209
@@ -225,7 +231,7 @@ async function start() {
225231 const { ok, val } = parsePrompt ( buff ) ;
226232 if ( ! ok ) {
227233 setErrorMsg ( "Bad handshake response from device. Please try again" ) ;
228- resetPort ( ) ;
234+ await resetPort ( ) ;
229235 return ;
230236 }
231237
@@ -238,7 +244,7 @@ async function start() {
238244
239245function cancel ( ) {
240246 if ( state . isWriting ) {
241- resetPort ( ) ;
247+ void resetPort ( ) ;
242248 }
243249
244250 setScene ( scenes . start ) ;
0 commit comments