import { useEffect } from 'react' import { useTranslation } from '../../i18n' import { MarkdownRenderer } from '../markdown/MarkdownRenderer' import { isTauriRuntime } from '../../lib/desktopRuntime' import { useUpdateStore } from '../../stores/updateStore' import { formatBytes } from '../../lib/formatBytes' export function UpdateChecker() { const t = useTranslation() const status = useUpdateStore((s) => s.status) const availableVersion = useUpdateStore((s) => s.availableVersion) const releaseNotes = useUpdateStore((s) => s.releaseNotes) const progressPercent = useUpdateStore((s) => s.progressPercent) const downloadedBytes = useUpdateStore((s) => s.downloadedBytes) const totalBytes = useUpdateStore((s) => s.totalBytes) const error = useUpdateStore((s) => s.error) const shouldPrompt = useUpdateStore((s) => s.shouldPrompt) const initialize = useUpdateStore((s) => s.initialize) const installUpdate = useUpdateStore((s) => s.installUpdate) const dismissPrompt = useUpdateStore((s) => s.dismissPrompt) useEffect(() => { void initialize() }, [initialize]) if (!isTauriRuntime()) return null const showPopup = shouldPrompt && !!availableVersion && ['available', 'downloading', 'restarting'].includes(status) if (!showPopup) return null const hasKnownProgress = typeof totalBytes === 'number' && totalBytes > 0 const downloadedText = formatBytes(downloadedBytes) const statusText = status === 'restarting' ? t('update.restarting') : status === 'downloading' ? hasKnownProgress ? t('update.downloading') : t('update.progressBytes', { downloaded: downloadedText }) : null return (
{t('update.available', { version: availableVersion })}
{releaseNotes && ({statusText} {status === 'downloading' && hasKnownProgress ? ` ${progressPercent}%` : ''}
)}{t('update.failed', { error })}
)} {status === 'available' && (