Skip to content

Commit

Permalink
feat: implement reload board data action
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocusinato committed Nov 7, 2024
1 parent 3ccc864 commit 9c0390f
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
24 changes: 22 additions & 2 deletions arduino-ide-extension/src/browser/boards/boards-data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,20 @@ export class BoardsDataStore
return data;
}

async reloadBoardData(fqbn: string | undefined): Promise<void> {
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,
Expand Down Expand Up @@ -299,9 +313,15 @@ export class BoardsDataStore
return `.arduinoIDE-configOptions-${fqbn}`;
}

async loadBoardDetails(fqbn: string): Promise<BoardDetails | undefined> {
async loadBoardDetails(
fqbn: string,
forceRefresh = false
): Promise<BoardDetails | undefined> {
try {
const details = await this.boardsService.getBoardDetails({ fqbn });
const details = await this.boardsService.getBoardDetails({
fqbn,
forceRefresh,
});
return details;
} catch (err) {
if (
Expand Down
44 changes: 44 additions & 0 deletions arduino-ide-extension/src/browser/contributions/board-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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',
};
}
}
5 changes: 4 additions & 1 deletion arduino-ide-extension/src/common/protocol/boards-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ export interface BoardsService
skipPostInstall?: boolean;
}): Promise<void>;
getDetectedPorts(): Promise<DetectedPorts>;
getBoardDetails(options: { fqbn: string }): Promise<BoardDetails | undefined>;
getBoardDetails(options: {
fqbn: string;
forceRefresh?: boolean;
}): Promise<BoardDetails | undefined>;
getBoardPackage(options: {
id: string /* TODO: change to PlatformIdentifier type? */;
}): Promise<BoardsPackage | undefined>;
Expand Down
4 changes: 4 additions & 0 deletions arduino-ide-extension/src/node/boards-service-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ export class BoardsServiceImpl

async getBoardDetails(options: {
fqbn: string;
forceRefresh?: boolean;
}): Promise<BoardDetails | undefined> {
if (options.forceRefresh) {
await this.refresh();
}
const coreClient = await this.coreClient;
const { client, instance } = coreClient;
const { fqbn } = options;
Expand Down
3 changes: 3 additions & 0 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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",
Expand Down

0 comments on commit 9c0390f

Please sign in to comment.