File size: 847 Bytes
00a912e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import { SERVER_URL } from '@/lib/config'
import { useEffect, useState } from 'react'
/**
* Check once on mount whether the server is running a newer version
* than the client was built with. Returns `true` when an update is available.
*/
export function useVersionCheck() {
const [hasUpdate, setHasUpdate] = useState(false)
useEffect(() => {
const controller = new AbortController()
fetch(`${SERVER_URL}/api/version`, { signal: controller.signal })
.then((res) => (res.ok ? res.json() : null))
.then((data: { version: string } | null) => {
if (data?.version && data.version !== __APP_VERSION__) {
setHasUpdate(true)
}
})
.catch(() => {
// Silently ignore — network errors, server down, etc.
})
return () => controller.abort()
}, [])
return hasUpdate
}
|