mirror of
https://github.com/gethomepage/homepage.git
synced 2026-01-14 21:22:08 +08:00
Enhancement: configurable CPU temp scale (#3332)
--------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
@@ -9,7 +9,7 @@ function convertToFahrenheit(t) {
|
||||
return (t * 9) / 5 + 32;
|
||||
}
|
||||
|
||||
export default function CpuTemp({ expanded, units, refresh = 1500 }) {
|
||||
export default function CpuTemp({ expanded, units, refresh = 1500, tempmin = 0, tempmax = -1 }) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { data, error } = useSWR(`/api/widgets/resources?type=cputemp`, {
|
||||
@@ -39,7 +39,12 @@ export default function CpuTemp({ expanded, units, refresh = 1500 }) {
|
||||
}
|
||||
const unit = units === "imperial" ? "fahrenheit" : "celsius";
|
||||
mainTemp = unit === "celsius" ? mainTemp : convertToFahrenheit(mainTemp);
|
||||
const maxTemp = unit === "celsius" ? data.cputemp.max : convertToFahrenheit(data.cputemp.max);
|
||||
|
||||
const minTemp = tempmin < mainTemp ? tempmin : mainTemp;
|
||||
let maxTemp = tempmax;
|
||||
if (maxTemp < minTemp) {
|
||||
maxTemp = unit === "celsius" ? data.cputemp.max : convertToFahrenheit(data.cputemp.max);
|
||||
}
|
||||
|
||||
return (
|
||||
<Resource
|
||||
@@ -58,7 +63,7 @@ export default function CpuTemp({ expanded, units, refresh = 1500 }) {
|
||||
unit,
|
||||
})}
|
||||
expandedLabel={t("resources.max")}
|
||||
percentage={Math.round((mainTemp / maxTemp) * 100)}
|
||||
percentage={Math.round(((mainTemp - minTemp) / (maxTemp - minTemp)) * 100)}
|
||||
expanded={expanded}
|
||||
/>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user