From 617790b239cd6743bd7731a3d5b46a18fb6a9b21 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Thu, 30 May 2024 21:41:12 +0200 Subject: [PATCH] Prevent closing serial twice on reboot (#3990) --- src/js/webSerial.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/js/webSerial.js b/src/js/webSerial.js index 00754caff0..b4c4634acd 100644 --- a/src/js/webSerial.js +++ b/src/js/webSerial.js @@ -20,6 +20,7 @@ class WebSerial extends EventTarget { this.connected = false; this.openRequested = false; this.openCanceled = false; + this.closeRequested = false; this.transmitting = false; this.connectionInfo = null; @@ -66,6 +67,7 @@ class WebSerial extends EventTarget { handleDisconnect() { this.disconnect(); + this.closeRequested = true; } getConnectedPort() { @@ -116,6 +118,7 @@ class WebSerial extends EventTarget { async connect(path, options) { this.openRequested = true; + this.closeRequested = false; this.port = this.ports.find(device => device.path === path).port; @@ -191,6 +194,11 @@ class WebSerial extends EventTarget { this.bytesReceived = 0; this.bytesSent = 0; + // if we are already closing, don't do it again + if (this.closeRequested) { + return; + } + const doCleanup = async () => { this.removeEventListener('receive', this.handleReceiveBytes); if (this.reader) {