@@ -247,19 +247,17 @@ PID: ${PID}`;
247
247
}
248
248
249
249
// Installed ports
250
- const registerPorts = ( ports : AvailablePorts ) => {
250
+ const registerPorts = ( protocol : string , ports : AvailablePorts ) => {
251
251
const addresses = Object . keys ( ports ) ;
252
252
if ( ! addresses . length ) {
253
253
return ;
254
254
}
255
255
256
256
// Register placeholder for protocol
257
- const [ port ] = ports [ addresses [ 0 ] ] ;
258
- const protocol = port . protocol ;
259
257
const menuPath = [ ...portsSubmenuPath , protocol ] ;
260
258
const placeholder = new PlaceholderMenuNode (
261
259
menuPath ,
262
- `${ firstToUpperCase ( port . protocol ) } ports`
260
+ `${ firstToUpperCase ( protocol ) } ports`
263
261
) ;
264
262
this . menuModelRegistry . registerMenuNode ( menuPath , placeholder ) ;
265
263
this . toDisposeBeforeMenuRebuild . push (
@@ -268,63 +266,68 @@ PID: ${PID}`;
268
266
)
269
267
) ;
270
268
271
- for ( const address of addresses ) {
272
- if ( ! ! ports [ address ] ) {
273
- const [ port , boards ] = ports [ address ] ;
274
- if ( ! boards . length ) {
275
- boards . push ( {
276
- name : '' ,
277
- } ) ;
278
- }
279
- for ( const { name, fqbn } of boards ) {
280
- const id = `arduino-select-port--${ address } ${
281
- fqbn ? `--${ fqbn } ` : ''
282
- } `;
283
- const command = { id } ;
284
- const handler = {
285
- execute : ( ) => {
286
- if (
287
- ! Port . equals (
288
- port ,
289
- this . boardsServiceProvider . boardsConfig . selectedPort
290
- )
291
- ) {
292
- this . boardsServiceProvider . boardsConfig = {
293
- selectedBoard :
294
- this . boardsServiceProvider . boardsConfig . selectedBoard ,
295
- selectedPort : port ,
296
- } ;
297
- }
298
- } ,
299
- isToggled : ( ) =>
300
- Port . equals (
269
+ for ( const address of Object . keys ( ports ) ) {
270
+ const [ port , boards ] = ports [ address ] ;
271
+ if ( ! boards . length ) {
272
+ boards . push ( { name : '' } ) ;
273
+ }
274
+ for ( const { name, fqbn } of boards ) {
275
+ const id = `arduino-select-port--${ address } ${
276
+ fqbn ? `--${ fqbn } ` : ''
277
+ } `;
278
+ const command = { id } ;
279
+ const handler = {
280
+ execute : ( ) => {
281
+ if (
282
+ ! Port . equals (
301
283
port ,
302
284
this . boardsServiceProvider . boardsConfig . selectedPort
303
- ) ,
304
- } ;
305
- const label = `${ address } ${ name ? ` (${ name } )` : '' } ` ;
306
- const menuAction = {
307
- commandId : id ,
308
- label,
309
- order : `1${ label } ` , // `1` comes after the placeholder which has order `0`
310
- } ;
311
- this . commandRegistry . registerCommand ( command , handler ) ;
312
- this . toDisposeBeforeMenuRebuild . push (
313
- Disposable . create ( ( ) =>
314
- this . commandRegistry . unregisterCommand ( command )
315
- )
316
- ) ;
317
- this . menuModelRegistry . registerMenuAction ( menuPath , menuAction ) ;
318
- }
285
+ )
286
+ ) {
287
+ this . boardsServiceProvider . boardsConfig = {
288
+ selectedBoard :
289
+ this . boardsServiceProvider . boardsConfig . selectedBoard ,
290
+ selectedPort : port ,
291
+ } ;
292
+ }
293
+ } ,
294
+ isToggled : ( ) =>
295
+ Port . equals (
296
+ port ,
297
+ this . boardsServiceProvider . boardsConfig . selectedPort
298
+ ) ,
299
+ } ;
300
+ const label = `${ address } ${ name ? ` (${ name } )` : '' } ` ;
301
+ const menuAction = {
302
+ commandId : id ,
303
+ label,
304
+ order : `1${ label } ` , // `1` comes after the placeholder which has order `0`
305
+ } ;
306
+ this . commandRegistry . registerCommand ( command , handler ) ;
307
+ this . toDisposeBeforeMenuRebuild . push (
308
+ Disposable . create ( ( ) =>
309
+ this . commandRegistry . unregisterCommand ( command )
310
+ )
311
+ ) ;
312
+ this . menuModelRegistry . registerMenuAction ( menuPath , menuAction ) ;
319
313
}
320
314
}
321
315
} ;
322
316
323
- const { serial, network, unknown } =
324
- AvailablePorts . groupByProtocol ( availablePorts ) ;
325
- registerPorts ( serial ) ;
326
- registerPorts ( network ) ;
327
- registerPorts ( unknown ) ;
317
+ const grouped = AvailablePorts . byProtocol ( availablePorts ) ;
318
+ // We first show serial and network ports, then all the rest
319
+ [ 'serial' , 'network' ] . forEach ( ( protocol ) => {
320
+ const ports = grouped . get ( protocol ) ;
321
+ if ( ports ) {
322
+ registerPorts ( protocol , ports ) ;
323
+ }
324
+ } ) ;
325
+ grouped . forEach ( ( ports , protocol ) => {
326
+ if ( protocol === 'serial' || protocol === 'network' ) {
327
+ return ;
328
+ }
329
+ registerPorts ( protocol , ports ) ;
330
+ } ) ;
328
331
329
332
this . mainMenuManager . update ( ) ;
330
333
}
0 commit comments