Skip to content

Commit d515809

Browse files
committed
Clean up auto-detect logic
1 parent 85d03b4 commit d515809

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

stores/deviceStore.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,20 @@ export const useDeviceStore = defineStore("device", {
153153
// biome-ignore lint/suspicious/noExplicitAny: FUGGEDABOUTIT
154154
connection.events.onDeviceMetadataPacket.subscribe((packet: any) => {
155155
// Try to find the device by pio env name first, then hw model if that fails
156-
const device = this.targets.find(
157-
(target: DeviceHardware) => target.platformioTarget === packet?.data?.platformioTarget,
158-
) || this.targets.find(
159-
(target: DeviceHardware) => target.hwModel === packet?.data?.hwModel,
160-
);
161-
console.log("Found device onDeviceMetadataPacket", device);
156+
let device = <undefined | DeviceHardware> undefined;
157+
const targets = [...this.targets].sort((a, b) => a.hwModel - b.hwModel);
158+
if (packet?.data?.platformioTarget?.length > 0) {
159+
device = targets.find(
160+
(target: DeviceHardware) => target.platformioTarget === packet?.data?.platformioTarget,
161+
);
162+
}
163+
if (!device) {
164+
device = targets.find(
165+
(target: DeviceHardware) => target.hwModel === packet?.data?.hwModel,
166+
);
167+
}
162168
if (device) {
169+
console.log("Found device onDeviceMetadataPacket", device);
163170
this.setSelectedTarget(device);
164171
}
165172
});

0 commit comments

Comments
 (0)