From 792df08c78719e864beccfe60ba85b13c38a0208 Mon Sep 17 00:00:00 2001 From: MacRimi Date: Tue, 14 Oct 2025 12:58:53 +0200 Subject: [PATCH] Update hardware.tsx --- AppImage/components/hardware.tsx | 66 +++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) diff --git a/AppImage/components/hardware.tsx b/AppImage/components/hardware.tsx index ac12333..bfefce0 100644 --- a/AppImage/components/hardware.tsx +++ b/AppImage/components/hardware.tsx @@ -20,7 +20,7 @@ import { Info, } from "lucide-react" import useSWR from "swr" -import { useState } from "react" +import { useState, useEffect } from "react" import { type HardwareData, type GPU, type PCIDevice, type StorageDevice, fetcher } from "../types/hardware" const formatMemory = (memoryKB: number | string): string => { @@ -116,6 +116,70 @@ export default function Hardware() { const [selectedNetwork, setSelectedNetwork] = useState(null) const [selectedUPS, setSelectedUPS] = useState(null) // Added state for UPS modal + useEffect(() => { + if (!selectedGPU) return + + const pciDevice = findPCIDeviceForGPU(selectedGPU) + const fullSlot = pciDevice?.slot || selectedGPU.slot + + if (!fullSlot) { + setDetailsLoading(false) + setRealtimeGPUData({ has_monitoring_tool: false }) + return + } + + const abortController = new AbortController() + let timeoutId: NodeJS.Timeout + + const fetchRealtimeData = async () => { + try { + const apiUrl = `http://${window.location.hostname}:8008/api/gpu/${fullSlot}/realtime` + + // Set a timeout of 5 seconds + timeoutId = setTimeout(() => { + abortController.abort() + }, 5000) + + const response = await fetch(apiUrl, { + method: "GET", + headers: { + "Content-Type": "application/json", + }, + signal: abortController.signal, + }) + + clearTimeout(timeoutId) + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + + const data = await response.json() + setRealtimeGPUData(data) + setDetailsLoading(false) + } catch (error) { + // Only log non-abort errors + if (error instanceof Error && error.name !== "AbortError") { + console.error("[v0] Error fetching GPU realtime data:", error) + } + setRealtimeGPUData({ has_monitoring_tool: false }) + setDetailsLoading(false) + } + } + + // Initial fetch + fetchRealtimeData() + + // Poll every 3 seconds + const interval = setInterval(fetchRealtimeData, 3000) + + return () => { + clearInterval(interval) + clearTimeout(timeoutId) + abortController.abort() + } + }, [selectedGPU, hardwareData?.pci_devices]) + if (!hardwareData && !error) { return (