'use client'; import { useState, useEffect } from 'react'; import { AlertCircle, RefreshCw } from 'lucide-react'; import { Button } from './ui/button'; interface VersionInfo { version: string; buildTime: string; } export function VersionChecker() { const [currentVersion, setCurrentVersion] = useState(null); const [serverVersion, setServerVersion] = useState(null); const [showUpdate, setShowUpdate] = useState(false); useEffect(() => { // Get initial version from version.json const loadCurrentVersion = async () => { try { const response = await fetch('/ui/version.json', { cache: 'no-store' // Always fetch fresh version }); if (response.ok) { const data: VersionInfo = await response.json(); setCurrentVersion(data.version); } } catch (error) { console.warn('Failed to load UI version:', error); } }; loadCurrentVersion(); }, []); useEffect(() => { // Check server version periodically (every 5 minutes) const checkVersion = async () => { try { // Check if __SERVER_CONFIG__ is available if (typeof window !== 'undefined' && (window as any).__SERVER_CONFIG__) { const config = (window as any).__SERVER_CONFIG__; const version = config.uiVersion; if (version && version !== 'unknown') { setServerVersion(version); // If we have both versions and they don't match, show update notification if (currentVersion && version !== currentVersion) { setShowUpdate(true); } } } } catch (error) { console.warn('Failed to check server version:', error); } }; // Initial check after 2 seconds const initialTimeout = setTimeout(checkVersion, 2000); // Periodic check every 5 minutes const interval = setInterval(checkVersion, 5 * 60 * 1000); return () => { clearTimeout(initialTimeout); clearInterval(interval); }; }, [currentVersion]); const handleRefresh = () => { // Force reload to get new version window.location.reload(); }; if (!showUpdate) { return null; } return (

New UI Version Available

A new version of the UI has been deployed. Refresh to get the latest updates.

); }