9494 </ol >
9595
9696 <div v-if =" firmwareStore.canShowFlash" >
97- <a
98- v-if =" firmwareStore.selectedFirmware?.id"
99- :href =" downloadUf2FileUrl"
100- class =" text-black inline-flex w-full justify-center bg-meshtastic hover:bg-gray-200 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center"
101- >
102- {{ $t('flash.uf2.download_uf2') }}
103- </a >
104- <button
105- v-else
106- class =" text-black inline-flex w-full justify-center bg-meshtastic hover:bg-gray-200 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center"
107- @click =" downloadUf2FileFs"
108- >
109- {{ $t('flash.uf2.download_uf2') }}
110- </button >
97+ <template v-if =" hasVariantChoices " >
98+ <div class =" grid gap-2" >
99+ <template v-for =" variant in variantTargets " :key =" variant .platformioTarget " >
100+ <a
101+ v-if =" firmwareStore.selectedFirmware?.id"
102+ :href =" getDownloadUf2Url(variant)"
103+ class =" text-black inline-flex w-full justify-center bg-meshtastic hover:bg-gray-200 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center"
104+ >
105+ {{ formatVariantLabel(variant) }} &ndash ; {{ $t('flash.uf2.download_uf2') }}
106+ </a >
107+ <button
108+ v-else
109+ type =" button"
110+ class =" text-black inline-flex w-full justify-center bg-meshtastic hover:bg-gray-200 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center"
111+ @click =" downloadUf2FileFsForTarget(variant)"
112+ >
113+ {{ formatVariantLabel(variant) }} &ndash ; {{ $t('flash.uf2.download_uf2') }}
114+ </button >
115+ </template >
116+ </div >
117+ </template >
118+ <template v-else >
119+ <a
120+ v-if =" firmwareStore.selectedFirmware?.id"
121+ :href =" getDownloadUf2Url(deviceStore.$state.selectedTarget)"
122+ class =" text-black inline-flex w-full justify-center bg-meshtastic hover:bg-gray-200 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center"
123+ >
124+ {{ $t('flash.uf2.download_uf2') }}
125+ </a >
126+ <button
127+ v-else
128+ class =" text-black inline-flex w-full justify-center bg-meshtastic hover:bg-gray-200 focus:ring-4 focus:outline-none focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center"
129+ @click =" downloadUf2FileFsForTarget(deviceStore.$state.selectedTarget)"
130+ >
131+ {{ $t('flash.uf2.download_uf2') }}
132+ </button >
133+ </template >
111134 </div >
112135 </div >
113136 </div >
@@ -119,24 +142,63 @@ import {
119142 FolderDown ,
120143 Info ,
121144} from ' lucide-vue-next'
122- import { track } from ' @vercel/analytics'
123145import { computed } from ' vue'
124146
125147import { useDeviceStore } from ' ../../stores/deviceStore'
126148import { useFirmwareStore } from ' ../../stores/firmwareStore'
149+ import type { DeviceHardware } from ' ~/types/api'
127150import FlashHeader from ' ./FlashHeader.vue'
128151import ReleaseNotes from ' ./ReleaseNotes.vue'
129152
130153const deviceStore = useDeviceStore ()
131154const firmwareStore = useFirmwareStore ()
132155
133- const downloadUf2FileFs = () => {
156+ const variantTargets = computed <DeviceHardware []>(() => {
157+ const selected = deviceStore .$state .selectedTarget
158+ if (! selected ) return []
159+ const targets = deviceStore .targets || []
160+ let candidates = targets .filter (target => target .hwModel === selected .hwModel )
161+ if (selected .key ) {
162+ const keyMatches = targets .filter (target => target .key === selected .key )
163+ if (keyMatches .length > 0 ) {
164+ candidates = keyMatches
165+ }
166+ }
167+
168+ const uniqueByEnv = new Map <string , DeviceHardware >()
169+ candidates .forEach ((candidate ) => {
170+ uniqueByEnv .set (candidate .platformioTarget , candidate )
171+ })
172+
173+ const result = Array .from (uniqueByEnv .values ())
174+ if (! result .find (candidate => candidate .platformioTarget === selected .platformioTarget )) {
175+ result .push (selected )
176+ }
177+
178+ return result .sort ((a , b ) => {
179+ if (a .displayName === b .displayName ) {
180+ return (a .variant || ' ' ).localeCompare (b .variant || ' ' )
181+ }
182+ return a .displayName .localeCompare (b .displayName )
183+ })
184+ })
185+
186+ const hasVariantChoices = computed (() => variantTargets .value .length > 1 )
187+
188+ const formatVariantLabel = (target ? : DeviceHardware ) => {
189+ if (! target ) return ' '
190+ return target .variant ? ` ${target .displayName } ${target .variant } ` : target .displayName
191+ }
192+
193+ const downloadUf2FileFsForTarget = (target ? : DeviceHardware ) => {
194+ if (! target ) return
134195 let suffix = ' '
135196 if (firmwareStore .shouldInstallInkHud ) {
136197 suffix = ' -inkhud'
137198 }
138- const searchRegex = new RegExp (` firmware-${deviceStore . $state . selectedTarget .platformioTarget }${suffix }-.+.uf2 ` )
199+ const searchRegex = new RegExp (` firmware-${target .platformioTarget }${suffix }-.+.uf2 ` )
139200 console .log (searchRegex )
201+ firmwareStore .trackDownload (target , false )
140202 firmwareStore .downloadUf2FileSystem (searchRegex )
141203}
142204
@@ -148,19 +210,19 @@ const isNewFirmware = computed(() => {
148210const canInstallInkHud = computed (() => {
149211 if (! isNewFirmware .value )
150212 return false
151- return deviceStore .$state .selectedTarget .hasInkHud === true
213+ return deviceStore .$state .selectedTarget ? .hasInkHud === true
152214})
153215
154- const downloadUf2FileUrl = computed (( ) => {
155- if (! firmwareStore .selectedFirmware ?.id ) return ' '
216+ const getDownloadUf2Url = ( target ? : DeviceHardware ) => {
217+ if (! target || ! firmwareStore .selectedFirmware ?.id ) return ' '
156218 const firmwareVersion = firmwareStore .selectedFirmware .id .replace (' v' , ' ' )
157219 let suffix = ' '
158220 if (firmwareStore .shouldInstallInkHud ) {
159221 suffix = ' -inkhud'
160222 }
161- const firmwareFile = ` firmware-${deviceStore . $state . selectedTarget .platformioTarget }${suffix }-${firmwareVersion }.uf2 `
162- firmwareStore .trackDownload (deviceStore . $state . selectedTarget , false )
223+ const firmwareFile = ` firmware-${target .platformioTarget }${suffix }-${firmwareVersion }.uf2 `
224+ firmwareStore .trackDownload (target , false )
163225 console .log (firmwareFile )
164226 return firmwareStore .getReleaseFileUrl (firmwareFile )
165- })
227+ }
166228 </script >
0 commit comments