/**
* Update Settings Component
* Displays update status and allows manual update checking/installation
*/
import { useEffect, useCallback } from 'react';
import { Download, RefreshCw, Loader2, Rocket, XCircle } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Progress } from '@/components/ui/progress';
import { useUpdateStore } from '@/stores/update';
import { useTranslation } from 'react-i18next';
function formatBytes(bytes: number): string {
if (bytes === 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
export function UpdateSettings() {
const { t } = useTranslation('settings');
const {
status,
currentVersion,
updateInfo,
progress,
error,
isInitialized,
autoInstallCountdown,
init,
checkForUpdates,
downloadUpdate,
installUpdate,
cancelAutoInstall,
clearError,
} = useUpdateStore();
// Initialize on mount
useEffect(() => {
init();
}, [init]);
const handleCheckForUpdates = useCallback(async () => {
clearError();
await checkForUpdates();
}, [checkForUpdates, clearError]);
const renderStatusIcon = () => {
switch (status) {
case 'checking':
case 'downloading':
return
{t('updates.currentVersion')}
v{currentVersion}
{renderStatusText()}
{renderAction()}{Math.round(progress.percent)}% complete
Version {updateInfo.version}
{updateInfo.releaseDate && ({new Date(updateInfo.releaseDate).toLocaleDateString()}
)}{t('updates.whatsNew')}
{updateInfo.releaseNotes}
{t('updates.errorDetails')}
{error}
{t('updates.help')}