fix listener memory leak

This commit is contained in:
pompurin404 2024-08-03 20:21:51 +08:00
parent f16f57ed1b
commit df8ae6392e
No known key found for this signature in database
5 changed files with 7 additions and 5 deletions

View File

@ -4,7 +4,7 @@ import { patchMihomoConfig } from '@renderer/utils/ipc'
import { Key } from 'react'
const OutboundModeSwitcher: React.FC = () => {
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig(true)
const { mode } = controledMihomoConfig || {}
const onChangeMode = async (mode: OutboundMode): Promise<void> => {

View File

@ -10,7 +10,7 @@ const SysproxySwitcher: React.FC = () => {
const navigate = useNavigate()
const location = useLocation()
const match = location.pathname.includes('/sysproxy')
const { appConfig, patchAppConfig } = useAppConfig()
const { appConfig, patchAppConfig } = useAppConfig(true)
const { sysProxy } = appConfig || {}
const { enable } = sysProxy || {}

View File

@ -11,7 +11,7 @@ const TunSwitcher: React.FC = () => {
const location = useLocation()
const match = location.pathname.includes('/tun')
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig(true)
const { tun } = controledMihomoConfig || {}
const { enable } = tun || {}

View File

@ -8,7 +8,7 @@ interface RetuenType {
patchAppConfig: (value: Partial<IAppConfig>) => Promise<void>
}
export const useAppConfig = (): RetuenType => {
export const useAppConfig = (listenUpdate = false): RetuenType => {
const { data: appConfig, mutate: mutateAppConfig } = useSWR('getConfig', () => getAppConfig())
const patchAppConfig = async (value: Partial<IAppConfig>): Promise<void> => {
@ -18,6 +18,7 @@ export const useAppConfig = (): RetuenType => {
}
useEffect(() => {
if (!listenUpdate) return
window.electron.ipcRenderer.on('appConfigUpdated', () => {
mutateAppConfig()
})

View File

@ -8,7 +8,7 @@ interface RetuenType {
patchControledMihomoConfig: (value: Partial<IMihomoConfig>) => Promise<void>
}
export const useControledMihomoConfig = (): RetuenType => {
export const useControledMihomoConfig = (listenUpdate = false): RetuenType => {
const { data: controledMihomoConfig, mutate: mutateControledMihomoConfig } = useSWR(
'getControledMihomoConfig',
() => getControledMihomoConfig()
@ -21,6 +21,7 @@ export const useControledMihomoConfig = (): RetuenType => {
}
useEffect(() => {
if (!listenUpdate) return
window.electron.ipcRenderer.on('controledMihomoConfigUpdated', () => {
mutateControledMihomoConfig()
})