Better handle multi-core temp

pull/1169/head
shamoon 2 years ago
parent 489132269e
commit a90f178ee0

@ -5,6 +5,10 @@ import { useTranslation } from "next-i18next";
import UsageBar from "./usage-bar"; import UsageBar from "./usage-bar";
function convertToFahrenheit(t) {
return t * 5/9 + 32
}
export default function CpuTemp({ expanded, units }) { export default function CpuTemp({ expanded, units }) {
const { t } = useTranslation(); const { t } = useTranslation();
@ -23,7 +27,7 @@ export default function CpuTemp({ expanded, units }) {
); );
} }
if (!data) { if (!data || !data.cputemp) {
return ( return (
<div className="flex-none flex flex-row items-center mr-3 py-1.5 animate-pulse"> <div className="flex-none flex flex-row items-center mr-3 py-1.5 animate-pulse">
<FaThermometerHalf className="text-theme-800 dark:text-theme-200 w-5 h-5" /> <FaThermometerHalf className="text-theme-800 dark:text-theme-200 w-5 h-5" />
@ -43,10 +47,16 @@ export default function CpuTemp({ expanded, units }) {
); );
} }
let minTemp = 0;
let mainTemp = data.cputemp.main;
if (data.cputemp.cores?.length) {
mainTemp = data.cputemp.cores.reduce((a, b) => a + b) / data.cputemp.cores.length;
minTemp = Math.min(...data.cputemp.cores);
}
const unit = units === "imperial" ? "fahrenheit" : "celsius"; const unit = units === "imperial" ? "fahrenheit" : "celsius";
const mainTemp = (unit === "celsius") ? data.cputemp.main : data.cputemp.main * 5/9 + 32; mainTemp = (unit === "celsius") ? mainTemp : convertToFahrenheit(mainTemp);
const maxTemp = (unit === "celsius") ? data.cputemp.max : data.cputemp.max * 5/9 + 32; const maxTemp = (unit === "celsius") ? data.cputemp.max : convertToFahrenheit(data.cputemp.max);
const percent = Math.round((mainTemp / maxTemp) * 100); const percent = Math.round(((mainTemp - minTemp) / (maxTemp - minTemp)) * 100);
return ( return (
<div className="flex-none flex flex-row items-center mr-3 py-1.5"> <div className="flex-none flex flex-row items-center mr-3 py-1.5">

Loading…
Cancel
Save