@@ -238,17 +238,18 @@ PID: ${PID}`;
238
238
}
239
239
240
240
// Installed ports
241
- const registerPorts = ( protocol : string , ports : AvailablePorts ) => {
241
+ const registerPorts = ( protocol : string , protocolOrder : number , ports : AvailablePorts ) => {
242
242
const addresses = Object . keys ( ports ) ;
243
243
if ( ! addresses . length ) {
244
244
return ;
245
245
}
246
246
247
247
// Register placeholder for protocol
248
- const menuPath = [ ...portsSubmenuPath , protocol ] ;
248
+ const menuPath = [ ...portsSubmenuPath , ` ${ protocolOrder . toString ( ) } _ ${ protocol } ` ] ;
249
249
const placeholder = new PlaceholderMenuNode (
250
250
menuPath ,
251
- `${ firstToUpperCase ( protocol ) } ports`
251
+ `${ firstToUpperCase ( protocol ) } ports` ,
252
+ { order : protocolOrder . toString ( ) } ,
252
253
) ;
253
254
this . menuModelRegistry . registerMenuNode ( menuPath , placeholder ) ;
254
255
this . toDisposeBeforeMenuRebuild . push (
@@ -257,7 +258,17 @@ PID: ${PID}`;
257
258
)
258
259
) ;
259
260
260
- for ( const address of Object . keys ( ports ) ) {
261
+ // First we show addresses with recognized boards connected,
262
+ // then all the rest.
263
+ let sortedAddresses = Object . keys ( ports ) ;
264
+ sortedAddresses . sort ( ( left : string , right : string ) : number => {
265
+ const [ , leftBoards ] = ports [ left ] ;
266
+ const [ , rightBoards ] = ports [ right ] ;
267
+ return rightBoards . length - leftBoards . length ;
268
+ } )
269
+
270
+ for ( let i = 0 ; i < sortedAddresses . length ; i ++ ) {
271
+ const address = sortedAddresses [ i ] ;
261
272
const [ port , boards ] = ports [ address ] ;
262
273
if ( ! boards . length ) {
263
274
boards . push ( { name : '' } ) ;
@@ -281,7 +292,7 @@ PID: ${PID}`;
281
292
const menuAction = {
282
293
commandId : id ,
283
294
label,
284
- order : `1 ${ label } ` , // `1` comes after the placeholder which has order `0`
295
+ order : `${ protocolOrder + i + 1 } ` ,
285
296
} ;
286
297
this . commandRegistry . registerCommand ( command , handler ) ;
287
298
this . toDisposeBeforeMenuRebuild . push (
@@ -295,18 +306,19 @@ PID: ${PID}`;
295
306
} ;
296
307
297
308
const grouped = AvailablePorts . byProtocol ( availablePorts ) ;
309
+ let protocolOrder = 100 ;
298
310
// We first show serial and network ports, then all the rest
299
311
[ "serial" , "network" ] . forEach ( protocol => {
300
312
const ports = grouped . get ( protocol ) ;
301
313
if ( ports ) {
302
- registerPorts ( protocol , ports ) ;
314
+ registerPorts ( protocol , protocolOrder , ports ) ;
315
+ grouped . delete ( protocol ) ;
316
+ protocolOrder = protocolOrder + 100 ;
303
317
}
304
318
} ) ;
305
319
grouped . forEach ( ( ports , protocol ) => {
306
- if ( protocol === "serial" || protocol === "network" ) {
307
- return ;
308
- }
309
- registerPorts ( protocol , ports ) ;
320
+ registerPorts ( protocol , protocolOrder , ports ) ;
321
+ protocolOrder = protocolOrder + 100 ;
310
322
} )
311
323
312
324
this . mainMenuManager . update ( ) ;
0 commit comments