From 35e74e4daf16d4b4c5b79b942c449919cc766687 Mon Sep 17 00:00:00 2001 From: Malte Grimm Date: Thu, 23 Mar 2023 00:08:52 +0100 Subject: [PATCH] Add dropdown list to select firmwares --- src/components/Dashboard.tsx | 89 +++++++++++++++++++++++++++++++++++- src/core/stores/appStore.ts | 23 +++++++++- 2 files changed, 109 insertions(+), 3 deletions(-) diff --git a/src/components/Dashboard.tsx b/src/components/Dashboard.tsx index 679818eb..c0f37810 100644 --- a/src/components/Dashboard.tsx +++ b/src/components/Dashboard.tsx @@ -9,7 +9,8 @@ import { XIcon, BluetoothIcon, UsbIcon, - NetworkIcon + NetworkIcon, + RefreshCwIcon } from "lucide-react"; import { Subtle } from "@components/UI/Typography/Subtle.js"; import { H3 } from "@components/UI/Typography/H3.js"; @@ -26,6 +27,7 @@ import { setup, FlashOperation, FlashState, nextBatch, OverallFlashingState, can import { randId } from "@app/core/utils/randId"; import { subscribeAll } from "@app/core/subscriptions"; import { connect } from "http2"; +import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "./UI/Select"; let initTest: boolean = false; @@ -117,7 +119,8 @@ const DeviceList = ({devices, rootConfig, totalConfigCount}: {devices: Device[], } -
+
+ {deviceSelectedToFlash.filter(d => d).length > 0 && +
+ + ); +} + +export type FirmwareVersion = { + name: string, + link: string, +} + +interface FirmwareGithubRelease { + name: string, + assets: { + name: string, + browser_download_url: string + }[] +} + +async function loadFirmwareList() : Promise { + const releases: FirmwareGithubRelease[] = await (await fetch("https://api.github.com/repos/meshtastic/firmware/releases")).json(); + console.log(releases); + const yo = releases.map(r => { + const url = r.assets.find(a => a.name.startsWith("firmware"))!.browser_download_url; + if(url === undefined) + return undefined; + return { + name: r.name.replace("Meshtastic Firmware ", ""), + link: url + }; + }).filter(r => r !== undefined) as FirmwareVersion[]; + return yo; +} + function deviceStateToText(state: FlashState) { switch(state.state) { case "doNotFlash": diff --git a/src/core/stores/appStore.ts b/src/core/stores/appStore.ts index af6da3f9..b696fd23 100644 --- a/src/core/stores/appStore.ts +++ b/src/core/stores/appStore.ts @@ -2,6 +2,7 @@ import { produce } from "immer"; import { create } from "zustand"; import { Protobuf } from "@meshtastic/meshtasticjs"; import type { OverallFlashingState } from "../flashing/Flasher"; +import type { FirmwareVersion } from "@app/components/Dashboard"; export interface RasterSource { enabled: boolean; @@ -42,7 +43,7 @@ export class ConfigPreset { if(config.lora === undefined) config.lora = new Protobuf.Config_LoRaConfig(); if(config.bluetooth === undefined) - config.bluetooth = new Protobuf.Config_BluetoothConfig(); + config.bluetooth = new Protobuf.Config_BluetoothConfig(); } public saveConfigTree() { @@ -161,6 +162,8 @@ interface AppState { configPresetRoot: ConfigPreset; configPresetSelected: ConfigPreset | undefined; overallFlashingState: OverallFlashingState; + firmwareRefreshing: boolean; + firmwareList: FirmwareVersion[]; setRasterSources: (sources: RasterSource[]) => void; addRasterSource: (source: RasterSource) => void; @@ -176,6 +179,8 @@ interface AppState { setConfigPresetRoot: (root: ConfigPreset) => void; setConfigPresetSelected: (selection: ConfigPreset) => void; setOverallFlashingState: (state: OverallFlashingState) => void; + setFirmwareRefreshing: (state: boolean) => void; + setFirmwareList: (state: FirmwareVersion[]) => void; } export const useAppStore = create()((set) => ({ @@ -190,6 +195,8 @@ export const useAppStore = create()((set) => ({ configPresetRoot: ConfigPreset.loadOrCreate(), configPresetSelected: undefined, overallFlashingState: "idle", + firmwareRefreshing: false, + firmwareList: [], setRasterSources: (sources: RasterSource[]) => { set( @@ -274,4 +281,18 @@ export const useAppStore = create()((set) => ({ }) ) }, + setFirmwareRefreshing: (state: boolean) => { + set( + produce((draft) => { + draft.firmwareRefreshing = state; + }) + ) + }, + setFirmwareList: (state: FirmwareVersion[]) => { + set( + produce((draft) => { + draft.firmwareList = state; + }) + ) + } })); \ No newline at end of file