Skip to content

Commit

Permalink
Prevent closing serial twice on reboot (#3990)
Browse files Browse the repository at this point in the history
  • Loading branch information
haslinghuis authored May 30, 2024
1 parent ff83600 commit 617790b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/js/webSerial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -66,6 +67,7 @@ class WebSerial extends EventTarget {

handleDisconnect() {
this.disconnect();
this.closeRequested = true;
}

getConnectedPort() {
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 617790b

Please sign in to comment.