diff --git a/arduino-ide-extension/src/browser/contributions/board-selection.ts b/arduino-ide-extension/src/browser/contributions/board-selection.ts index 4e1e148fc..cd088f057 100644 --- a/arduino-ide-extension/src/browser/contributions/board-selection.ts +++ b/arduino-ide-extension/src/browser/contributions/board-selection.ts @@ -9,10 +9,7 @@ import { BoardsConfig } from '../boards/boards-config'; import { MainMenuManager } from '../../common/main-menu-manager'; import { BoardsListWidget } from '../boards/boards-list-widget'; import { NotificationCenter } from '../notification-center'; -import { - AvailableBoard, - BoardsServiceProvider, -} from '../boards/boards-service-provider'; +import { BoardsServiceProvider } from '../boards/boards-service-provider'; import { ArduinoMenus, PlaceholderMenuNode, @@ -23,6 +20,7 @@ import { InstalledBoardWithPackage, AvailablePorts, Port, + Board, } from '../../common/protocol'; import { SketchContribution, Command, CommandRegistry } from './contribution'; import { nls } from '@theia/core/lib/common'; @@ -84,7 +82,6 @@ export class BoardSelection extends SketchContribution { } // IDE2 must show the board info based on the selected port. // https://github.com/arduino/arduino-ide/issues/1489 - // IDE 1.x does not support network ports if (selectedPort.protocol === 'network') { this.messageService.info( @@ -95,21 +92,19 @@ export class BoardSelection extends SketchContribution { ); return; } + // serial protocol with one or many detected boards or available VID+PID properties from the port + const isNonNativeSerial = (port: Port, boards: Board[]) => { + return ( + port.protocol === 'serial' && + (boards.length || + (port.properties?.['vid'] && port.properties?.['pid'])) + ); + }; const selectedPortKey = Port.keyOf(selectedPort); - console.log('selectedportkey', JSON.stringify(selectedPortKey)); - console.log( - 'availableboards', - JSON.stringify( - this.boardsServiceProvider.availableBoards.filter( - AvailableBoard.hasPort - ) - ) - ); - const state = await this.boardsService.getState(); const boardListOnSelectedPort = Object.entries(state).filter( - ([portKey, [, boards]]) => - portKey === selectedPortKey && boards.length + ([portKey, [port, boards]]) => + portKey === selectedPortKey && isNonNativeSerial(port, boards) ); // IDE 1.x show this when cannot identify for example a ESP8266MOD although compile and upload works if (!boardListOnSelectedPort.length) { @@ -123,7 +118,6 @@ export class BoardSelection extends SketchContribution { } const [, [port, boards]] = boardListOnSelectedPort[0]; - boardListOnSelectedPort.length && boardListOnSelectedPort[0]; if (boardListOnSelectedPort.length > 1 || boards.length > 1) { console.warn( `Detected more than one available boards on the selected port : ${JSON.stringify( @@ -139,10 +133,17 @@ export class BoardSelection extends SketchContribution { !!s ? s : '(null)'; const readProperty = (property: string, port: Port) => falsyToNullString(port.properties?.[property]); - const BN = board.name; + const BN = + board?.name ?? + nls.localize('arduino/board/unknownBoard', 'Unknown board'); const VID = readProperty('vid', port); const PID = readProperty('pid', port); - const SN = readProperty('serialNumber', port); + const SN = board + ? readProperty('serialNumber', port) + : nls.localize( + 'arduino/board/unknownBoardSerialNumber', + 'Upload any sketch to obtain it.' + ); const detail = ` BN: ${BN} VID: ${VID} diff --git a/i18n/en.json b/i18n/en.json index 51681edd5..2cdfc1574 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -39,7 +39,9 @@ "showAllPorts": "Show all ports", "succesfullyInstalledPlatform": "Successfully installed platform {0}:{1}", "succesfullyUninstalledPlatform": "Successfully uninstalled platform {0}:{1}", - "typeOfPorts": "{0} ports" + "typeOfPorts": "{0} ports", + "unknownBoard": "Unknown board", + "unknownBoardSerialNumber": "Upload any sketch to obtain it." }, "boardsManager": "Boards Manager", "boardsType": {