@@ -33,6 +33,7 @@ import {
33
33
BoardDetailsRequest ,
34
34
BoardDetailsResponse ,
35
35
BoardListAllRequest ,
36
+ BoardListAllResponse ,
36
37
BoardSearchRequest ,
37
38
} from './cli-protocol/cc/arduino/cli/commands/v1/board_pb' ;
38
39
import {
@@ -200,37 +201,28 @@ export class BoardsServiceImpl
200
201
const req = new BoardSearchRequest ( ) ;
201
202
req . setSearchArgs ( query || '' ) ;
202
203
req . setInstance ( instance ) ;
203
- const boards = await new Promise < BoardWithPackage [ ] > ( ( resolve , reject ) => {
204
- client . boardSearch ( req , ( error , resp ) => {
205
- if ( error ) {
206
- reject ( error ) ;
207
- return ;
208
- }
209
- const boards : Array < BoardWithPackage > = [ ] ;
210
- for ( const board of resp . getBoardsList ( ) ) {
211
- const platform = board . getPlatform ( ) ;
212
- if ( platform ) {
213
- boards . push ( {
214
- name : board . getName ( ) ,
215
- fqbn : board . getFqbn ( ) ,
216
- packageId : platform . getId ( ) ,
217
- packageName : platform . getName ( ) ,
218
- manuallyInstalled : platform . getManuallyInstalled ( ) ,
219
- } ) ;
220
- }
221
- }
222
- resolve ( boards ) ;
223
- } ) ;
224
- } ) ;
225
- return boards ;
204
+ return this . handleListBoards ( client . boardSearch . bind ( client ) , req ) ;
226
205
}
227
206
228
207
async getInstalledBoards ( ) : Promise < BoardWithPackage [ ] > {
229
208
const { instance, client } = await this . coreClient ;
230
209
const req = new BoardListAllRequest ( ) ;
231
210
req . setInstance ( instance ) ;
211
+ return this . handleListBoards ( client . boardListAll . bind ( client ) , req ) ;
212
+ }
213
+
214
+ async handleListBoards (
215
+ getBoards : (
216
+ request : BoardListAllRequest | BoardSearchRequest ,
217
+ callback : (
218
+ error : ServiceError | null ,
219
+ response : BoardListAllResponse
220
+ ) => void
221
+ ) => void ,
222
+ request : BoardListAllRequest | BoardSearchRequest
223
+ ) : Promise < BoardWithPackage [ ] > {
232
224
const boards = await new Promise < BoardWithPackage [ ] > ( ( resolve , reject ) => {
233
- client . boardListAll ( req , ( error , resp ) => {
225
+ getBoards ( request , ( error , resp ) => {
234
226
if ( error ) {
235
227
reject ( error ) ;
236
228
return ;
0 commit comments