diff --git a/src/main.ts b/src/main.ts index 65d5a17..4d82d9c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -36,13 +36,19 @@ function setElement(id: string, num: number) { } } +let lock = false let timer: number async function getSystemInfo() { - clearTimeout(timer) + if (lock) { + return + } + lock = true const { cpuUsage, memoryUsage, networkSpeedDown, networkSpeedUp } = (await invoke("plugin:system_info|get_sys_info")) as SystemInfo + lock = false + setElement("#cpu-usage", cpuUsage) setElement("#memory-usage", memoryUsage) @@ -51,7 +57,8 @@ async function getSystemInfo() { networkSpeedDown, )} / ↑ ${formatBytes(networkSpeedUp)}` - setTimeout(() => { + clearTimeout(timer) + timer = setTimeout(() => { getSystemInfo() }, 1200) }