diff --git a/frontend/src/components/SiteFooter.tsx b/frontend/src/components/SiteFooter.tsx index a1778395..3f5a3dde 100644 --- a/frontend/src/components/SiteFooter.tsx +++ b/frontend/src/components/SiteFooter.tsx @@ -1,64 +1,123 @@ +import { useEffect, useState } from "react"; import { useHealth } from "src/hooks"; import { T } from "src/locale"; export function SiteFooter() { - const health = useHealth(); + const health = useHealth(); + const [latestVersion, setLatestVersion] = useState(null); + const [isNewVersionAvailable, setIsNewVersionAvailable] = useState(false); - const getVersion = () => { - if (!health.data) { - return ""; - } - const v = health.data.version; - return `v${v.major}.${v.minor}.${v.revision}`; - }; + const getVersion = () => { + if (!health.data) { + return ""; + } + const v = health.data.version; + return `v${v.major}.${v.minor}.${v.revision}`; + }; - return ( - - ); -} + const compareVersions = (current: string, latest: string): boolean => { + const cleanCurrent = current.replace(/^v/, ""); + const cleanLatest = latest.replace(/^v/, ""); + + const currentParts = cleanCurrent.split(".").map(Number); + const latestParts = cleanLatest.split(".").map(Number); + + for (let i = 0; i < Math.max(currentParts.length, latestParts.length); i++) { + const curr = currentParts[i] || 0; + const lat = latestParts[i] || 0; + + if (lat > curr) return true; + if (lat < curr) return false; + } + return false; + }; + + useEffect(() => { + const checkForUpdates = async () => { + try { + const response = await fetch( + "https://api.github.com/repos/NginxProxyManager/nginx-proxy-manager/releases/latest" + ); + if (response.ok) { + const data = await response.json(); + const latest = data.tag_name; + setLatestVersion(latest); + + const currentVersion = "2.12.1"; + if (currentVersion && compareVersions(currentVersion, latest)) { + setIsNewVersionAvailable(true); + } + } + } catch (error) { + console.debug("Could not check for updates:", error); + } + }; + + if (health.data) { + checkForUpdates(); + } + }, [health.data]); + + return ( + + ); +} \ No newline at end of file