Skip to content

Commit e444956

Browse files
author
Akos Kitta
committed
Show ports if has recognized board attached to it.
Closes #1365 - Ref: 79ea0fa - Ref: 74bfdc4 Signed-off-by: Akos Kitta <[email protected]>
1 parent 5cb9166 commit e444956

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

Diff for: arduino-ide-extension/src/browser/boards/boards-config.tsx

+3-8
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,9 @@ export class BoardsConfig extends React.Component<
337337
if (this.state.showAllPorts) {
338338
ports = this.state.knownPorts;
339339
} else {
340-
ports = this.state.knownPorts.filter((port) => {
341-
if (port.protocol === 'serial' || port.protocol === 'network') {
342-
// Allow all `serial` and `network` boards.
343-
// IDE2 must support better label for unrecognized `network` boards: https://github.com/arduino/arduino-ide/issues/1331
344-
return true;
345-
}
346-
return false;
347-
});
340+
ports = this.state.knownPorts.filter(
341+
Port.visiblePorts(this.availableBoards)
342+
);
348343
}
349344
return !ports.length ? (
350345
<div className="loading noselect">

Diff for: arduino-ide-extension/src/browser/boards/boards-service-provider.ts

+3-8
Original file line numberDiff line numberDiff line change
@@ -528,14 +528,9 @@ export class BoardsServiceProvider implements FrontendApplicationContribution {
528528
const currentAvailableBoards = this._availableBoards;
529529
const availableBoards: AvailableBoard[] = [];
530530
const attachedBoards = this._attachedBoards.filter(({ port }) => !!port);
531-
const availableBoardPorts = availablePorts.filter((port) => {
532-
if (port.protocol === 'serial' || port.protocol === 'network') {
533-
// Allow all `serial` and `network` boards.
534-
// IDE2 must support better label for unrecognized `network` boards: https://github.com/arduino/arduino-ide/issues/1331
535-
return true;
536-
}
537-
return false;
538-
});
531+
const availableBoardPorts = availablePorts.filter(
532+
Port.visiblePorts(attachedBoards)
533+
);
539534

540535
for (const boardPort of availableBoardPorts) {
541536
const board = attachedBoards.find(({ port }) =>

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

+26
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,32 @@ export namespace Port {
259259
}
260260
return false;
261261
}
262+
// See https://github.com/arduino/arduino-ide/commit/79ea0fa9a6ad2b01eaac22cef2f494d3b68284e6#diff-fb37f20bea00881acee3aafddb1ecefcecf41ce59845ca1510da79e918ee0837L338-L348
263+
// See https://github.com/arduino/arduino-ide/commit/79ea0fa9a6ad2b01eaac22cef2f494d3b68284e6#diff-e42c82bb67e277cfa4598239952afd65db44dba55dc7d68df619dfccfa648279L441-L455
264+
// See https://github.com/arduino/arduino-ide/commit/74bfdc4c56d7a1577a4e800a378c21b82c1da5f8#diff-e42c82bb67e277cfa4598239952afd65db44dba55dc7d68df619dfccfa648279L405-R424
265+
/**
266+
* All ports with `'serial'` or `'network'` `protocol`, or any other port `protocol` that has at least one recognized board connected to.
267+
*/
268+
export function visiblePorts(
269+
boardsHaystack: ReadonlyArray<Board>
270+
): (port: Port) => boolean {
271+
return (port: Port) => {
272+
if (port.protocol === 'serial' || port.protocol === 'network') {
273+
// Allow all `serial` and `network` boards.
274+
// IDE2 must support better label for unrecognized `network` boards: https://github.com/arduino/arduino-ide/issues/1331
275+
return true;
276+
}
277+
// All other ports with different protocol are
278+
// only shown if there is a recognized board
279+
// connected
280+
for (const board of boardsHaystack) {
281+
if (board.port?.address === port.address) {
282+
return true;
283+
}
284+
}
285+
return false;
286+
};
287+
}
262288
}
263289

264290
export interface BoardsPackage extends ArduinoComponent {

0 commit comments

Comments
 (0)