Skip to content

Commit

Permalink
chore: refactor system info retrieval with locking mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
a145789 committed Jul 14, 2024
1 parent 45bc8a1 commit f1b7930
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -51,7 +57,8 @@ async function getSystemInfo() {
networkSpeedDown,
)} / ↑ ${formatBytes(networkSpeedUp)}`

setTimeout(() => {
clearTimeout(timer)
timer = setTimeout(() => {
getSystemInfo()
}, 1200)
}
Expand Down

0 comments on commit f1b7930

Please sign in to comment.