@@ -82,15 +82,12 @@ export function initializeSerialBackend() {
8282
8383function connectDisconnect ( ) {
8484 const selectedPort = PortHandler . portPicker . selectedPort ;
85- const portName = selectedPort === "manual" ? PortHandler . portPicker . portOverride : selectedPort ;
8685
87- if ( ! GUI . connect_lock && selectedPort !== "noselection" && ! selectedPort . path ?. startsWith ( "usb_ " ) ) {
86+ if ( ! GUI . connect_lock && selectedPort !== "noselection" && ! selectedPort . path ?. startsWith ( "usb " ) ) {
8887 // GUI control overrides the user control
8988
9089 GUI . configuration_loaded = false ;
9190
92- const baudRate = PortHandler . portPicker . selectedBauds ;
93-
9491 if ( ! isConnected ) {
9592 // prevent connection when we do not have permission
9693 if ( selectedPort . startsWith ( "requestpermission" ) ) {
@@ -103,34 +100,29 @@ function connectDisconnect() {
103100 return ;
104101 }
105102
103+ const portName = selectedPort === "manual" ? PortHandler . portPicker . portOverride : selectedPort ;
104+
106105 console . log ( `${ logHead } Connecting to: ${ portName } ` ) ;
107106 GUI . connecting_to = portName ;
108107
109108 // lock port select & baud while we are connecting / connected
110109 PortHandler . portPickerDisabled = true ;
111110 $ ( "div.connection_button__label" ) . text ( i18n . getMessage ( "connecting" ) ) ;
112111
113- // Set configuration flags for consistency with other code
114- CONFIGURATOR . virtualMode = selectedPort === "virtual" ;
115-
116- // Select the appropriate protocol based directly on the port path
117- serial . selectProtocol ( selectedPort ) ;
118-
119- if ( CONFIGURATOR . virtualMode ) {
120- CONFIGURATOR . virtualApiVersion = PortHandler . portPicker . virtualMspVersion ;
121- // Virtual mode uses a callback instead of port path
122- serial . connect ( onOpenVirtual ) ;
123- } else {
124- // Set up event listeners for all non-virtual connections
112+ // Set up event listeners for non-virtual connections
113+ if ( selectedPort !== "virtual" ) {
125114 serial . removeEventListener ( "connect" , connectHandler ) ;
126115 serial . addEventListener ( "connect" , connectHandler ) ;
127116
128117 serial . removeEventListener ( "disconnect" , disconnectHandler ) ;
129118 serial . addEventListener ( "disconnect" , disconnectHandler ) ;
130-
131- // All non-virtual modes pass the port path and options
132- serial . connect ( portName , { baudRate } ) ;
133119 }
120+
121+ serial . connect (
122+ portName ,
123+ { baudRate : PortHandler . portPicker . selectedBauds } ,
124+ selectedPort === "virtual" ? onOpenVirtual : undefined ,
125+ ) ;
134126 } else {
135127 // If connected, start disconnection sequence
136128 GUI . timeout_kill_all ( ) ;
@@ -348,6 +340,9 @@ function onOpenVirtual() {
348340 GUI . connecting_to = false ;
349341
350342 CONFIGURATOR . connectionValid = true ;
343+ CONFIGURATOR . virtualMode = true ;
344+ CONFIGURATOR . virtualApiVersion = PortHandler . portPicker . virtualMspVersion ;
345+
351346 isConnected = true ;
352347
353348 mspHelper = new MspHelper ( ) ;
0 commit comments