@@ -233,25 +233,32 @@ const timeout = (prom, time) => {
233233}
234234
235235export const serialBoards : { value : any [ ] } = { value : [ ] }
236+ // TODO: resolve callbacks properly
237+ // https://stackoverflow.com/questions/69608234/get-promise-resolve-from-separate-callback
236238const scanForKeyboards = async ( ) => {
237239 console . log ( 'checking for connected keyboards' )
238240 if ( connectedKeyboardPort && connectedKeyboardPort . isOpen ) connectedKeyboardPort . close ( )
239241 const ports = await serialPort . SerialPort . list ( )
240242 const circuitPythonPorts = ports //.filter(port => {
241243 // return port.manufacturer && ['0xCB'].includes(port.manufacturer)
242244 // });
243- let boards = await Promise . allSettled (
245+ const boards = ( await Promise . allSettled (
244246 circuitPythonPorts . map ( async ( a ) => await timeout ( getBoardInfo ( a ) , 2000 ) )
245- )
246- boards = boards . filter ( ( a ) => a . value !== undefined ) . map ( ( a ) => a . value )
247+ ) ) as {
248+ status : 'fulfilled' | 'rejected'
249+ value : { name : string ; id : string ; path : string }
250+ } [ ]
251+ const filteredBoards : { name : string ; id : string ; path : string } [ ] = boards
252+ . filter ( ( a ) => a . value !== undefined )
253+ . map ( ( a ) => a . value )
247254
248255 console . log ( 'boards ready' )
249- boards . map ( ( a ) => console . log ( `${ a . name } - ${ a . id } | ${ a . path } ` ) )
256+ filteredBoards . map ( ( a ) => console . log ( `${ a . name } - ${ a . id } | ${ a . path } ` ) )
250257 mainWindow ?. webContents . send ( 'keyboardScan' , {
251- keyboards : boards
258+ keyboards : filteredBoards
252259 } )
253- serialBoards . value = boards
254- return boards
260+ serialBoards . value = filteredBoards
261+ return filteredBoards
255262}
256263
257264let currentPackage = ''
0 commit comments