import { Box, Typography, Button, Snackbar, Alert } from '@mui/material'; import { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; declare global { interface Window { electron: { ipcRenderer: { invoke(channel: string, ...args: unknown[]): Promise; on(channel: string, func: (...args: unknown[]) => void): void; removeAllListeners(channel: string): void; }; }; } } const LaunchPage = () => { const navigate = useNavigate(); const [isDownloading, setIsDownloading] = useState(false); const [downloadProgress, setDownloadProgress] = useState(0); const [installStatus, setInstallStatus] = useState(''); const [notification, setNotification] = useState<{ open: boolean; message: string; severity: 'success' | 'error' | 'info'; }>({ open: false, message: '', severity: 'info' }); const [installStep, setInstallStep] = useState(''); const [installMessage, setInstallMessage] = useState(''); useEffect(() => { const savedConfig = localStorage.getItem('launcher_config'); if (!savedConfig || !JSON.parse(savedConfig).accessToken) { navigate('/login'); } window.electron.ipcRenderer.on('download-progress', (progress: any) => { setDownloadProgress(progress as number); }); // Добавляем слушатель для статуса установки window.electron.ipcRenderer.on('installation-progress', (data: any) => { setInstallStatus((data as { status: string }).status); }); // Обновляем слушатель для статуса установки window.electron.ipcRenderer.on('installation-status', (data: any) => { const { step, message } = data as { step: string; message: string }; setInstallStep(step); setInstallMessage(message); }); return () => { window.electron.ipcRenderer.removeAllListeners('download-progress'); window.electron.ipcRenderer.removeAllListeners('installation-progress'); window.electron.ipcRenderer.removeAllListeners('installation-status'); }; }, [navigate]); const handleLogout = () => { localStorage.removeItem('launcher_config'); navigate('/login'); }; const showNotification = ( message: string, severity: 'success' | 'error' | 'info', ) => { setNotification({ open: true, message, severity }); }; const handleCloseNotification = () => { setNotification({ ...notification, open: false }); }; const handleLaunchMinecraft = async () => { try { setIsDownloading(true); setDownloadProgress(0); // Сначала проверяем и обновляем файлы const downloadResult = await window.electron.ipcRenderer.invoke( 'download-and-extract', ); if (downloadResult?.success) { if (downloadResult.updated) { showNotification( `Сборка успешно обновлена до версии ${downloadResult.version}`, 'success', ); } else { showNotification( `Установлена актуальная версия сборки ${downloadResult.version}`, 'info', ); } // Затем запускаем Minecraft const launchResult = await window.electron.ipcRenderer.invoke('launch-minecraft'); if (launchResult?.success) { showNotification('Minecraft успешно запущен!', 'success'); } } } catch (error) { console.error('Error:', error); showNotification(`Ошибка: ${error.message}`, 'error'); } finally { setIsDownloading(false); } }; return ( Добро пожаловать в лаунчер {isDownloading ? ( Загрузка и установка: {downloadProgress}% {installMessage && ( {installMessage} )} {installStep && ( Шаг: {installStep} )} ) : ( )} {notification.message} ); }; export default LaunchPage;