From 5001d839ddfa08f89f2df48601fc8ccd08bfa021 Mon Sep 17 00:00:00 2001 From: Mark Haslinghuis Date: Wed, 18 Jun 2025 23:58:35 +0200 Subject: [PATCH] Fix auto-connect --- src/js/port_handler.js | 10 ---------- src/js/serial_backend.js | 21 +++++++++------------ 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/js/port_handler.js b/src/js/port_handler.js index 3299ed67..2e5c9f7f 100644 --- a/src/js/port_handler.js +++ b/src/js/port_handler.js @@ -207,16 +207,6 @@ PortHandler.selectActivePort = function (suggestedDevice = false) { return selectedPort; } - // If there is no connection, check for the last used device - // Check if the device is already connected - if (this.portPicker.selectedPort && this.portPicker.selectedPort !== DEFAULT_PORT) { - selectedPort = this.currentSerialPorts.find((device) => device.path === this.portPicker.selectedPort); - if (selectedPort) { - console.log(`${this.logHead} Using previously selected device: ${selectedPort.path}`); - return selectedPort.path; - } - } - // Return the suggested device (the new device that has been detected) if (!selectedPort && suggestedDevice) { selectedPort = suggestedDevice.path; diff --git a/src/js/serial_backend.js b/src/js/serial_backend.js index 7c666b50..9d3d2345 100644 --- a/src/js/serial_backend.js +++ b/src/js/serial_backend.js @@ -55,19 +55,12 @@ function disconnectHandler(event) { export function initializeSerialBackend() { $("a.connection_button__link").on("click", connectDisconnect); - EventBus.$on("port-handler:auto-select-serial-device", function (device) { - if ( - !GUI.connected_to && - !GUI.connecting_to && - GUI.active_tab !== "firmware_flasher" && - ((PortHandler.portPicker.autoConnect && !["manual", "virtual"].includes(device)) || - Date.now() - rebootTimestamp < REBOOT_CONNECT_MAX_TIME_MS) - ) { - connectDisconnect(); - } - }); + const autoConnectEvents = [ + "port-handler:auto-select-webserial-device", + "port-handler:auto-select-webbluetooth-device", + ]; - EventBus.$on("port-handler:auto-select-bluetooth-device", function (device) { + const autoConnectHandler = function (device) { if ( !GUI.connected_to && !GUI.connecting_to && @@ -77,6 +70,10 @@ export function initializeSerialBackend() { ) { connectDisconnect(); } + }; + + autoConnectEvents.forEach((eventName) => { + EventBus.$on(eventName, autoConnectHandler); }); // Using serial and bluetooth we don't know which event we need before we connect