Skip to content

Commit

Permalink
Small ui fixes on firmware updates (#1291)
Browse files Browse the repository at this point in the history
  • Loading branch information
loucass003 authored Jan 31, 2025
1 parent 15ea04d commit fb23ba8
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions gui/public/i18n/en/translation.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,7 @@ firmware_update-changelog-title = Updating to {$version}
firmware_update-looking_for_devices = Looking for devices to update...
firmware_update-retry = Retry
firmware_update-update = Update Selected Trackers
firmware_update-exit = Exit
## Tray Menu
tray_menu-show = Show
Expand Down
17 changes: 16 additions & 1 deletion gui/src/components/firmware-update/FirmwareUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,21 @@ export function FirmwareUpdate() {
queueFlashing(selectedDevices);
};

const exit = () => {
clear();
navigate('/');
};

const canStartUpdate =
isValid &&
devices.length !== 0 &&
!hasPendingTrackers &&
trackerWithErrors.length === 0;
const canRetry =
isValid && devices.length !== 0 && trackerWithErrors.length !== 0;
!hasPendingTrackers &&
isValid &&
devices.length !== 0 &&
trackerWithErrors.length !== 0;

const statusKeys = Object.keys(status);

Expand Down Expand Up @@ -395,6 +403,13 @@ export function FirmwareUpdate() {
onClick={startUpdate}
></Button>
</Localized>
<Localized id="firmware_update-exit">
<Button
variant="primary"
onClick={exit}
disabled={hasPendingTrackers}
></Button>
</Localized>
</div>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion gui/src/components/tracker/TrackerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export function TrackerCard({
}) {
const { currentFirmwareRelease } = useAppContext();
const { useVelocity } = useTracker(tracker);

const velocity = useVelocity();

return (
Expand Down
8 changes: 4 additions & 4 deletions gui/src/hooks/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ export function useProvideAppContext(): AppContext {
useEffect(() => {
const fetchCurrentFirmwareRelease = async () => {
const releases: any[] | null = JSON.parse(
await cacheWrap(
(await cacheWrap(
'firmware-releases',
() =>
fetch('https://api.github.com/repos/SlimeVR/SlimeVR-Tracker-ESP/releases')
.then((res) => res.text())
.catch(() => 'null'),
1000 * 60 * 60
)
.catch(() => null),
60 * 60 * 1000
)) ?? 'null'
);
if (!releases) return null;

Expand Down
4 changes: 2 additions & 2 deletions gui/src/hooks/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function cacheGet(key: string): Promise<string | null> {
const item = JSON.parse(itemStr);
const now = new Date();

if (now.getTime() > item.expiry) {
if (item.expiry > 0 && now.getTime() > item.expiry) {
await store.delete(key);
return null;
}
Expand All @@ -50,7 +50,7 @@ export async function cacheSet(key: string, value: unknown, ttl: number | undefi

export async function cacheWrap(
key: string,
orDefault: () => Promise<string>,
orDefault: () => Promise<string | null>,
ttl: number | undefined
) {
const realItem = await store.get(key);
Expand Down

0 comments on commit fb23ba8

Please sign in to comment.