File tree 2 files changed +34
-18
lines changed
arduino-ide-extension/src
2 files changed +34
-18
lines changed Original file line number Diff line number Diff line change @@ -184,6 +184,10 @@ export class BoardsConfig extends React.Component<
184
184
. filter ( notEmpty ) ;
185
185
}
186
186
187
+ protected get availableBoards ( ) : Board [ ] {
188
+ return this . props . boardsServiceProvider . availableBoards ;
189
+ }
190
+
187
191
protected queryPorts = async (
188
192
availablePorts : MaybePromise < Port [ ] > = this . availablePorts
189
193
) => {
@@ -281,8 +285,25 @@ export class BoardsConfig extends React.Component<
281
285
}
282
286
283
287
protected renderPorts ( ) : React . ReactNode {
284
- const filter = this . state . showAllPorts ? ( ) => true : Port . isBoardPort ;
285
- const ports = this . state . knownPorts . filter ( filter ) ;
288
+ let ports = [ ] as Port [ ] ;
289
+ debugger ;
290
+ if ( this . state . showAllPorts ) {
291
+ ports = this . state . knownPorts ;
292
+ } else {
293
+ ports = this . state . knownPorts . filter ( ( port ) => {
294
+ if ( port . protocol === 'serial' ) {
295
+ return true ;
296
+ }
297
+ // All other ports with different protocol are
298
+ // only shown if there is a recognized board
299
+ // connected
300
+ for ( const board of this . availableBoards ) {
301
+ if ( board . port ?. address === port . address ) {
302
+ return true ;
303
+ }
304
+ }
305
+ } ) ;
306
+ }
286
307
return ! ports . length ? (
287
308
< div className = "loading noselect" > No ports discovered</ div >
288
309
) : (
Original file line number Diff line number Diff line change @@ -176,25 +176,20 @@ export namespace Port {
176
176
}
177
177
178
178
export function compare ( left : Port , right : Port ) : number {
179
- // Board ports have higher priorities, they come first.
180
- if ( isBoardPort ( left ) && ! isBoardPort ( right ) ) {
179
+ // Ports must be sorted in this order:
180
+ // 1. Serial
181
+ // 2. Network
182
+ // 3. Other protocols
183
+ if ( left . protocol === "serial" && right . protocol !== "serial" ) {
181
184
return - 1 ;
182
- }
183
- if ( ! isBoardPort ( left ) && isBoardPort ( right ) ) {
185
+ } else if ( left . protocol !== "serial" && right . protocol === "serial" ) {
186
+ return 1 ;
187
+ } else if ( left . protocol === "network" && right . protocol !== "network" ) {
188
+ return - 1 ;
189
+ } else if ( left . protocol !== "network" && right . protocol === "network" ) {
184
190
return 1 ;
185
191
}
186
- let result = naturalCompare (
187
- left . protocol . toLocaleLowerCase ( ) ,
188
- right . protocol . toLocaleLowerCase ( )
189
- ) ;
190
- if ( result !== 0 ) {
191
- return result ;
192
- }
193
- result = naturalCompare ( left . address , right . address ) ;
194
- if ( result !== 0 ) {
195
- return result ;
196
- }
197
- return naturalCompare ( left . label || '' , right . label || '' ) ;
192
+ return naturalCompare ( left . address ! , right . address ! ) ;
198
193
}
199
194
200
195
export function equals (
You can’t perform that action at this time.
0 commit comments