diff --git a/gui/public/i18n/en/translation.ftl b/gui/public/i18n/en/translation.ftl index f9bc29eda..1f4e0a862 100644 --- a/gui/public/i18n/en/translation.ftl +++ b/gui/public/i18n/en/translation.ftl @@ -283,6 +283,7 @@ tracker-settings-forget = Forget tracker tracker-settings-forget-description = Removes the tracker from the SlimeVR Server and prevent it from connecting to it until the server is restarted. The configuration of the tracker won't be lost. tracker-settings-forget-label = Forget tracker tracker-settings-update-unavailable = Cannot be updated (DIY) +tracker-settings-update-low-battery = Cannot update. Battery lower than 50% tracker-settings-update-up_to_date = Up to date tracker-settings-update-available = { $versionName } is now available tracker-settings-update = Update now diff --git a/gui/src/components/firmware-update/FirmwareUpdate.tsx b/gui/src/components/firmware-update/FirmwareUpdate.tsx index 222491186..dcf36b186 100644 --- a/gui/src/components/firmware-update/FirmwareUpdate.tsx +++ b/gui/src/components/firmware-update/FirmwareUpdate.tsx @@ -10,7 +10,6 @@ import { FirmwareUpdateStatus, FirmwareUpdateStatusResponseT, FirmwareUpdateStopQueuesRequestT, - HardwareInfoT, RpcMessage, TrackerStatus, } from 'solarxr-protocol'; @@ -37,18 +36,30 @@ import { A } from '@/components/commons/A'; export function checkForUpdate( currentFirmwareRelease: FirmwareRelease, - hardwareInfo: HardwareInfoT -) { - return ( - // TODO: This is temporary, end goal is to support all board types - hardwareInfo.officialBoardType === BoardType.SLIMEVR && - semver.valid(currentFirmwareRelease.version) && - semver.valid(hardwareInfo.firmwareVersion?.toString() ?? 'none') && - semver.lt( - hardwareInfo.firmwareVersion?.toString() ?? 'none', - currentFirmwareRelease.version - ) + device: DeviceDataT +): 'need-update' | 'low-battery' | 'updated' | 'unavailable' { + if ( + device.hardwareInfo?.officialBoardType !== BoardType.SLIMEVR || + !semver.valid(currentFirmwareRelease.version) || + !semver.valid(device.hardwareInfo.firmwareVersion?.toString() ?? 'none') + ) { + return 'unavailable'; + } + + const canUpdate = semver.lt( + device.hardwareInfo.firmwareVersion?.toString() ?? 'none', + currentFirmwareRelease.version ); + + if ( + canUpdate && + device.hardwareStatus?.batteryPctEstimate && + device.hardwareStatus?.batteryPctEstimate < 50 + ) { + return 'low-battery'; + } + + return canUpdate ? 'need-update' : 'updated'; } interface FirmwareUpdateForm { @@ -126,12 +137,12 @@ export function FirmwareUpdate() { const devices = state.datafeed?.devices.filter( - ({ trackers, hardwareInfo }) => - trackers.length > 0 && + (device) => + device.trackers.length > 0 && currentFirmwareRelease && - hardwareInfo && - checkForUpdate(currentFirmwareRelease, hardwareInfo) && - trackers.every(({ status }) => status === TrackerStatus.OK) + device.hardwareInfo && + checkForUpdate(currentFirmwareRelease, device) === 'need-update' && + device.trackers.every(({ status }) => status === TrackerStatus.OK) ) || []; useRPCPacket( diff --git a/gui/src/components/tracker/TrackerCard.tsx b/gui/src/components/tracker/TrackerCard.tsx index 0520dba13..22253a946 100644 --- a/gui/src/components/tracker/TrackerCard.tsx +++ b/gui/src/components/tracker/TrackerCard.tsx @@ -15,6 +15,52 @@ import { DownloadIcon } from '@/components/commons/icon/DownloadIcon'; import { Link } from 'react-router-dom'; import { useAppContext } from '@/hooks/app'; import { checkForUpdate } from '@/components/firmware-update/FirmwareUpdate'; +import { Tooltip } from '@/components/commons/Tooltip'; +import { Localized } from '@fluent/react'; + +function UpdateIcon({ + showUpdate, +}: { + showUpdate: 'need-update' | 'low-battery' | 'updated' | 'unavailable'; +}) { + const content = ( +