@@ -7,6 +7,7 @@ import { FrontendApplicationContribution } from '@theia/core/lib/browser/fronten
7
7
import { RecursiveRequired } from '../../common/types' ;
8
8
import { BoardsServiceClient , AttachedBoardsChangeEvent , BoardInstalledEvent , Board , Port , BoardUninstalledEvent } from '../../common/protocol' ;
9
9
import { BoardsConfig } from './boards-config' ;
10
+ import { naturalCompare } from '../../common/utils' ;
10
11
11
12
@injectable ( )
12
13
export class BoardsServiceClientImpl implements BoardsServiceClient , FrontendApplicationContribution {
@@ -262,10 +263,10 @@ export class BoardsServiceClientImpl implements BoardsServiceClient, FrontendApp
262
263
} ) ;
263
264
}
264
265
265
- const sortedAvailableBoards = availableBoards . sort ( AvailableBoard . COMPARATOR ) ;
266
+ const sortedAvailableBoards = availableBoards . sort ( AvailableBoard . compare ) ;
266
267
let hasChanged = sortedAvailableBoards . length !== currentAvailableBoards . length ;
267
268
for ( let i = 0 ; ! hasChanged && i < sortedAvailableBoards . length ; i ++ ) {
268
- hasChanged = AvailableBoard . COMPARATOR ( sortedAvailableBoards [ i ] , currentAvailableBoards [ i ] ) !== 0 ;
269
+ hasChanged = AvailableBoard . compare ( sortedAvailableBoards [ i ] , currentAvailableBoards [ i ] ) !== 0 ;
269
270
}
270
271
if ( hasChanged ) {
271
272
this . _availableBoards = sortedAvailableBoards ;
@@ -312,9 +313,10 @@ export class BoardsServiceClientImpl implements BoardsServiceClient, FrontendApp
312
313
}
313
314
314
315
/**
315
- * Representation of a ready-to-use board, configured by the user. Not all of the available boards are
316
- * necessarily recognized by the CLI (e.g.: it is a 3rd party board) or correctly configured but ready for `verify`.
317
- * If it has the selected board and a associated port, it can be used for `upload`.
316
+ * Representation of a ready-to-use board, either the user has configured it or was automatically recognized by the CLI.
317
+ * An available board was not necessarily recognized by the CLI (e.g.: it is a 3rd party board) or correctly configured but ready for `verify`.
318
+ * If it has the selected board and a associated port, it can be used for `upload`. We render an available board for the user
319
+ * when it has the `port` set.
318
320
*/
319
321
export interface AvailableBoard extends Board {
320
322
readonly state : AvailableBoard . State ;
@@ -339,17 +341,27 @@ export namespace AvailableBoard {
339
341
'incomplete'
340
342
}
341
343
342
- export function isWithPort ( board : AvailableBoard ) : board is AvailableBoard & { port : Port } {
344
+ export function is ( board : any ) : board is AvailableBoard {
345
+ return Board . is ( board ) && 'state' in board ;
346
+ }
347
+
348
+ export function hasPort ( board : AvailableBoard ) : board is AvailableBoard & { port : Port } {
343
349
return ! ! board . port ;
344
350
}
345
351
346
- export const COMPARATOR = ( left : AvailableBoard , right : AvailableBoard ) => {
347
- let result = left . name . localeCompare ( right . name ) ;
352
+ export const compare = ( left : AvailableBoard , right : AvailableBoard ) => {
353
+ if ( left . selected && ! right . selected ) {
354
+ return - 1 ;
355
+ }
356
+ if ( right . selected && ! left . selected ) {
357
+ return 1 ;
358
+ }
359
+ let result = naturalCompare ( left . name , right . name ) ;
348
360
if ( result !== 0 ) {
349
361
return result ;
350
362
}
351
363
if ( left . fqbn && right . fqbn ) {
352
- result = left . name . localeCompare ( right . name ) ;
364
+ result = naturalCompare ( left . fqbn , right . fqbn ) ;
353
365
if ( result !== 0 ) {
354
366
return result ;
355
367
}
0 commit comments