From 8fa69560959aacf42411549d9fc689fa130b296f Mon Sep 17 00:00:00 2001 From: DIKER0K Date: Mon, 7 Jul 2025 00:58:09 +0500 Subject: [PATCH] add: linear progress --- src/renderer/pages/LaunchPage.tsx | 57 ++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 9 deletions(-) diff --git a/src/renderer/pages/LaunchPage.tsx b/src/renderer/pages/LaunchPage.tsx index 521ce29..4865313 100644 --- a/src/renderer/pages/LaunchPage.tsx +++ b/src/renderer/pages/LaunchPage.tsx @@ -1,4 +1,11 @@ -import { Box, Typography, Button, Snackbar, Alert } from '@mui/material'; +import { + Box, + Typography, + Button, + Snackbar, + Alert, + LinearProgress, +} from '@mui/material'; import { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; @@ -18,6 +25,7 @@ const LaunchPage = () => { const navigate = useNavigate(); const [isDownloading, setIsDownloading] = useState(false); const [downloadProgress, setDownloadProgress] = useState(0); + const [buffer, setBuffer] = useState(10); const [installStatus, setInstallStatus] = useState(''); const [notification, setNotification] = useState<{ open: boolean; @@ -33,6 +41,22 @@ const LaunchPage = () => { navigate('/login'); } + const progressListener = (...args: unknown[]) => { + const progress = args[0] as number; + setDownloadProgress(progress); + setBuffer(Math.min(progress + 10, 100)); + }; + + window.electron.ipcRenderer.on('download-progress', progressListener); + window.electron.ipcRenderer.on( + 'installation-status', + (...args: unknown[]) => { + const status = args[0] as { step: string; message: string }; + setInstallStep(status.step); + setInstallMessage(status.message); + }, + ); + return () => { window.electron.ipcRenderer.removeAllListeners('download-progress'); window.electron.ipcRenderer.removeAllListeners('installation-progress'); @@ -60,13 +84,12 @@ const LaunchPage = () => { try { setIsDownloading(true); setDownloadProgress(0); + setBuffer(10); - // Загружаем настройки и токены const savedConfig = JSON.parse( localStorage.getItem('launcher_config') || '{}', ); - // Сначала проверяем и обновляем файлы const downloadResult = await window.electron.ipcRenderer.invoke( 'download-and-extract', ); @@ -84,7 +107,6 @@ const LaunchPage = () => { ); } - // Затем запускаем Minecraft с данными авторизации const launchResult = await window.electron.ipcRenderer.invoke( 'launch-minecraft', { @@ -108,15 +130,32 @@ const LaunchPage = () => { }; return ( - + Добро пожаловать в лаунчер {isDownloading ? ( - - Загрузка и установка: {downloadProgress}% - {installMessage && ( + + {/* + Загрузка и установка: {downloadProgress}% + */} + + + + + + {`${Math.round(downloadProgress)}%`} + + + {/* {installMessage && ( {installMessage} @@ -125,7 +164,7 @@ const LaunchPage = () => { Шаг: {installStep} - )} + )} */} ) : (