import ProgressBar from "../ProgressBar"; import SystemItem from "../SystemItem"; import { useAtomValue } from "jotai"; import { appDownloadProgress } from "@/_helpers/JotaiWrapper"; import { useEffect, useState } from "react"; import { executeSerial } from "../../../../electron/core/plugin-manager/execution/extension-manager"; import { SystemMonitoringService } from "../../../shared/coreService"; import { getSystemBarVisibilityAtom } from "@/_helpers/atoms/SystemBar.atom"; import { currentProductAtom } from "@/_helpers/atoms/Model.atom"; const MonitorBar: React.FC = () => { const show = useAtomValue(getSystemBarVisibilityAtom); const progress = useAtomValue(appDownloadProgress); const activeModel = useAtomValue(currentProductAtom); const [ram, setRam] = useState(0); const [gpu, setGPU] = useState(0); const [cpu, setCPU] = useState(0); const [version, setVersion] = useState(""); useEffect(() => { const getSystemResources = async () => { const resourceInfor = await executeSerial( SystemMonitoringService.GET_RESOURCES_INFORMATION ); const currentLoadInfor = await executeSerial( SystemMonitoringService.GET_CURRENT_LOAD_INFORMATION ); const ram = (resourceInfor?.mem?.used ?? 0) / (resourceInfor?.mem?.total ?? 1); setRam(Math.round(ram * 100)); setCPU(Math.round(currentLoadInfor?.currentLoad ?? 0)); }; const getAppVersion = () => { window.electronAPI.appVersion().then((version: string | undefined) => { setVersion(version ?? ""); }); }; getAppVersion(); getSystemResources(); // Fetch interval - every 3s const intervalId = setInterval(() => { getSystemResources(); }, 3000); return () => clearInterval(intervalId); }, []); if (!show) return null; return (
{progress && progress >= 0 ? ( ) : (
)}
{activeModel && ( )} v{version}
); }; export default MonitorBar;