fix: remove dead localStorage writes and hardcoded key

- Remove unused `dns_settings_enabled` localStorage writes in
  setting-clash.tsx — state is sourced from verge config, these
  writes were never read anywhere.
- Replace hardcoded `'last_check_update'` localStorage read in
  system-info-card.tsx with exported `readLastCheckTime()` from
  the useUpdate hook, keeping the key in a single source of truth.
This commit is contained in:
Tunglies 2026-03-29 02:06:08 +08:00
parent 99bbd7ee5a
commit 7a06a5a069
No known key found for this signature in database
GPG Key ID: B9B01B389469B3E8
3 changed files with 11 additions and 14 deletions

View File

@ -13,7 +13,11 @@ import { useNavigate } from 'react-router'
import { useServiceInstaller } from '@/hooks/use-service-installer' import { useServiceInstaller } from '@/hooks/use-service-installer'
import { useSystemState } from '@/hooks/use-system-state' import { useSystemState } from '@/hooks/use-system-state'
import { useUpdate, updateLastCheckTime } from '@/hooks/use-update' import {
useUpdate,
updateLastCheckTime,
readLastCheckTime,
} from '@/hooks/use-update'
import { useVerge } from '@/hooks/use-verge' import { useVerge } from '@/hooks/use-verge'
import { getSystemInfo } from '@/services/cmds' import { getSystemInfo } from '@/services/cmds'
import { showNotice } from '@/services/notice-service' import { showNotice } from '@/services/notice-service'
@ -63,8 +67,7 @@ export const SystemInfoCard = () => {
// 如果启用了自动检查更新但没有记录,设置当前时间并延迟检查 // 如果启用了自动检查更新但没有记录,设置当前时间并延迟检查
useEffect(() => { useEffect(() => {
if (!verge?.auto_check_update) return if (!verge?.auto_check_update) return
const stored = localStorage.getItem('last_check_update') if (readLastCheckTime() !== null) return
if (stored) return
updateLastCheckTime() updateLastCheckTime()
const timeoutId = window.setTimeout(() => { const timeoutId = window.setTimeout(() => {

View File

@ -78,7 +78,6 @@ const SettingClash = ({ onError }: Props) => {
const handleDnsToggle = useLockFn(async (enable: boolean) => { const handleDnsToggle = useLockFn(async (enable: boolean) => {
try { try {
setDnsSettingsEnabled(enable) setDnsSettingsEnabled(enable)
localStorage.setItem('dns_settings_enabled', String(enable))
await patchVerge({ enable_dns_settings: enable }) await patchVerge({ enable_dns_settings: enable })
await invoke('apply_dns_config', { apply: enable }) await invoke('apply_dns_config', { apply: enable })
setTimeout(() => { setTimeout(() => {
@ -86,7 +85,6 @@ const SettingClash = ({ onError }: Props) => {
}, 500) }, 500)
} catch (err: any) { } catch (err: any) {
setDnsSettingsEnabled(!enable) setDnsSettingsEnabled(!enable)
localStorage.setItem('dns_settings_enabled', String(!enable))
showNotice.error(err) showNotice.error(err)
await patchVerge({ enable_dns_settings: !enable }).catch(() => {}) await patchVerge({ enable_dns_settings: !enable }).catch(() => {})
throw err throw err

View File

@ -16,7 +16,7 @@ export interface UpdateInfo {
const LAST_CHECK_KEY = 'last_check_update' const LAST_CHECK_KEY = 'last_check_update'
const readLastCheckFromStorage = (): number | null => { export const readLastCheckTime = (): number | null => {
const stored = localStorage.getItem(LAST_CHECK_KEY) const stored = localStorage.getItem(LAST_CHECK_KEY)
if (!stored) return null if (!stored) return null
const ts = parseInt(stored, 10) const ts = parseInt(stored, 10)
@ -63,14 +63,10 @@ export const useUpdate = (
}) })
// Shared last check timestamp // Shared last check timestamp
const { data: lastCheckUpdate } = useSWR( const { data: lastCheckUpdate } = useSWR(LAST_CHECK_KEY, readLastCheckTime, {
LAST_CHECK_KEY, revalidateOnFocus: false,
readLastCheckFromStorage, revalidateOnReconnect: false,
{ })
revalidateOnFocus: false,
revalidateOnReconnect: false,
},
)
return { return {
updateInfo, updateInfo,