import { useState, useEffect } from 'react'; import { AppShell, Group, ActionIcon, Tooltip, rem, Loader, Center, Stack, Text, Button, Select, useMantineColorScheme, } from '@mantine/core'; import { Settings, ArrowLeft } from 'lucide-react'; import { DownloadScreen } from '@/components/screens/DownloadScreen'; import { LaunchScreen } from '@/components/screens/LaunchScreen'; import { InterfaceScreen } from '@/components/screens/InterfaceScreen'; import { UpdateDialog } from '@/components/UpdateDialog'; import { SettingsModal } from '@/components/SettingsModal'; import { ScreenTransition } from '@/components/ScreenTransition'; import type { UpdateInfo } from '@/types'; type Screen = 'download' | 'launch' | 'interface'; export const App = () => { const [currentScreen, setCurrentScreen] = useState(null); const [updateInfo, setUpdateInfo] = useState(null); const [showUpdateDialog, setShowUpdateDialog] = useState(false); const [settingsOpened, setSettingsOpened] = useState(false); const [hasInitialized, setHasInitialized] = useState(false); const [activeInterfaceTab, setActiveInterfaceTab] = useState( 'terminal' ); const { colorScheme } = useMantineColorScheme(); useEffect(() => { const checkInstallation = async () => { try { const startTime = Date.now(); const installedVersions = await window.electronAPI.kobold.getInstalledVersions(false); const elapsed = Date.now() - startTime; const minDelay = 500; if (elapsed < minDelay) { await new Promise((resolve) => setTimeout(resolve, minDelay - elapsed) ); } setCurrentScreen(installedVersions.length > 0 ? 'launch' : 'download'); setHasInitialized(true); } catch (error) { console.error('Error checking installation:', error); setHasInitialized(true); } }; checkInstallation(); window.electronAPI.kobold.onUpdateAvailable((info) => { setUpdateInfo(info); setShowUpdateDialog(true); }); const cleanupInstallDirListener = window.electronAPI.kobold.onInstallDirChanged(() => { checkInstallation(); }); return () => { window.electronAPI.kobold.removeAllListeners('update-available'); cleanupInstallDirListener(); }; }, []); const handleDownloadComplete = () => { setTimeout(() => { setCurrentScreen('launch'); }, 100); }; const handleLaunch = () => { setCurrentScreen('interface'); }; const handleBackToLaunch = () => { setCurrentScreen('launch'); }; const handleEject = async () => { try { const confirmed = await window.electronAPI.kobold.confirmEject(); if (!confirmed) { return; } } catch (error) { console.error('Error showing confirmation dialog:', error); return; } try { await window.electronAPI.kobold.stopKoboldCpp(); } catch (error) { console.error('Error stopping KoboldCpp:', error); } handleBackToLaunch(); }; const handleUpdateIgnore = () => { setShowUpdateDialog(false); }; const handleUpdateAccept = () => { setShowUpdateDialog(false); setCurrentScreen('download'); }; return ( <>
{currentScreen === 'interface' && ( )}
{currentScreen === 'interface' && (