Skip to content

Commit a2dc2b7

Browse files
silvanocerzaAlberto Iannaccone
authored and
Alberto Iannaccone
committed
Fix ports shown multiple times in menu
1 parent 1a11de2 commit a2dc2b7

File tree

1 file changed

+37
-40
lines changed

1 file changed

+37
-40
lines changed

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

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -286,49 +286,46 @@ PID: ${PID}`;
286286
for (let i = 0; i < sortedAddresses.length; i++) {
287287
const address = sortedAddresses[i];
288288
const [port, boards] = ports[address];
289-
if (!boards.length) {
290-
boards.push({ name: '' });
289+
let label = `${address}`;
290+
if (boards.length) {
291+
const boardsList = boards.map((board) => board.name).join(', ');
292+
label = `${label} (${boardsList})`;
291293
}
292-
for (const { name, fqbn } of boards) {
293-
const id = `arduino-select-port--${address}${
294-
fqbn ? `--${fqbn}` : ''
295-
}`;
296-
const command = { id };
297-
const handler = {
298-
execute: () => {
299-
if (
300-
!Port.equals(
301-
port,
302-
this.boardsServiceProvider.boardsConfig.selectedPort
303-
)
304-
) {
305-
this.boardsServiceProvider.boardsConfig = {
306-
selectedBoard:
307-
this.boardsServiceProvider.boardsConfig.selectedBoard,
308-
selectedPort: port,
309-
};
310-
}
311-
},
312-
isToggled: () =>
313-
Port.equals(
294+
const id = `arduino-select-port--${address}`;
295+
const command = { id };
296+
const handler = {
297+
execute: () => {
298+
if (
299+
!Port.equals(
314300
port,
315301
this.boardsServiceProvider.boardsConfig.selectedPort
316-
),
317-
};
318-
const label = `${address}${name ? ` (${name})` : ''}`;
319-
const menuAction = {
320-
commandId: id,
321-
label,
322-
order: `${protocolOrder + i + 1}`,
323-
};
324-
this.commandRegistry.registerCommand(command, handler);
325-
this.toDisposeBeforeMenuRebuild.push(
326-
Disposable.create(() =>
327-
this.commandRegistry.unregisterCommand(command)
328-
)
329-
);
330-
this.menuModelRegistry.registerMenuAction(menuPath, menuAction);
331-
}
302+
)
303+
) {
304+
this.boardsServiceProvider.boardsConfig = {
305+
selectedBoard:
306+
this.boardsServiceProvider.boardsConfig.selectedBoard,
307+
selectedPort: port,
308+
};
309+
}
310+
},
311+
isToggled: () =>
312+
Port.equals(
313+
port,
314+
this.boardsServiceProvider.boardsConfig.selectedPort
315+
),
316+
};
317+
const menuAction = {
318+
commandId: id,
319+
label,
320+
order: `${protocolOrder + i + 1}`,
321+
};
322+
this.commandRegistry.registerCommand(command, handler);
323+
this.toDisposeBeforeMenuRebuild.push(
324+
Disposable.create(() =>
325+
this.commandRegistry.unregisterCommand(command)
326+
)
327+
);
328+
this.menuModelRegistry.registerMenuAction(menuPath, menuAction);
332329
}
333330
};
334331

0 commit comments

Comments
 (0)