fix: defer provider queries on startup

This commit is contained in:
Tunglies
2026-06-29 06:03:51 +08:00
parent 2a5d29cdb2
commit 4ec3a9bf4c
3 changed files with 10 additions and 1 deletions
+5 -1
View File
@@ -18,7 +18,7 @@ import {
} from '@mui/material'
import { useLockFn } from 'ahooks'
import dayjs from 'dayjs'
import { useState } from 'react'
import { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { updateProxyProvider } from 'tauri-plugin-mihomo-api'
@@ -52,6 +52,10 @@ export const ProviderButton = () => {
const { refreshProxy, refreshProxyProviders } = useAppRefreshers()
const [updating, setUpdating] = useState<Record<string, boolean>>({})
useEffect(() => {
refreshProxyProviders().catch(() => {})
}, [refreshProxyProviders])
// 检查是否有提供者
const hasProviders = Object.keys(proxyProviders || {}).length > 0
+2
View File
@@ -79,12 +79,14 @@ export const AppDataProvider = ({
queryKey: ['getProxyProviders'],
queryFn: calcuProxyProviders,
...TQ_MIHOMO,
revalidateOnMount: false,
})
const { data: ruleProviders, refetch: _refetchRuleProviders } = useQuery({
queryKey: ['getRuleProviders'],
queryFn: getRuleProviders,
...TQ_MIHOMO,
revalidateOnMount: false,
})
const { data: rulesData, refetch: _refetchRules } = useQuery({
+3
View File
@@ -18,6 +18,7 @@ type QueryOptions<T> = {
retryDelay?: number | ((attempt: number) => number)
refetchInterval?: number | false
refetchIntervalInBackground?: boolean
revalidateOnMount?: boolean
refetchOnWindowFocus?: boolean
refetchOnReconnect?: boolean
}
@@ -110,6 +111,7 @@ export function useQuery<T>(options: QueryOptions<T>): QueryResult<T> {
retryDelay,
refetchInterval,
refetchIntervalInBackground,
revalidateOnMount,
refetchOnWindowFocus,
refetchOnReconnect,
staleTime,
@@ -148,6 +150,7 @@ export function useQuery<T>(options: QueryOptions<T>): QueryResult<T> {
}, interval)
},
revalidateOnFocus: refetchOnWindowFocus,
revalidateOnMount,
revalidateOnReconnect: refetchOnReconnect,
refreshInterval: refetchInterval || 0,
refreshWhenHidden: refetchIntervalInBackground ?? false,