mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00: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'
|
||||
|
||||
const OutboundModeSwitcher: React.FC = () => {
|
||||
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig()
|
||||
const { controledMihomoConfig, patchControledMihomoConfig } = useControledMihomoConfig(true)
|
||||
const { mode } = controledMihomoConfig || {}
|
||||
|
||||
const onChangeMode = async (mode: OutboundMode): Promise<void> => {
|
||||
|
||||
@ -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 || {}
|
||||
|
||||
|
||||
@ -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 || {}
|
||||
|
||||
|
||||
@ -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()
|
||||
})
|
||||
|
||||
@ -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()
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user