mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-18 08:21:34 +08:00
fix: prevent TUN from being falsely disabled during startup
- Add 10s startup grace period before TUN auto-disable logic activates; service IPC may not be ready when the frontend first queries, causing a transient isServiceOk=false that incorrectly persists - Replace placeholderData (which set isLoading=false with stale data) with a proper isStartingUp guard; query now polls every 2s during startup to catch service readiness quickly - Add 'getSystemState' to refresh-verge-config invalidation keys to fix key mismatch that prevented event-driven refetches from working
This commit is contained in:
parent
decdeffcf6
commit
5da9f99698
@ -1,5 +1,5 @@
|
|||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery } from '@tanstack/react-query'
|
||||||
import { useEffect, useRef } from 'react'
|
import { useEffect, useRef, useState } from 'react'
|
||||||
|
|
||||||
import { getRunningMode, isAdmin, isServiceAvailable } from '@/services/cmds'
|
import { getRunningMode, isAdmin, isServiceAvailable } from '@/services/cmds'
|
||||||
import { showNotice } from '@/services/notice-service'
|
import { showNotice } from '@/services/notice-service'
|
||||||
@ -18,6 +18,9 @@ const defaultSystemState = {
|
|||||||
isServiceOk: false,
|
isServiceOk: false,
|
||||||
} as SystemState
|
} as SystemState
|
||||||
|
|
||||||
|
// Grace period for service initialization during startup
|
||||||
|
const STARTUP_GRACE_MS = 10_000
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 自定义 hook 用于获取系统运行状态
|
* 自定义 hook 用于获取系统运行状态
|
||||||
* 包括运行模式、管理员状态、系统服务是否可用
|
* 包括运行模式、管理员状态、系统服务是否可用
|
||||||
@ -25,6 +28,12 @@ const defaultSystemState = {
|
|||||||
export function useSystemState() {
|
export function useSystemState() {
|
||||||
const { verge, patchVerge } = useVerge()
|
const { verge, patchVerge } = useVerge()
|
||||||
const disablingTunRef = useRef(false)
|
const disablingTunRef = useRef(false)
|
||||||
|
const [isStartingUp, setIsStartingUp] = useState(true)
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const timer = setTimeout(() => setIsStartingUp(false), STARTUP_GRACE_MS)
|
||||||
|
return () => clearTimeout(timer)
|
||||||
|
}, [])
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: systemState = defaultSystemState,
|
data: systemState = defaultSystemState,
|
||||||
@ -40,8 +49,7 @@ export function useSystemState() {
|
|||||||
])
|
])
|
||||||
return { runningMode, isAdminMode, isServiceOk } as SystemState
|
return { runningMode, isAdminMode, isServiceOk } as SystemState
|
||||||
},
|
},
|
||||||
refetchInterval: 30000,
|
refetchInterval: isStartingUp ? 2000 : 30000,
|
||||||
placeholderData: defaultSystemState,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const isSidecarMode = systemState.runningMode === 'Sidecar'
|
const isSidecarMode = systemState.runningMode === 'Sidecar'
|
||||||
@ -58,7 +66,8 @@ export function useSystemState() {
|
|||||||
!disablingTunRef.current &&
|
!disablingTunRef.current &&
|
||||||
enable_tun_mode &&
|
enable_tun_mode &&
|
||||||
!isTunModeAvailable &&
|
!isTunModeAvailable &&
|
||||||
!isLoading
|
!isLoading &&
|
||||||
|
!isStartingUp
|
||||||
) {
|
) {
|
||||||
disablingTunRef.current = true
|
disablingTunRef.current = true
|
||||||
patchVerge({ enable_tun_mode: false })
|
patchVerge({ enable_tun_mode: false })
|
||||||
@ -89,7 +98,7 @@ export function useSystemState() {
|
|||||||
disablingTunRef.current = false
|
disablingTunRef.current = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [enable_tun_mode, isTunModeAvailable, patchVerge, isLoading])
|
}, [enable_tun_mode, isTunModeAvailable, patchVerge, isLoading, isStartingUp])
|
||||||
|
|
||||||
return {
|
return {
|
||||||
runningMode: systemState.runningMode,
|
runningMode: systemState.runningMode,
|
||||||
|
|||||||
@ -62,6 +62,7 @@ export const useLayoutEvents = (
|
|||||||
'getAutotemProxy',
|
'getAutotemProxy',
|
||||||
'getRunningMode',
|
'getRunningMode',
|
||||||
'isServiceAvailable',
|
'isServiceAvailable',
|
||||||
|
'getSystemState',
|
||||||
])
|
])
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user