import { Stack, Text, Group, Button, Card, Loader, Anchor, Progress, } from '@mantine/core'; import { Download, X, ExternalLink } from 'lucide-react'; import { useState } from 'react'; import type { DownloadItem } from '@/types/electron'; import type { BinaryUpdateInfo } from '@/hooks/useUpdateChecker'; import { useKoboldBackendsStore } from '@/stores/koboldBackends'; import { pretifyBinName } from '@/utils/assets'; import { formatDownloadSize } from '@/utils/format'; import { GITHUB_API } from '@/constants'; import { safeExecute } from '@/utils/logger'; import { Modal } from '@/components/Modal'; interface UpdateAvailableModalProps { opened: boolean; onClose: () => void; onSkip: () => void; updateInfo?: BinaryUpdateInfo; onUpdate: (download: DownloadItem) => Promise; } export const UpdateAvailableModal = ({ opened, onClose, onSkip, updateInfo, onUpdate, }: UpdateAvailableModalProps) => { const { downloading, downloadProgress } = useKoboldBackendsStore(); const currentBackend = updateInfo?.currentBackend; const availableUpdate = updateInfo?.availableUpdate; const [isUpdating, setIsUpdating] = useState(false); const isDownloading = !!availableUpdate && downloading === availableUpdate.name; const currentProgress = availableUpdate ? downloadProgress[availableUpdate.name] || 0 : 0; const handleUpdate = async () => { if (availableUpdate) { setIsUpdating(true); await safeExecute(async () => { await onUpdate(availableUpdate); onClose(); }, 'Failed to update:'); } setIsUpdating(false); }; return (
Current Version {currentBackend?.version}
Available Version {availableUpdate?.version}
{availableUpdate?.name && ( Binary Type: {pretifyBinName(availableUpdate?.name)} )} {availableUpdate?.size && ( Update Size:{' '} {formatDownloadSize(availableUpdate.size, availableUpdate.url)} )} View Release Notes
{isDownloading ? `${Math.min(currentProgress, 100).toFixed(1)}% complete` : 'Preparing update...'}
); };