Skip to content

Commit 328c211

Browse files
committed
Reworked board selection dialog ordering
1 parent 374afe0 commit 328c211

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

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

+23-2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ export class BoardsConfig extends React.Component<
184184
.filter(notEmpty);
185185
}
186186

187+
protected get availableBoards(): Board[] {
188+
return this.props.boardsServiceProvider.availableBoards;
189+
}
190+
187191
protected queryPorts = async (
188192
availablePorts: MaybePromise<Port[]> = this.availablePorts
189193
) => {
@@ -281,8 +285,25 @@ export class BoardsConfig extends React.Component<
281285
}
282286

283287
protected renderPorts(): React.ReactNode {
284-
const filter = this.state.showAllPorts ? () => true : Port.isBoardPort;
285-
const ports = this.state.knownPorts.filter(filter);
288+
let ports = [] as Port[];
289+
debugger;
290+
if (this.state.showAllPorts) {
291+
ports = this.state.knownPorts;
292+
} else {
293+
ports = this.state.knownPorts.filter((port) => {
294+
if (port.protocol === 'serial') {
295+
return true;
296+
}
297+
// All other ports with different protocol are
298+
// only shown if there is a recognized board
299+
// connected
300+
for (const board of this.availableBoards) {
301+
if (board.port?.address === port.address) {
302+
return true;
303+
}
304+
}
305+
});
306+
}
286307
return !ports.length ? (
287308
<div className="loading noselect">No ports discovered</div>
288309
) : (

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

+11-16
Original file line numberDiff line numberDiff line change
@@ -176,25 +176,20 @@ export namespace Port {
176176
}
177177

178178
export function compare(left: Port, right: Port): number {
179-
// Board ports have higher priorities, they come first.
180-
if (isBoardPort(left) && !isBoardPort(right)) {
179+
// Ports must be sorted in this order:
180+
// 1. Serial
181+
// 2. Network
182+
// 3. Other protocols
183+
if (left.protocol === "serial" && right.protocol !== "serial") {
181184
return -1;
182-
}
183-
if (!isBoardPort(left) && isBoardPort(right)) {
185+
} else if (left.protocol !== "serial" && right.protocol === "serial") {
186+
return 1;
187+
} else if (left.protocol === "network" && right.protocol !== "network") {
188+
return -1;
189+
} else if (left.protocol !== "network" && right.protocol === "network") {
184190
return 1;
185191
}
186-
let result = naturalCompare(
187-
left.protocol.toLocaleLowerCase(),
188-
right.protocol.toLocaleLowerCase()
189-
);
190-
if (result !== 0) {
191-
return result;
192-
}
193-
result = naturalCompare(left.address, right.address);
194-
if (result !== 0) {
195-
return result;
196-
}
197-
return naturalCompare(left.label || '', right.label || '');
192+
return naturalCompare(left.address!, right.address!);
198193
}
199194

200195
export function equals(

0 commit comments

Comments
 (0)