Skip to content

Commit f35a1e4

Browse files
committed
Fix ports shown multiple times in menu
1 parent 05b4c8d commit f35a1e4

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

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

+28-30
Original file line numberDiff line numberDiff line change
@@ -270,38 +270,36 @@ PID: ${PID}`;
270270
for (let i = 0; i < sortedAddresses.length; i++) {
271271
const address = sortedAddresses[i];
272272
const [port, boards] = ports[address];
273-
if (!boards.length) {
274-
boards.push({ name: '' });
273+
let label = `${address}`;
274+
if (boards.length) {
275+
const boardsList = boards.map(board => board.name).join(", ")
276+
label = `${label} (${boardsList})`
275277
}
276-
for (const { name, fqbn } of boards) {
277-
const id = `arduino-select-port--${address}${fqbn ? `--${fqbn}` : ''}`;
278-
const command = { id };
279-
const handler = {
280-
execute: () => {
281-
if (!Port.equals(port, this.boardsServiceProvider.boardsConfig.selectedPort)) {
282-
this.boardsServiceProvider.boardsConfig = {
283-
selectedBoard:
284-
this.boardsServiceProvider.boardsConfig.selectedBoard,
285-
selectedPort: port,
286-
};
287-
}
288-
},
289-
isToggled: () => Port.equals(port, this.boardsServiceProvider.boardsConfig.selectedPort),
290-
}
291-
const label = `${address}${name ? ` (${name})` : ''}`;
292-
const menuAction = {
293-
commandId: id,
294-
label,
295-
order: `${protocolOrder + i + 1}`,
296-
};
297-
this.commandRegistry.registerCommand(command, handler);
298-
this.toDisposeBeforeMenuRebuild.push(
299-
Disposable.create(() =>
300-
this.commandRegistry.unregisterCommand(command)
301-
)
302-
);
303-
this.menuModelRegistry.registerMenuAction(menuPath, menuAction);
278+
const id = `arduino-select-port--${address}`;
279+
const command = { id };
280+
const handler = {
281+
execute: () => {
282+
if (!Port.equals(port, this.boardsServiceProvider.boardsConfig.selectedPort)) {
283+
this.boardsServiceProvider.boardsConfig = {
284+
selectedBoard: this.boardsServiceProvider.boardsConfig.selectedBoard,
285+
selectedPort: port,
286+
};
287+
}
288+
},
289+
isToggled: () => Port.equals(port, this.boardsServiceProvider.boardsConfig.selectedPort),
290+
}
291+
const menuAction = {
292+
commandId: id,
293+
label,
294+
order: `${protocolOrder + i + 1}`
304295
}
296+
this.commandRegistry.registerCommand(command, handler);
297+
this.toDisposeBeforeMenuRebuild.push(
298+
Disposable.create(() =>
299+
this.commandRegistry.unregisterCommand(command)
300+
)
301+
);
302+
this.menuModelRegistry.registerMenuAction(menuPath, menuAction);
305303
}
306304
};
307305

0 commit comments

Comments
 (0)