import { useState, useCallback } from 'react'; import { Card, Text, Title, Loader, Stack, Container, Badge, } from '@mantine/core'; import { DownloadCard } from '@/components/DownloadCard'; import { StyledTooltip } from '@/components/StyledTooltip'; import { getPlatformDisplayName, formatFileSizeInMB } from '@/utils'; import { isAssetRecommended, sortAssetsByRecommendation, getAssetDescription, } from '@/utils/assets'; import { useKoboldVersions } from '@/hooks/useKoboldVersions'; import type { DownloadItem } from '@/types/electron'; interface DownloadScreenProps { onDownloadComplete: () => void; } export const DownloadScreen = ({ onDownloadComplete }: DownloadScreenProps) => { const { platformInfo, availableDownloads, loadingPlatform, loadingRemote, downloading, downloadProgress, handleDownload: sharedHandleDownload, } = useKoboldVersions(); const [downloadingType, setDownloadingType] = useState< 'asset' | 'rocm' | null >(null); const [downloadingAsset, setDownloadingAsset] = useState(null); const loading = loadingPlatform || loadingRemote; const regularDownloads = availableDownloads.filter((d) => d.type === 'asset'); const rocmDownload = availableDownloads.find((d) => d.type === 'rocm'); const handleDownload = useCallback( async (type: 'asset' | 'rocm', download?: DownloadItem) => { if (type === 'asset' && !download) return; setDownloadingType(type); setDownloadingAsset(type === 'asset' ? download!.name : null); try { const success = await sharedHandleDownload( type, download, false, false ); if (success) { onDownloadComplete(); setTimeout(() => { setDownloadingType(null); setDownloadingAsset(null); }, 200); } } catch (error) { window.electronAPI.logs.logError( `Failed to download ${type}:`, error as Error ); } finally { setDownloadingType(null); setDownloadingAsset(null); } }, [sharedHandleDownload, onDownloadComplete] ); const renderROCmCard = () => { if (!rocmDownload) return null; return ( { e.stopPropagation(); handleDownload('rocm', rocmDownload); }} /> ); }; return ( Available Binaries for Your Platform {loading ? ( Preparing download options... ) : ( <> {availableDownloads.length > 0 && ( <> {availableDownloads.length > 0 ? ( {platformInfo.hasAMDGPU && !platformInfo.hasROCm && (
AMD GPU Detected ROCm Not Found
For best performance with your AMD GPU, consider installing ROCm support.
)} {rocmDownload && platformInfo.hasAMDGPU && renderROCmCard()} {sortAssetsByRecommendation( regularDownloads, platformInfo.hasAMDGPU ).map((download) => ( { e.stopPropagation(); handleDownload('asset', download); }} /> ))} {rocmDownload && !platformInfo.hasAMDGPU && renderROCmCard()}
) : ( No downloads available No downloads available for your platform ( {getPlatformDisplayName(platformInfo.platform)}). )} )} )}
); };