fix: handle serial port disconnect

This commit is contained in:
Vlad Stan 2022-08-11 15:06:32 +03:00
parent 6b57c8b2a7
commit e20cfd3e6d

View file

@ -69,7 +69,8 @@ async function serialSigner(path) {
}) })
navigator.serial.addEventListener('disconnect', () => { navigator.serial.addEventListener('disconnect', () => {
console.log('### navigator.serial event: disconnected!', event) console.log('### navigator.serial event: disconnected!')
this.selectedPort = null
this.hww.authenticated = false this.hww.authenticated = false
this.$q.notify({ this.$q.notify({
type: 'warning', type: 'warning',
@ -113,14 +114,13 @@ async function serialSigner(path) {
/* Ignore the error */ /* Ignore the error */
}) })
if (this.selectedPort) await this.selectedPort.close() if (this.selectedPort) await this.selectedPort.close()
this.selectedPort = null
this.$q.notify({ this.$q.notify({
type: 'positive', type: 'positive',
message: 'Serial port disconnected!', message: 'Serial port disconnected!',
timeout: 5000 timeout: 5000
}) })
} catch (error) { } catch (error) {
this.selectedPort = null
this.$q.notify({ this.$q.notify({
type: 'warning', type: 'warning',
message: 'Cannot close serial port!', message: 'Cannot close serial port!',
@ -128,6 +128,7 @@ async function serialSigner(path) {
timeout: 10000 timeout: 10000
}) })
} finally { } finally {
this.selectedPort = null
this.hww.authenticated = false this.hww.authenticated = false
} }
}, },