mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 13:10:30 +08:00
fix listener memory leak
This commit is contained in:
parent
f16f57ed1b
commit
df8ae6392e
@ -4,7 +4,7 @@ import { patchMihomoConfig } from '@renderer/utils/ipc'
|
|||||||
import { Key } from 'react'
|
import { Key } from 'react'
|
||||||
|
|
||||||
const OutboundModeSwitcher: React.FC = () => {
|
const OutboundModeSwitcher: React.FC = () => {
|
||||||
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
|
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig(true)
|
||||||
const { mode } = controledMihomoConfig || {}
|
const { mode } = controledMihomoConfig || {}
|
||||||
|
|
||||||
const onChangeMode = async (mode: OutboundMode): Promise<void> => {
|
const onChangeMode = async (mode: OutboundMode): Promise<void> => {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ const SysproxySwitcher: React.FC = () => {
|
|||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const match = location.pathname.includes('/sysproxy')
|
const match = location.pathname.includes('/sysproxy')
|
||||||
const { appConfig, patchAppConfig } = useAppConfig()
|
const { appConfig, patchAppConfig } = useAppConfig(true)
|
||||||
const { sysProxy } = appConfig || {}
|
const { sysProxy } = appConfig || {}
|
||||||
const { enable } = sysProxy || {}
|
const { enable } = sysProxy || {}
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ const TunSwitcher: React.FC = () => {
|
|||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const match = location.pathname.includes('/tun')
|
const match = location.pathname.includes('/tun')
|
||||||
|
|
||||||
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
|
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig(true)
|
||||||
const { tun } = controledMihomoConfig || {}
|
const { tun } = controledMihomoConfig || {}
|
||||||
const { enable } = tun || {}
|
const { enable } = tun || {}
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,7 @@ interface RetuenType {
|
|||||||
patchAppConfig: (value: Partial<IAppConfig>) => Promise<void>
|
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 { data: appConfig, mutate: mutateAppConfig } = useSWR('getConfig', () => getAppConfig())
|
||||||
|
|
||||||
const patchAppConfig = async (value: Partial<IAppConfig>): Promise<void> => {
|
const patchAppConfig = async (value: Partial<IAppConfig>): Promise<void> => {
|
||||||
@ -18,6 +18,7 @@ export const useAppConfig = (): RetuenType => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!listenUpdate) return
|
||||||
window.electron.ipcRenderer.on('appConfigUpdated', () => {
|
window.electron.ipcRenderer.on('appConfigUpdated', () => {
|
||||||
mutateAppConfig()
|
mutateAppConfig()
|
||||||
})
|
})
|
||||||
|
|||||||
@ -8,7 +8,7 @@ interface RetuenType {
|
|||||||
patchControledMihomoConfig: (value: Partial<IMihomoConfig>) => Promise<void>
|
patchControledMihomoConfig: (value: Partial<IMihomoConfig>) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useControledMihomoConfig = (): RetuenType => {
|
export const useControledMihomoConfig = (listenUpdate = false): RetuenType => {
|
||||||
const { data: controledMihomoConfig, mutate: mutateControledMihomoConfig } = useSWR(
|
const { data: controledMihomoConfig, mutate: mutateControledMihomoConfig } = useSWR(
|
||||||
'getControledMihomoConfig',
|
'getControledMihomoConfig',
|
||||||
() => getControledMihomoConfig()
|
() => getControledMihomoConfig()
|
||||||
@ -21,6 +21,7 @@ export const useControledMihomoConfig = (): RetuenType => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!listenUpdate) return
|
||||||
window.electron.ipcRenderer.on('controledMihomoConfigUpdated', () => {
|
window.electron.ipcRenderer.on('controledMihomoConfigUpdated', () => {
|
||||||
mutateControledMihomoConfig()
|
mutateControledMihomoConfig()
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user