@@ -247,17 +247,25 @@ PID: ${PID}`;
247
247
}
248
248
249
249
// Installed ports
250
- const registerPorts = ( protocol : string , ports : AvailablePorts ) => {
250
+ const registerPorts = (
251
+ protocol : string ,
252
+ protocolOrder : number ,
253
+ ports : AvailablePorts
254
+ ) => {
251
255
const addresses = Object . keys ( ports ) ;
252
256
if ( ! addresses . length ) {
253
257
return ;
254
258
}
255
259
256
260
// Register placeholder for protocol
257
- const menuPath = [ ...portsSubmenuPath , protocol ] ;
261
+ const menuPath = [
262
+ ...portsSubmenuPath ,
263
+ `${ protocolOrder . toString ( ) } _${ protocol } ` ,
264
+ ] ;
258
265
const placeholder = new PlaceholderMenuNode (
259
266
menuPath ,
260
- `${ firstToUpperCase ( protocol ) } ports`
267
+ `${ firstToUpperCase ( protocol ) } ports` ,
268
+ { order : protocolOrder . toString ( ) }
261
269
) ;
262
270
this . menuModelRegistry . registerMenuNode ( menuPath , placeholder ) ;
263
271
this . toDisposeBeforeMenuRebuild . push (
@@ -266,7 +274,17 @@ PID: ${PID}`;
266
274
)
267
275
) ;
268
276
269
- for ( const address of Object . keys ( ports ) ) {
277
+ // First we show addresses with recognized boards connected,
278
+ // then all the rest.
279
+ const sortedAddresses = Object . keys ( ports ) ;
280
+ sortedAddresses . sort ( ( left : string , right : string ) : number => {
281
+ const [ , leftBoards ] = ports [ left ] ;
282
+ const [ , rightBoards ] = ports [ right ] ;
283
+ return rightBoards . length - leftBoards . length ;
284
+ } ) ;
285
+
286
+ for ( let i = 0 ; i < sortedAddresses . length ; i ++ ) {
287
+ const address = sortedAddresses [ i ] ;
270
288
const [ port , boards ] = ports [ address ] ;
271
289
if ( ! boards . length ) {
272
290
boards . push ( { name : '' } ) ;
@@ -301,7 +319,7 @@ PID: ${PID}`;
301
319
const menuAction = {
302
320
commandId : id ,
303
321
label,
304
- order : `1 ${ label } ` , // `1` comes after the placeholder which has order `0`
322
+ order : `${ protocolOrder + i + 1 } ` ,
305
323
} ;
306
324
this . commandRegistry . registerCommand ( command , handler ) ;
307
325
this . toDisposeBeforeMenuRebuild . push (
@@ -315,18 +333,19 @@ PID: ${PID}`;
315
333
} ;
316
334
317
335
const grouped = AvailablePorts . byProtocol ( availablePorts ) ;
336
+ let protocolOrder = 100 ;
318
337
// We first show serial and network ports, then all the rest
319
338
[ 'serial' , 'network' ] . forEach ( ( protocol ) => {
320
339
const ports = grouped . get ( protocol ) ;
321
340
if ( ports ) {
322
- registerPorts ( protocol , ports ) ;
341
+ registerPorts ( protocol , protocolOrder , ports ) ;
342
+ grouped . delete ( protocol ) ;
343
+ protocolOrder = protocolOrder + 100 ;
323
344
}
324
345
} ) ;
325
346
grouped . forEach ( ( ports , protocol ) => {
326
- if ( protocol === 'serial' || protocol === 'network' ) {
327
- return ;
328
- }
329
- registerPorts ( protocol , ports ) ;
347
+ registerPorts ( protocol , protocolOrder , ports ) ;
348
+ protocolOrder = protocolOrder + 100 ;
330
349
} ) ;
331
350
332
351
this . mainMenuManager . update ( ) ;
0 commit comments