diff --git a/arduino-ide-extension/src/browser/boards/boards-data-store.ts b/arduino-ide-extension/src/browser/boards/boards-data-store.ts index 1c23fb38f..d4204c703 100644 --- a/arduino-ide-extension/src/browser/boards/boards-data-store.ts +++ b/arduino-ide-extension/src/browser/boards/boards-data-store.ts @@ -222,6 +222,20 @@ export class BoardsDataStore return data; } + async reloadBoardData(fqbn: string | undefined): Promise { + if (!fqbn) { + return; + } + const key = this.getStorageKey(fqbn); + const details = await this.loadBoardDetails(fqbn, true); + if (!details) { + return; + } + const data = createDataStoreEntry(details); + await this.storageService.setData(key, data); + this.fireChanged({ fqbn, data }); + } + async selectProgrammer({ fqbn, selectedProgrammer, @@ -299,9 +313,15 @@ export class BoardsDataStore return `.arduinoIDE-configOptions-${fqbn}`; } - async loadBoardDetails(fqbn: string): Promise { + async loadBoardDetails( + fqbn: string, + forceRefresh = false + ): Promise { try { - const details = await this.boardsService.getBoardDetails({ fqbn }); + const details = await this.boardsService.getBoardDetails({ + fqbn, + forceRefresh, + }); return details; } catch (err) { if ( diff --git a/arduino-ide-extension/src/browser/contributions/board-selection.ts b/arduino-ide-extension/src/browser/contributions/board-selection.ts index ddeda87bc..f9c2d2b36 100644 --- a/arduino-ide-extension/src/browser/contributions/board-selection.ts +++ b/arduino-ide-extension/src/browser/contributions/board-selection.ts @@ -20,6 +20,7 @@ import { } from '../../common/protocol'; import type { BoardList } from '../../common/protocol/board-list'; import { BoardsListWidget } from '../boards/boards-list-widget'; +import { BoardsDataStore } from '../boards/boards-data-store'; import { BoardsServiceProvider } from '../boards/boards-service-provider'; import { ArduinoMenus, @@ -39,6 +40,8 @@ export class BoardSelection extends SketchContribution { private readonly menuModelRegistry: MenuModelRegistry; @inject(NotificationCenter) private readonly notificationCenter: NotificationCenter; + @inject(BoardsDataStore) + private readonly boardsDataStore: BoardsDataStore; @inject(BoardsService) private readonly boardsService: BoardsService; @inject(BoardsServiceProvider) @@ -74,6 +77,29 @@ SN: ${SN} }); }, }); + + registry.registerCommand(BoardSelection.Commands.RELOAD_BOARD_DATA, { + execute: async () => { + const selectedFqbn = + this.boardsServiceProvider.boardList.boardsConfig.selectedBoard?.fqbn; + let message: string; + + if (selectedFqbn) { + await this.boardsDataStore.reloadBoardData(selectedFqbn); + message = nls.localize( + 'arduino/board/boardDataReloaded', + 'Board data reloaded.' + ); + } else { + message = nls.localize( + 'arduino/board/selectBoardToReload', + 'Please select a board first.' + ); + } + + this.messageService.info(message, { timeout: 2000 }); + }, + }); } override onStart(): void { @@ -151,6 +177,21 @@ SN: ${SN} ) ); + const reloadBoardData = { + commandId: BoardSelection.Commands.RELOAD_BOARD_DATA.id, + label: nls.localize('arduino/board/reloadBoardData', 'Reload Board Data'), + order: '102', + }; + this.menuModelRegistry.registerMenuAction( + ArduinoMenus.TOOLS__BOARD_SELECTION_GROUP, + reloadBoardData + ); + this.toDisposeBeforeMenuRebuild.push( + Disposable.create(() => + this.menuModelRegistry.unregisterMenuAction(reloadBoardData) + ) + ); + const getBoardInfo = { commandId: BoardSelection.Commands.GET_BOARD_INFO.id, label: nls.localize('arduino/board/getBoardInfo', 'Get Board Info'), @@ -361,5 +402,8 @@ SN: ${SN} export namespace BoardSelection { export namespace Commands { export const GET_BOARD_INFO: Command = { id: 'arduino-get-board-info' }; + export const RELOAD_BOARD_DATA: Command = { + id: 'arduino-reload-board-data', + }; } } diff --git a/arduino-ide-extension/src/common/protocol/boards-service.ts b/arduino-ide-extension/src/common/protocol/boards-service.ts index d76406216..a97dc9057 100644 --- a/arduino-ide-extension/src/common/protocol/boards-service.ts +++ b/arduino-ide-extension/src/common/protocol/boards-service.ts @@ -67,7 +67,10 @@ export interface BoardsService skipPostInstall?: boolean; }): Promise; getDetectedPorts(): Promise; - getBoardDetails(options: { fqbn: string }): Promise; + getBoardDetails(options: { + fqbn: string; + forceRefresh?: boolean; + }): Promise; getBoardPackage(options: { id: string /* TODO: change to PlatformIdentifier type? */; }): Promise; diff --git a/arduino-ide-extension/src/node/boards-service-impl.ts b/arduino-ide-extension/src/node/boards-service-impl.ts index ea77f8a5f..a5572a1f6 100644 --- a/arduino-ide-extension/src/node/boards-service-impl.ts +++ b/arduino-ide-extension/src/node/boards-service-impl.ts @@ -73,7 +73,11 @@ export class BoardsServiceImpl async getBoardDetails(options: { fqbn: string; + forceRefresh?: boolean; }): Promise { + if (options.forceRefresh) { + await this.refresh(); + } const coreClient = await this.coreClient; const { client, instance } = coreClient; const { fqbn } = options; diff --git a/i18n/en.json b/i18n/en.json index 22babc740..37c90e2e6 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -13,6 +13,7 @@ "board": { "board": "Board{0}", "boardConfigDialogTitle": "Select Other Board and Port", + "boardDataReloaded": "Board data reloaded.", "boardInfo": "Board Info", "boards": "boards", "configDialog1": "Select both a Board and a Port if you want to upload a sketch.", @@ -31,10 +32,12 @@ "port": "Port{0}", "ports": "ports", "programmer": "Programmer", + "reloadBoardData": "Reload Board Data", "reselectLater": "Reselect later", "revertBoardsConfig": "Use '{0}' discovered on '{1}'", "searchBoard": "Search board", "selectBoard": "Select Board", + "selectBoardToReload": "Please select a board first.", "selectPortForInfo": "Please select a port to obtain board info.", "showAllAvailablePorts": "Shows all available ports when enabled", "showAllPorts": "Show all ports",