fix: harden home clash-mode card against /configs read failures

Recover from controller read/switch failures on the mode card instead of
showing a bare "communication error":

- fall back to the tolerant get_clash_mode command (then runtime config)
  when the live /configs mode is unavailable,
- optimistically reflect the clicked mode and write it through to the
  getClashConfig cache so a failed refetch can't flash back the old value,
- surface patch failures via showNotice on both the home card and the
  proxies page (patchClashMode can now reject), and
- revalidate getClashMode/getRuntimeConfig on refresh-clash-config so a
  once-empty fallback can recover.
This commit is contained in:
wonfen
2026-06-27 15:30:20 +08:00
parent d0d2f4e4f5
commit 5a96fdd9a2
5 changed files with 71 additions and 12 deletions
+11
View File
@@ -4,6 +4,7 @@ import { getVersion } from 'tauri-plugin-mihomo-api'
import {
getClashInfo,
getClashMode,
getRuntimeConfig,
patchClashConfig,
} from '@/services/cmds'
@@ -65,6 +66,16 @@ export const useRuntimeConfig = (shouldFetch: boolean = true) => {
})
}
// Fault-tolerant fallback for the current proxy mode, read straight from the
// saved clash config on the backend (bypasses the strict BaseConfig path).
export const useClashMode = (shouldFetch: boolean = true) => {
return useQuery({
queryKey: ['getClashMode'],
queryFn: getClashMode,
enabled: shouldFetch,
})
}
export const useClash = () => {
const { data: clash, refetch } = useRuntimeConfig()