From 454d8d03c239ffb88ed89211bc7fbdd207286c6e Mon Sep 17 00:00:00 2001 From: Mega-Volti <119437326+Mega-Volti@users.noreply.github.com> Date: Thu, 27 Jul 2023 01:35:48 +0200 Subject: [PATCH] Add custom refresh rate setting to resources Simplify resources refresh variable, enforce minimum Add custom refresh rate to uptime Add custom refresh rate to memory Add custom refresh rate to disk Add custom refresh rate to cputemp Add custom refresh rate to CPU --- src/components/widgets/resources/cpu.jsx | 4 ++-- src/components/widgets/resources/cputemp.jsx | 4 ++-- src/components/widgets/resources/disk.jsx | 4 ++-- src/components/widgets/resources/memory.jsx | 4 ++-- src/components/widgets/resources/resources.jsx | 14 ++++++++------ src/components/widgets/resources/uptime.jsx | 4 ++-- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/components/widgets/resources/cpu.jsx b/src/components/widgets/resources/cpu.jsx index 12972fe8..514b845f 100644 --- a/src/components/widgets/resources/cpu.jsx +++ b/src/components/widgets/resources/cpu.jsx @@ -5,11 +5,11 @@ import { useTranslation } from "next-i18next"; import Resource from "../widget/resource"; import Error from "../widget/error"; -export default function Cpu({ expanded }) { +export default function Cpu({ expanded, refresh = 1500 }) { const { t } = useTranslation(); const { data, error } = useSWR(`/api/widgets/resources?type=cpu`, { - refreshInterval: 1500, + refreshInterval: refresh, }); if (error || data?.error) { diff --git a/src/components/widgets/resources/cputemp.jsx b/src/components/widgets/resources/cputemp.jsx index ba6d9b73..684fe2f6 100644 --- a/src/components/widgets/resources/cputemp.jsx +++ b/src/components/widgets/resources/cputemp.jsx @@ -9,11 +9,11 @@ function convertToFahrenheit(t) { return t * 9/5 + 32 } -export default function CpuTemp({ expanded, units }) { +export default function CpuTemp({ expanded, units, refresh = 1500 }) { const { t } = useTranslation(); const { data, error } = useSWR(`/api/widgets/resources?type=cputemp`, { - refreshInterval: 1500, + refreshInterval: refresh, }); if (error || data?.error) { diff --git a/src/components/widgets/resources/disk.jsx b/src/components/widgets/resources/disk.jsx index ab56624d..ccda2410 100644 --- a/src/components/widgets/resources/disk.jsx +++ b/src/components/widgets/resources/disk.jsx @@ -5,11 +5,11 @@ import { useTranslation } from "next-i18next"; import Resource from "../widget/resource"; import Error from "../widget/error"; -export default function Disk({ options, expanded }) { +export default function Disk({ options, expanded, refresh = 1500 }) { const { t } = useTranslation(); const { data, error } = useSWR(`/api/widgets/resources?type=disk&target=${options.disk}`, { - refreshInterval: 1500, + refreshInterval: refresh, }); if (error || data?.error) { diff --git a/src/components/widgets/resources/memory.jsx b/src/components/widgets/resources/memory.jsx index 19ae8687..c3dbb277 100644 --- a/src/components/widgets/resources/memory.jsx +++ b/src/components/widgets/resources/memory.jsx @@ -5,11 +5,11 @@ import { useTranslation } from "next-i18next"; import Resource from "../widget/resource"; import Error from "../widget/error"; -export default function Memory({ expanded }) { +export default function Memory({ expanded, refresh = 1500 }) { const { t } = useTranslation(); const { data, error } = useSWR(`/api/widgets/resources?type=memory`, { - refreshInterval: 1500, + refreshInterval: refresh, }); if (error || data?.error) { diff --git a/src/components/widgets/resources/resources.jsx b/src/components/widgets/resources/resources.jsx index 0cc2c301..7b226ecb 100644 --- a/src/components/widgets/resources/resources.jsx +++ b/src/components/widgets/resources/resources.jsx @@ -9,16 +9,18 @@ import Uptime from "./uptime"; export default function Resources({ options }) { const { expanded, units } = options; + let { refresh } = options; + refresh = Math.max(refresh, 1000); return
- {options.cpu && } - {options.memory && } + {options.cpu && } + {options.memory && } {Array.isArray(options.disk) - ? options.disk.map((disk) => ) - : options.disk && } - {options.cputemp && } - {options.uptime && } + ? options.disk.map((disk) => ) + : options.disk && } + {options.cputemp && } + {options.uptime && }
{options.label && (
{options.label}
diff --git a/src/components/widgets/resources/uptime.jsx b/src/components/widgets/resources/uptime.jsx index 3984975f..73ec0a35 100644 --- a/src/components/widgets/resources/uptime.jsx +++ b/src/components/widgets/resources/uptime.jsx @@ -5,11 +5,11 @@ import { useTranslation } from "next-i18next"; import Resource from "../widget/resource"; import Error from "../widget/error"; -export default function Uptime() { +export default function Uptime({ refresh = 1500 }) { const { t } = useTranslation(); const { data, error } = useSWR(`/api/widgets/resources?type=uptime`, { - refreshInterval: 1500, + refreshInterval: refresh, }); if (error || data?.error) {