diff --git a/AppImage/components/hardware.tsx b/AppImage/components/hardware.tsx index cc6e1fd..d62f9a6 100644 --- a/AppImage/components/hardware.tsx +++ b/AppImage/components/hardware.tsx @@ -22,6 +22,34 @@ import useSWR from "swr" import { useState, useEffect } from "react" import { type HardwareData, type GPU, type PCIDevice, type StorageDevice, fetcher } from "../types/hardware" +const parseLsblkSize = (sizeStr: string | undefined): number => { + if (!sizeStr) return 0 + + // Remove spaces and convert to uppercase + const cleaned = sizeStr.trim().toUpperCase() + + // Extract number and unit + const match = cleaned.match(/^([\d.]+)([KMGT]?)$/) + if (!match) return 0 + + const value = Number.parseFloat(match[1]) + const unit = match[2] || "K" // Default to KB if no unit + + // Convert to KB + switch (unit) { + case "K": + return value + case "M": + return value * 1024 + case "G": + return value * 1024 * 1024 + case "T": + return value * 1024 * 1024 * 1024 + default: + return value + } +} + const formatMemory = (memoryKB: number | string): string => { const kb = typeof memoryKB === "string" ? Number.parseFloat(memoryKB) : memoryKB @@ -1571,7 +1599,7 @@ export default function Hardware() { {device.type} - {device.size &&

{formatMemory(device.size)}

} + {device.size &&

{formatMemory(parseLsblkSize(device.size))}

} {device.model && (

{device.model}

)} @@ -1610,7 +1638,7 @@ export default function Hardware() { {selectedDisk.size && (
Capacity - {formatMemory(selectedDisk.size)} + {formatMemory(parseLsblkSize(selectedDisk.size))}
)}