Files
Archive/clash-nyanpasu/frontend/interface/src/ipc/use-system-proxy.ts
T
2025-02-03 19:34:33 +01:00

27 lines
830 B
TypeScript

import { useQuery } from '@tanstack/react-query'
import { unwrapResult } from '../utils'
import { commands } from './bindings'
/**
* Custom hook to fetch and manage the system proxy settings.
*
* This hook leverages the `useQuery` hook to perform an asynchronous request
* to obtain system proxy data via `commands.getSysProxy()`. The result of the query
* is processed with `unwrapResult` to extract the proxy information.
*
* @returns An object containing the query results and helper properties/methods
* (e.g., loading status, error, and refetch function) provided by `useQuery`.
*/
export const useSystemProxy = () => {
const query = useQuery({
queryKey: ['system-proxy'],
queryFn: async () => {
return unwrapResult(await commands.getSysProxy())
},
})
return {
...query,
}
}