fix: hide system monitoring bar should stop spawning subprocess

This commit is contained in:
Louis 2024-10-01 13:09:17 +07:00
parent 87e1754e3a
commit 080bef214b
No known key found for this signature in database
GPG Key ID: 44FA9F4D33C37DE2

View File

@ -1,4 +1,4 @@
import { Fragment, useEffect, useState } from 'react' import { Fragment, useCallback, useState } from 'react'
import { Progress } from '@janhq/joi' import { Progress } from '@janhq/joi'
import { useClickOutside } from '@janhq/joi' import { useClickOutside } from '@janhq/joi'
@ -51,24 +51,27 @@ const SystemMonitor = () => {
const reduceTransparent = useAtomValue(reduceTransparentAtom) const reduceTransparent = useAtomValue(reduceTransparentAtom)
const { watch, stopWatching } = useGetSystemResources() const { watch, stopWatching } = useGetSystemResources()
useClickOutside( useClickOutside(
() => { () => {
setShowSystemMonitorPanel(false) toggleShowSystemMonitorPanel(false)
setShowFullScreen(false) setShowFullScreen(false)
}, },
null, null,
[control, elementExpand] [control, elementExpand]
) )
useEffect(() => { const toggleShowSystemMonitorPanel = useCallback(
// Watch for resource update (isShow: boolean) => {
watch() setShowSystemMonitorPanel(isShow)
if (isShow) {
return () => { watch()
stopWatching() } else {
} stopWatching()
// eslint-disable-next-line react-hooks/exhaustive-deps }
}, []) },
[setShowSystemMonitorPanel, stopWatching, watch]
)
return ( return (
<Fragment> <Fragment>
@ -79,7 +82,7 @@ const SystemMonitor = () => {
showSystemMonitorPanel && 'bg-[hsla(var(--secondary-bg))]' showSystemMonitorPanel && 'bg-[hsla(var(--secondary-bg))]'
)} )}
onClick={() => { onClick={() => {
setShowSystemMonitorPanel(!showSystemMonitorPanel) toggleShowSystemMonitorPanel(!showSystemMonitorPanel)
setShowFullScreen(false) setShowFullScreen(false)
}} }}
> >
@ -123,7 +126,7 @@ const SystemMonitor = () => {
size={16} size={16}
className="text-[hsla(var(--text-secondary))]" className="text-[hsla(var(--text-secondary))]"
onClick={() => { onClick={() => {
setShowSystemMonitorPanel(false) toggleShowSystemMonitorPanel(false)
setShowFullScreen(false) setShowFullScreen(false)
}} }}
/> />