diff --git a/locales/en/messages.json b/locales/en/messages.json index 476e9230f3..a956439b53 100755 --- a/locales/en/messages.json +++ b/locales/en/messages.json @@ -55,6 +55,9 @@ "portsSelectManual": { "message": "Manual Selection" }, + "portsSelectNone": { + "message": "No connection available" + }, "portsSelectVirtual": { "message": "Virtual Mode (Experimental)", "description": "Configure a Virtual Flight Controller without the need of a physical FC." @@ -113,6 +116,10 @@ "message": "Use mDNS Browser Device discovery on network (experimental)", "description": "Enable mDNS Browser Device discovery in PortHandler (experimental)" }, + "showManualMode": { + "message": "Enable manual connection mode", + "description": "Text for the option to enable or disable manual connection mode" + }, "showVirtualMode": { "message": "Enable virtual connection mode", "description": "Text for the option to enable or disable the virtual FC" diff --git a/src/js/port_handler.js b/src/js/port_handler.js index e1dafe7fd2..da1cb87678 100644 --- a/src/js/port_handler.js +++ b/src/js/port_handler.js @@ -5,7 +5,6 @@ import { generateVirtualApiVersions, getTextWidth } from './utils/common'; import { get as getConfig } from "./ConfigStorage"; import serial from "./serial"; import MdnsDiscovery from "./mdns_discovery"; -import $ from 'jquery'; import { isWeb } from "./utils/isWeb"; const TIMEOUT_CHECK = 500 ; // With 250 it seems that it produces a memory leak and slowdown in some versions, reason unknown @@ -18,6 +17,7 @@ export const usbDevices = { filters: [ ] }; const PortHandler = new function () { + this.currentPorts = []; this.initialPorts = false; this.port_detected_callbacks = []; this.port_removed_callbacks = []; @@ -26,6 +26,7 @@ const PortHandler = new function () { this.showAllSerialDevices = false; this.useMdnsBrowser = false; this.showVirtualMode = false; + this.showManualMode = false; }; PortHandler.initialize = function () { @@ -56,6 +57,7 @@ PortHandler.reinitialize = function () { } this.showVirtualMode = getConfig('showVirtualMode').showVirtualMode; + this.showManualMode = getConfig('showManualMode').showManualMode; this.showAllSerialDevices = getConfig('showAllSerialDevices').showAllSerialDevices; this.useMdnsBrowser = getConfig('useMdnsBrowser').useMdnsBrowser; @@ -86,10 +88,10 @@ PortHandler.check_serial_devices = function () { const self = this; serial.getDevices(function(cp) { - let currentPorts = []; + self.currentPorts = []; if (self.useMdnsBrowser) { - currentPorts = [ + self.currentPorts = [ ...cp, ...(MdnsDiscovery.mdnsBrowser.services?.filter(s => s.txt?.vendor === 'elrs' && s.txt?.type === 'rx' && s.ready === true) .map(s => s.addresses.map(a => ({ @@ -101,36 +103,35 @@ PortHandler.check_serial_devices = function () { }))).flat() ?? []), ].filter(Boolean); } else { - currentPorts = cp; + self.currentPorts = cp; } // auto-select port (only during initialization) if (!self.initialPorts) { - currentPorts = self.updatePortSelect(currentPorts); - self.selectPort(currentPorts); - self.initialPorts = currentPorts; + self.updatePortSelect(self.currentPorts); + self.selectActivePort(); + self.initialPorts = self.currentPorts; GUI.updateManualPortVisibility(); } else { - self.removePort(currentPorts); - self.detectPort(currentPorts); + self.removePort(); + self.detectPort(); } }); }; PortHandler.check_usb_devices = function (callback) { const self = this; + chrome.usb.getDevices(usbDevices, function (result) { const dfuElement = self.portPickerElement.children("[value='DFU']"); if (result.length) { + // Found device in DFU mode, add it to the list if (!dfuElement.length) { self.portPickerElement.empty(); - let usbText; - if (result[0].productName) { - usbText = (`DFU - ${result[0].productName}`); - } else { - usbText = "DFU"; - } + + const productName = result[0].productName; + const usbText = productName ? `DFU - ${productName}` : 'DFU'; self.portPickerElement.append($('