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 12972fe8909fb8f90e9e986040d11c07b0fc3f8a..514b845f6a4d8716732c72ee7440f24cbc67bc6a 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 ba6d9b730d722935c7c3d7a7e2aefde5bcbd1994..684fe2f6dac0b25e787f4d780e69faaf32e58cdf 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 ab56624d994b27da2e199f39e9b98320a9f51999..ccda241047695bc51a99229b20d0d089b32f6d9a 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 19ae8687948030e20ed2a20bffd9c2db0d75636e..c3dbb277bfcca7dc469d2252d8fb352fc270df30 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 0cc2c30137b741ea853735dce5ecdef06ff6ed6e..7b226ecb8f3553f21d350bba5273997c7ce20ae6 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 3984975f15241b08a4f71e9cd9fc45b9a6570313..73ec0a35edd5bd00b143c4548e556c9def84b697 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) {