Skip to content

Commit

Permalink
fix listener memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Aug 3, 2024
1 parent 6484e3e commit d9120e4
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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> => {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/sider/sysproxy-switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {}

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/components/sider/tun-switcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {}

Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/hooks/use-app-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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> => {
Expand All @@ -18,6 +18,7 @@ export const useAppConfig = (): RetuenType => {
}

useEffect(() => {
if (!listenUpdate) return
window.electron.ipcRenderer.on('appConfigUpdated', () => {
mutateAppConfig()
})
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/src/hooks/use-controled-mihomo-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -21,6 +21,7 @@ export const useControledMihomoConfig = (): RetuenType => {
}

useEffect(() => {
if (!listenUpdate) return
window.electron.ipcRenderer.on('controledMihomoConfigUpdated', () => {
mutateControledMihomoConfig()
})
Expand Down

0 comments on commit d9120e4

Please sign in to comment.