Skip to content

Commit 41844c9

Browse files
feat: implement menu action to reload current board data (#2553)
1 parent 7c231ff commit 41844c9

File tree

5 files changed

+77
-3
lines changed

5 files changed

+77
-3
lines changed

arduino-ide-extension/src/browser/boards/boards-data-store.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,20 @@ export class BoardsDataStore
222222
return data;
223223
}
224224

225+
async reloadBoardData(fqbn: string | undefined): Promise<void> {
226+
if (!fqbn) {
227+
return;
228+
}
229+
const key = this.getStorageKey(fqbn);
230+
const details = await this.loadBoardDetails(fqbn, true);
231+
if (!details) {
232+
return;
233+
}
234+
const data = createDataStoreEntry(details);
235+
await this.storageService.setData(key, data);
236+
this.fireChanged({ fqbn, data });
237+
}
238+
225239
async selectProgrammer({
226240
fqbn,
227241
selectedProgrammer,
@@ -299,9 +313,15 @@ export class BoardsDataStore
299313
return `.arduinoIDE-configOptions-${fqbn}`;
300314
}
301315

302-
async loadBoardDetails(fqbn: string): Promise<BoardDetails | undefined> {
316+
async loadBoardDetails(
317+
fqbn: string,
318+
forceRefresh = false
319+
): Promise<BoardDetails | undefined> {
303320
try {
304-
const details = await this.boardsService.getBoardDetails({ fqbn });
321+
const details = await this.boardsService.getBoardDetails({
322+
fqbn,
323+
forceRefresh,
324+
});
305325
return details;
306326
} catch (err) {
307327
if (

arduino-ide-extension/src/browser/contributions/board-selection.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from '../../common/protocol';
2121
import type { BoardList } from '../../common/protocol/board-list';
2222
import { BoardsListWidget } from '../boards/boards-list-widget';
23+
import { BoardsDataStore } from '../boards/boards-data-store';
2324
import { BoardsServiceProvider } from '../boards/boards-service-provider';
2425
import {
2526
ArduinoMenus,
@@ -39,6 +40,8 @@ export class BoardSelection extends SketchContribution {
3940
private readonly menuModelRegistry: MenuModelRegistry;
4041
@inject(NotificationCenter)
4142
private readonly notificationCenter: NotificationCenter;
43+
@inject(BoardsDataStore)
44+
private readonly boardsDataStore: BoardsDataStore;
4245
@inject(BoardsService)
4346
private readonly boardsService: BoardsService;
4447
@inject(BoardsServiceProvider)
@@ -74,6 +77,29 @@ SN: ${SN}
7477
});
7578
},
7679
});
80+
81+
registry.registerCommand(BoardSelection.Commands.RELOAD_BOARD_DATA, {
82+
execute: async () => {
83+
const selectedFqbn =
84+
this.boardsServiceProvider.boardList.boardsConfig.selectedBoard?.fqbn;
85+
let message: string;
86+
87+
if (selectedFqbn) {
88+
await this.boardsDataStore.reloadBoardData(selectedFqbn);
89+
message = nls.localize(
90+
'arduino/board/boardDataReloaded',
91+
'Board data reloaded.'
92+
);
93+
} else {
94+
message = nls.localize(
95+
'arduino/board/selectBoardToReload',
96+
'Please select a board first.'
97+
);
98+
}
99+
100+
this.messageService.info(message, { timeout: 2000 });
101+
},
102+
});
77103
}
78104

79105
override onStart(): void {
@@ -151,6 +177,21 @@ SN: ${SN}
151177
)
152178
);
153179

180+
const reloadBoardData = {
181+
commandId: BoardSelection.Commands.RELOAD_BOARD_DATA.id,
182+
label: nls.localize('arduino/board/reloadBoardData', 'Reload Board Data'),
183+
order: '102',
184+
};
185+
this.menuModelRegistry.registerMenuAction(
186+
ArduinoMenus.TOOLS__BOARD_SELECTION_GROUP,
187+
reloadBoardData
188+
);
189+
this.toDisposeBeforeMenuRebuild.push(
190+
Disposable.create(() =>
191+
this.menuModelRegistry.unregisterMenuAction(reloadBoardData)
192+
)
193+
);
194+
154195
const getBoardInfo = {
155196
commandId: BoardSelection.Commands.GET_BOARD_INFO.id,
156197
label: nls.localize('arduino/board/getBoardInfo', 'Get Board Info'),
@@ -361,5 +402,8 @@ SN: ${SN}
361402
export namespace BoardSelection {
362403
export namespace Commands {
363404
export const GET_BOARD_INFO: Command = { id: 'arduino-get-board-info' };
405+
export const RELOAD_BOARD_DATA: Command = {
406+
id: 'arduino-reload-board-data',
407+
};
364408
}
365409
}

arduino-ide-extension/src/common/protocol/boards-service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ export interface BoardsService
6767
skipPostInstall?: boolean;
6868
}): Promise<void>;
6969
getDetectedPorts(): Promise<DetectedPorts>;
70-
getBoardDetails(options: { fqbn: string }): Promise<BoardDetails | undefined>;
70+
getBoardDetails(options: {
71+
fqbn: string;
72+
forceRefresh?: boolean;
73+
}): Promise<BoardDetails | undefined>;
7174
getBoardPackage(options: {
7275
id: string /* TODO: change to PlatformIdentifier type? */;
7376
}): Promise<BoardsPackage | undefined>;

arduino-ide-extension/src/node/boards-service-impl.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ export class BoardsServiceImpl
7373

7474
async getBoardDetails(options: {
7575
fqbn: string;
76+
forceRefresh?: boolean;
7677
}): Promise<BoardDetails | undefined> {
78+
if (options.forceRefresh) {
79+
await this.refresh();
80+
}
7781
const coreClient = await this.coreClient;
7882
const { client, instance } = coreClient;
7983
const { fqbn } = options;

i18n/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"board": {
1414
"board": "Board{0}",
1515
"boardConfigDialogTitle": "Select Other Board and Port",
16+
"boardDataReloaded": "Board data reloaded.",
1617
"boardInfo": "Board Info",
1718
"boards": "boards",
1819
"configDialog1": "Select both a Board and a Port if you want to upload a sketch.",
@@ -31,10 +32,12 @@
3132
"port": "Port{0}",
3233
"ports": "ports",
3334
"programmer": "Programmer",
35+
"reloadBoardData": "Reload Board Data",
3436
"reselectLater": "Reselect later",
3537
"revertBoardsConfig": "Use '{0}' discovered on '{1}'",
3638
"searchBoard": "Search board",
3739
"selectBoard": "Select Board",
40+
"selectBoardToReload": "Please select a board first.",
3841
"selectPortForInfo": "Please select a port to obtain board info.",
3942
"showAllAvailablePorts": "Shows all available ports when enabled",
4043
"showAllPorts": "Show all ports",

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy