@@ -3,6 +3,12 @@ import { EventBus } from "../components/eventBus";
33import { serial } from "./serial.js" ;
44import WEBUSBDFU from "./protocols/webusbdfu" ;
55import { reactive } from "vue" ;
6+ import {
7+ checkBrowserCompatibility ,
8+ checkWebBluetoothSupport ,
9+ checkWebSerialSupport ,
10+ checkWebUSBSupport ,
11+ } from "./utils/checkBrowserCompatibility.js" ;
612
713const DEFAULT_PORT = "noselection" ;
814const DEFAULT_BAUDS = 115200 ;
@@ -27,7 +33,17 @@ const PortHandler = new (function () {
2733 this . bluetoothAvailable = false ;
2834 this . dfuAvailable = false ;
2935 this . portAvailable = false ;
30- this . showAllSerialDevices = false ;
36+
37+ checkBrowserCompatibility ( ) ;
38+
39+ this . showBluetoothOption = checkWebBluetoothSupport ( ) ;
40+ this . showSerialOption = checkWebSerialSupport ( ) ;
41+ this . showUsbOption = checkWebUSBSupport ( ) ;
42+
43+ console . log ( `${ this . logHead } Bluetooth available: ${ this . showBluetoothOption } ` ) ;
44+ console . log ( `${ this . logHead } Serial available: ${ this . showSerialOption } ` ) ;
45+ console . log ( `${ this . logHead } DFU available: ${ this . showUsbOption } ` ) ;
46+
3147 this . showVirtualMode = getConfig ( "showVirtualMode" , false ) . showVirtualMode ;
3248 this . showManualMode = getConfig ( "showManualMode" , false ) . showManualMode ;
3349 this . showAllSerialDevices = getConfig ( "showAllSerialDevices" , false ) . showAllSerialDevices ;
@@ -183,21 +199,21 @@ PortHandler.selectActivePort = function (suggestedDevice = false) {
183199 }
184200
185201 // If there is a connection, return it
186- // if (selectedPort) {
187- // console.log(`${this.logHead} Using connected device: ${selectedPort.path}`);
188- // selectedPort = selectedPort.path;
189- // return selectedPort;
190- // }
202+ if ( selectedPort ) {
203+ console . log ( `${ this . logHead } Using connected device: ${ selectedPort . path } ` ) ;
204+ selectedPort = selectedPort . path ;
205+ return selectedPort ;
206+ }
191207
192208 // If there is no connection, check for the last used device
193209 // Check if the device is already connected
194- // if (this.portPicker.selectedPort && this.portPicker.selectedPort !== DEFAULT_PORT) {
195- // selectedPort = this.currentSerialPorts.find((device) => device.path === this.portPicker.selectedPort);
196- // if (selectedPort) {
197- // console.log(`${this.logHead} Using previously selected device: ${selectedPort.path}`);
198- // return selectedPort.path;
199- // }
200- // }
210+ if ( this . portPicker . selectedPort && this . portPicker . selectedPort !== DEFAULT_PORT ) {
211+ selectedPort = this . currentSerialPorts . find ( ( device ) => device . path === this . portPicker . selectedPort ) ;
212+ if ( selectedPort ) {
213+ console . log ( `${ this . logHead } Using previously selected device: ${ selectedPort . path } ` ) ;
214+ return selectedPort . path ;
215+ }
216+ }
201217
202218 // Return the suggested device (the new device that has been detected)
203219 if ( ! selectedPort && suggestedDevice ) {
@@ -289,15 +305,23 @@ PortHandler.updateDeviceList = async function (deviceType) {
289305 try {
290306 switch ( deviceType ) {
291307 case "bluetooth" :
292- ports = await serial . getDevices ( "bluetooth" ) ;
308+ if ( this . showBluetoothOption ) {
309+ ports = await serial . getDevices ( "bluetooth" ) ;
310+ }
293311 break ;
294312 case "usb" :
295- ports = await WEBUSBDFU . getDevices ( ) ;
313+ if ( this . showUsbOption ) {
314+ ports = await WEBUSBDFU . getDevices ( ) ;
315+ }
296316 break ;
297317 case "serial" :
298- default :
299- ports = await serial . getDevices ( "serial" ) ;
318+ if ( this . showSerialOption ) {
319+ ports = await serial . getDevices ( "serial" ) ;
320+ }
300321 break ;
322+ default :
323+ console . warn ( `${ this . logHead } Unknown device type: ${ deviceType } ` ) ;
324+ return [ ] ;
301325 }
302326
303327 // Sort the ports
0 commit comments