diff --git a/arduino-ide-extension/src/browser/boards/boards-config-component.tsx b/arduino-ide-extension/src/browser/boards/boards-config-component.tsx index da50ad0be..f89db8ca4 100644 --- a/arduino-ide-extension/src/browser/boards/boards-config-component.tsx +++ b/arduino-ide-extension/src/browser/boards/boards-config-component.tsx @@ -6,7 +6,6 @@ import * as React from '@theia/core/shared/react'; import { Board, BoardIdentifier, - BoardsConfig, BoardWithPackage, DetectedPort, findMatchingPortIndex, @@ -15,6 +14,7 @@ import { } from '../../common/protocol/boards-service'; import { Defined } from '../../common/types'; import { NotificationCenter } from '../notification-center'; +import { BoardsConfigDialogState } from './boards-config-dialog'; import { EditBoardsConfigActionParams } from './boards-service-provider'; namespace BoardsConfigComponent { @@ -22,7 +22,7 @@ namespace BoardsConfigComponent { /** * This is not the real config, it's only living in the dialog. Users can change it without update and can cancel any modifications. */ - readonly boardsConfig: BoardsConfig; + readonly boardsConfig: BoardsConfigDialogState; readonly notificationCenter: NotificationCenter; readonly appState: FrontendApplicationState; readonly onFocusNodeSet: (element: HTMLElement | undefined) => void; @@ -187,10 +187,7 @@ export class BoardsConfigComponent extends React.Component< }; private readonly selectBoard = (selectedBoard: BoardWithPackage) => { - this.props.onBoardSelected({ - fqbn: selectedBoard.fqbn, - name: selectedBoard.name, - }); + this.props.onBoardSelected(selectedBoard); }; private readonly focusNodeSet = (element: HTMLElement | null) => { diff --git a/arduino-ide-extension/src/browser/boards/boards-config-dialog.tsx b/arduino-ide-extension/src/browser/boards/boards-config-dialog.tsx index 8e5257387..0941550f0 100644 --- a/arduino-ide-extension/src/browser/boards/boards-config-dialog.tsx +++ b/arduino-ide-extension/src/browser/boards/boards-config-dialog.tsx @@ -12,7 +12,6 @@ import { import React from '@theia/core/shared/react'; import type { ReactNode } from '@theia/core/shared/react/index'; import { - BoardIdentifier, BoardsConfig, BoardWithPackage, DetectedPort, @@ -31,8 +30,12 @@ import { @injectable() export class BoardsConfigDialogProps extends DialogProps {} +export type BoardsConfigDialogState = Omit & { + selectedBoard: BoardsConfig['selectedBoard'] | BoardWithPackage; +}; + @injectable() -export class BoardsConfigDialog extends ReactDialog { +export class BoardsConfigDialog extends ReactDialog { @inject(BoardsServiceProvider) private readonly boardsServiceProvider: BoardsServiceProvider; @inject(NotificationCenter) @@ -43,7 +46,7 @@ export class BoardsConfigDialog extends ReactDialog { private readonly onFilterTextDidChangeEmitter: Emitter< Defined >; - private readonly onBoardSelected = (board: BoardIdentifier): void => { + private readonly onBoardSelected = (board: BoardWithPackage): void => { this._boardsConfig.selectedBoard = board; this.update(); }; @@ -64,7 +67,7 @@ export class BoardsConfigDialog extends ReactDialog { ): readonly DetectedPort[] => { return this.boardsServiceProvider.boardList.ports(predicate); }; - private _boardsConfig: BoardsConfig; + private _boardsConfig: BoardsConfigDialogState; private focusNode: HTMLElement | undefined; constructor( @@ -181,7 +184,7 @@ export class BoardsConfigDialog extends ReactDialog { return ''; } - get value(): BoardsConfig { + get value(): BoardsConfigDialogState { return this._boardsConfig; } } diff --git a/arduino-ide-extension/src/common/protocol/boards-service.ts b/arduino-ide-extension/src/common/protocol/boards-service.ts index 9f079eaa9..392703657 100644 --- a/arduino-ide-extension/src/common/protocol/boards-service.ts +++ b/arduino-ide-extension/src/common/protocol/boards-service.ts @@ -483,9 +483,10 @@ export namespace Board { manuallyInstalled: boolean; }>; export function decorateBoards( - selectedBoard: BoardIdentifier | undefined, + selectedBoard: BoardIdentifier | BoardWithPackage | undefined, boards: Array ): Array { + let foundSelected = false; // Board names are not unique. We show the corresponding core name as a detail. // https://github.com/arduino/arduino-cli/pull/294#issuecomment-513764948 const distinctBoardNames = new Map(); @@ -496,28 +497,39 @@ export namespace Board { const selectedBoardPackageId = selectedBoard ? createPlatformIdentifier(selectedBoard) : undefined; - // Due to the non-unique board names, IDE2 has to check the package name. - const selected = (board: BoardWithPackage) => { - if (!!selectedBoard) { - if ( - boardIdentifierEquals( - { name: board.name, fqbn: board.fqbn }, - selectedBoard - ) - ) { + const selectedBoardFqbn = selectedBoard?.fqbn; + // Due to the non-unique board names, IDE2 has to check the package name when boards are not installed and the FQBN is absent. + const isSelected = (board: BoardWithPackage) => { + if (!selectedBoard) { + return false; + } + if (foundSelected) { + return false; + } + let selected = false; + if (board.fqbn && selectedBoardFqbn) { + if (boardIdentifierEquals(board, selectedBoard)) { + selected = true; + } + } + if (!selected) { + if (board.name === selectedBoard.name) { if (selectedBoardPackageId) { - return platformIdentifierEquals( - selectedBoardPackageId, - board.packageId - ); + const boardPackageId = createPlatformIdentifier(board); + if (boardPackageId) { + if ( + platformIdentifierEquals(boardPackageId, selectedBoardPackageId) + ) { + selected = true; + } + } } - if (!board.fqbn && board.name === selectedBoard.name) { - return true; - } - return false; } } - return false; + if (selected) { + foundSelected = true; + } + return selected; }; return boards.map((board) => ({ ...board, @@ -525,7 +537,7 @@ export namespace Board { (distinctBoardNames.get(board.name) || 0) > 1 ? ` - ${board.packageName}` : undefined, - selected: selected(board), + selected: isSelected(board), missing: !installed(board), })); } @@ -711,9 +723,7 @@ export function boardIdentifierEquals( if (left.fqbn && right.fqbn) { const leftFqbn = options.looseFqbn ? sanitizeFqbn(left.fqbn) : left.fqbn; const rightFqbn = options.looseFqbn ? sanitizeFqbn(right.fqbn) : right.fqbn; - if (leftFqbn === rightFqbn) { - return true; - } + return leftFqbn === rightFqbn; } // No more Genuino hack. // https://github.com/arduino/arduino-ide/blob/f6a43254f5c416a2e4fa888875358336b42dd4d5/arduino-ide-extension/src/common/protocol/boards-service.ts#L572-L581