fetch version info and give up after 5 tries

This commit is contained in:
proddy
2026-09-15 21:56:53 +02:00
parent b1b8ab7dcc
commit c6e3cceead
+8 -2
View File
@@ -1,4 +1,4 @@
import { memo, useContext, useEffect, useState } from 'react'; import { memo, useContext, useEffect, useRef, useState } from 'react';
import { Link } from 'react-router'; import { Link } from 'react-router';
import CancelIcon from '@mui/icons-material/Cancel'; import CancelIcon from '@mui/icons-material/Cancel';
@@ -52,6 +52,7 @@ const STABLE_RELNOTES_URL =
const DEV_URL = 'https://github.com/emsesp/EMS-ESP32/releases/download/latest/'; const DEV_URL = 'https://github.com/emsesp/EMS-ESP32/releases/download/latest/';
const DEV_RELNOTES_URL = const DEV_RELNOTES_URL =
'https://github.com/emsesp/EMS-ESP32/blob/dev/CHANGELOG_LATEST.md'; 'https://github.com/emsesp/EMS-ESP32/blob/dev/CHANGELOG_LATEST.md';
const MAX_VERSION_POLLS = 5; // approx 15 seconds of waiting
// Types for better type safety // Types for better type safety
interface PartitionData { interface PartitionData {
@@ -440,12 +441,17 @@ const Version = () => {
const stableUpgradeAvailable = versions?.stable?.upgradeable ?? false; const stableUpgradeAvailable = versions?.stable?.upgradeable ?? false;
const devUpgradeAvailable = versions?.dev?.upgradeable ?? false; const devUpgradeAvailable = versions?.dev?.upgradeable ?? false;
const internetLive = Boolean(versions?.stable || versions?.dev); const internetLive = Boolean(versions?.stable || versions?.dev);
const versionPolls = useRef(0);
useEffect(() => { useEffect(() => {
if (internetLive) { if (internetLive || versionPolls.current >= MAX_VERSION_POLLS) {
return; return;
} }
const interval = setInterval(() => { const interval = setInterval(() => {
versionPolls.current += 1;
if (versionPolls.current >= MAX_VERSION_POLLS) {
clearInterval(interval);
}
void refreshVersions(); void refreshVersions();
}, 3000); }, 3000);
return () => clearInterval(interval); return () => clearInterval(interval);