From a604fce2f3253069b79eb0e2e1fb0155b09fb657 Mon Sep 17 00:00:00 2001 From: blckmn Date: Fri, 20 Jun 2025 21:18:02 +1000 Subject: [PATCH] Checks for refresh --- src/js/protocols/WebSerial.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/js/protocols/WebSerial.js b/src/js/protocols/WebSerial.js index 945a8c75..04189590 100644 --- a/src/js/protocols/WebSerial.js +++ b/src/js/protocols/WebSerial.js @@ -44,6 +44,7 @@ class WebSerial extends EventTarget { this.closeRequested = false; this.transmitting = false; this.connectionInfo = null; + this.refreshRequired = true; this.bitrate = 0; this.bytesSent = 0; @@ -79,7 +80,7 @@ class WebSerial extends EventTarget { const added = this.createPort(device); this.ports.push(added); this.dispatchEvent(new CustomEvent("addedDevice", { detail: added })); - + this.refreshRequired = true; return added; } @@ -87,6 +88,7 @@ class WebSerial extends EventTarget { const removed = this.ports.find((port) => port.port === device); this.ports = this.ports.filter((port) => port.port !== device); this.dispatchEvent(new CustomEvent("removedDevice", { detail: removed })); + this.refreshRequired = true; } handleReceiveBytes(info) { @@ -121,6 +123,7 @@ class WebSerial extends EventTarget { const ports = await navigator.serial.getPorts(); this.portCounter = 1; this.ports = ports.map((port) => this.createPort(port)); + this.refreshRequired = false; } catch (error) { console.error(`${logHead} Error loading devices:`, error); } @@ -142,11 +145,14 @@ class WebSerial extends EventTarget { } catch (error) { console.error(`${logHead} User didn't select any SERIAL device when requesting permission:`, error); } + this.refreshRequired = true; return newPermissionPort; } async getDevices() { - await this.loadDevices(); + if (this.refreshRequired) { + await this.loadDevices(); + } return this.ports; }