diff --git a/src/shared/api/contracts/profiles/ProfileBaseEntity.ts b/src/shared/api/contracts/profiles/ProfileBaseEntity.ts index 9462b3d..0bd9640 100644 --- a/src/shared/api/contracts/profiles/ProfileBaseEntity.ts +++ b/src/shared/api/contracts/profiles/ProfileBaseEntity.ts @@ -6,6 +6,7 @@ export type ProfileBaseEntity = { launchVersion: string; jvmArguments: string; iconBase64: string; + state: string; }; export type ProfileExtendedBaseEntity = { diff --git a/src/shared/enums/index.ts b/src/shared/enums/index.ts index dac2f80..4640083 100644 --- a/src/shared/enums/index.ts +++ b/src/shared/enums/index.ts @@ -3,3 +3,4 @@ export * from "./integration"; export * from "./storages"; export * from "./systems"; export * from "./textures"; +export * from "./profileState"; diff --git a/src/shared/enums/profileState.ts b/src/shared/enums/profileState.ts new file mode 100644 index 0000000..80aec78 --- /dev/null +++ b/src/shared/enums/profileState.ts @@ -0,0 +1,11 @@ +export enum ProfileState { + PROFILE_STATE_CREATED = 0, // Профиль создан + PROFILE_STATE_LOADING = 1, // Профиль загружается + PROFILE_STATE_ACTIVE = 2, // Профиль активен +} + +export enum ProfileStateOption { + "OPTION_0" = "Создан", // Профиль создан + "OPTION_1" = "Загружается Engine", // Профиль загружается + "OPTION_2" = "Активен", // Профиль активен +} diff --git a/src/widgets/client-hub/lib/useConnectionHub.ts b/src/widgets/client-hub/lib/useConnectionHub.ts index 4f9c849..cc66254 100644 --- a/src/widgets/client-hub/lib/useConnectionHub.ts +++ b/src/widgets/client-hub/lib/useConnectionHub.ts @@ -19,9 +19,16 @@ export const useConnectionHub = (props: ConnectionHubProps) => { const accessToken = getStorageAccessToken(); const [connectionHub, setConnectionHub] = useState(null); - const [progressPercent, setProgressPercent] = useState(0); + + const [percentStage, setPercentStage] = useState(0); + const [percentAllStages, setPercentAllStages] = useState(0); + const [isRestoring, setIsRestoring] = useState(false); + const [logs, setLogs] = useState(null); + + const [isPacked, setIsPacked] = useState(false); + useEffect(() => { if (isLoading || !accessToken) return; @@ -38,13 +45,33 @@ export const useConnectionHub = (props: ConnectionHubProps) => { await connection.start(); - connection.on("BlockRestore", () => { - setIsRestoring(true); + if (profile?.hasUpdate == false) setIsRestoring(true); + + connection.on("ChangeProgress", (profileName, percent) => { + if (profileName == profile?.profileName) { + setIsRestoring(true); + setPercentStage(percent); + } + }); + + connection.on("FullProgress", (profileName, percent) => { + if (profileName == profile?.profileName) { + setIsRestoring(true); + setIsPacked(true); + setPercentAllStages(percent); + } + }); + + connection.on("OnException", (profileName, exception: string) => { + if (profileName == profile?.profileName) { + setLogs((prev) => (prev ? [...prev, exception] : [exception])); + } }); - connection.on("ChangeProgress", (percent) => { - setIsRestoring(true); - setProgressPercent(percent); + connection.on("Log", (profileName, log: string) => { + if (profileName == profile?.profileName) { + setLogs((prev) => (prev ? [...prev, log] : [log])); + } }); connection.on("Message", (msg) => { @@ -54,21 +81,28 @@ export const useConnectionHub = (props: ConnectionHubProps) => { }); }); - connection.on("SuccessInstalled", () => { - setIsRestoring(false); - setProgressPercent(0); - toast({ - title: "Успешно", - description: "Клиент успешно загружен", - }); + connection.on("SuccessInstalled", (profileName) => { + if (profileName == profile?.profileName) { + setIsPacked(false); + setIsRestoring(false); + setPercentStage(0); + setPercentAllStages(0); + setLogs(null); + toast({ + title: "Успешно", + description: `Профиль ${profileName} успешно загружен`, + }); + } }); - connection.on("SuccessPacked", () => { - setIsRestoring(false); - setProgressPercent(0); + connection.on("SuccessPacked", (profileName) => { + if (profileName == profile?.profileName) { + setIsRestoring(false); + setPercentStage(0); + } toast({ title: "Успешно", - description: "Клиент успешно собран", + description: `Профиль ${profileName} успешно собран`, }); }); } catch (error) { @@ -84,6 +118,7 @@ export const useConnectionHub = (props: ConnectionHubProps) => { }, []); const onDownloadDistributive = () => { + setIsPacked(true); setIsRestoring(true); connectionHub ?.invoke("Restore", profile?.profileName) @@ -100,6 +135,7 @@ export const useConnectionHub = (props: ConnectionHubProps) => { }; const onBuildDistributive = () => { + setIsPacked(false); setIsRestoring(true); connectionHub ?.invoke("Build", profile?.profileName) @@ -119,6 +155,9 @@ export const useConnectionHub = (props: ConnectionHubProps) => { onDownloadDistributive, onBuildDistributive, isDisable: isRestoring, - progress: progressPercent, + isPacked, + percentStage, + percentAllStages, + logs, }; }; diff --git a/src/widgets/client-hub/ui/DownloadClientHub.tsx b/src/widgets/client-hub/ui/DownloadClientHub.tsx index 8aa0bf5..e8ba5f8 100644 --- a/src/widgets/client-hub/ui/DownloadClientHub.tsx +++ b/src/widgets/client-hub/ui/DownloadClientHub.tsx @@ -1,11 +1,14 @@ "use client"; -import React from "react"; +import React, { useEffect, useRef } from "react"; + +import { ProfileExtendedBaseEntity } from "@/shared/api/contracts"; import { Button } from "@/shared/ui/button"; import { Progress } from "@/shared/ui/progress"; +import { Textarea } from "@/shared/ui/textarea"; +import { Icons } from "@/shared/ui/icons"; import { useConnectionHub } from "../lib/useConnectionHub"; -import { ProfileExtendedBaseEntity } from "@/shared/api/contracts"; interface DownloadClientHubProps { profile?: ProfileExtendedBaseEntity; @@ -13,8 +16,22 @@ interface DownloadClientHubProps { } export function DownloadClientHub(props: DownloadClientHubProps) { - const { onDownloadDistributive, onBuildDistributive, isDisable, progress } = - useConnectionHub(props); + const { + onDownloadDistributive, + onBuildDistributive, + isDisable, + isPacked, + percentStage, + percentAllStages, + logs, + } = useConnectionHub(props); + + const textareaRef = useRef(null); + useEffect(() => { + if (textareaRef.current) { + textareaRef.current.scrollTop = textareaRef.current.scrollHeight; + } + }, [logs]); return ( <> @@ -29,6 +46,7 @@ export function DownloadClientHub(props: DownloadClientHubProps) { onClick={onDownloadDistributive} disabled={isDisable || !props.profile || !props.profile.hasUpdate} > + {isDisable && } Загрузить @@ -44,19 +62,47 @@ export function DownloadClientHub(props: DownloadClientHubProps) { onClick={onBuildDistributive} disabled={isDisable || !props.profile || !props.profile.hasUpdate} > + {isDisable && } Собрать - {Boolean(progress) && ( -
-
-
Прогресс
-

Выполнено на {progress}% из 100%

-
-
- + {Boolean(isDisable) && ( +
+
+
+
Прогресс
+

+ Выполнено на {percentStage}% из 100% +

+
+
+ +
+ {Boolean(isPacked) && logs && ( +
+
+
+
Полный прогресс
+

+ Выполнено на {percentAllStages}% из 100% +

+
+
+ +
+
+
+