diff --git a/src-tauri/src/core/service.rs b/src-tauri/src/core/service.rs index 7f31390..2a4f055 100644 --- a/src-tauri/src/core/service.rs +++ b/src-tauri/src/core/service.rs @@ -300,7 +300,9 @@ pub mod win_service { /// stop service pub async fn stop_service() -> Result<()> { let url = format!("{SERVICE_URL}/stop_service"); - let res = reqwest::Client::new() + let res = reqwest::ClientBuilder::new() + .no_proxy() + .build()? .post(url) .send() .await? @@ -318,7 +320,11 @@ pub mod win_service { /// check the windows service status pub async fn check_service() -> Result { let url = format!("{SERVICE_URL}/get_clash"); - let response = reqwest::get(url) + let response = reqwest::ClientBuilder::new() + .no_proxy() + .build()? + .get(url) + .send() .await? .json::() .await @@ -351,7 +357,9 @@ pub mod win_service { map.insert("log_file", log_path); let url = format!("{SERVICE_URL}/start_clash"); - let res = reqwest::Client::new() + let res = reqwest::ClientBuilder::new() + .no_proxy() + .build()? .post(url) .json(&map) .send() @@ -370,7 +378,9 @@ pub mod win_service { /// stop the clash by service pub(super) async fn stop_clash_by_service() -> Result<()> { let url = format!("{SERVICE_URL}/stop_clash"); - let res = reqwest::Client::new() + let res = reqwest::ClientBuilder::new() + .no_proxy() + .build()? .post(url) .send() .await? diff --git a/src/components/setting/service-mode.tsx b/src/components/setting/service-mode.tsx index 46f5cbf..6472f03 100644 --- a/src/components/setting/service-mode.tsx +++ b/src/components/setting/service-mode.tsx @@ -1,104 +1,117 @@ -import useSWR, { useSWRConfig } from "swr"; -import { useLockFn } from "ahooks"; -import { useTranslation } from "react-i18next"; -import { - Button, - Dialog, - DialogContent, - DialogTitle, - Stack, - Typography, -} from "@mui/material"; -import { - checkService, - installService, - uninstallService, - patchVergeConfig, -} from "../../services/cmds"; -import Notice from "../base/base-notice"; -import noop from "../../utils/noop"; - -interface Props { - open: boolean; - enable: boolean; - onClose: () => void; - onError?: (err: Error) => void; -} - -const ServiceMode = (props: Props) => { - const { open, enable, onClose, onError = noop } = props; - - const { t } = useTranslation(); - const { mutate } = useSWRConfig(); - const { data: status } = useSWR("checkService", checkService, { - revalidateIfStale: true, - shouldRetryOnError: false, - }); - - const state = status != null ? status : "pending"; - - const onInstall = useLockFn(async () => { - try { - await installService(); - mutate("checkService"); - onClose(); - Notice.success("Service installed successfully"); - } catch (err: any) { - mutate("checkService"); - onError(err); - } - }); - - const onUninstall = useLockFn(async () => { - try { - if (state === "active" && enable) { - await patchVergeConfig({ enable_service_mode: false }); - } - - await uninstallService(); - mutate("checkService"); - onClose(); - Notice.success("Service uninstalled successfully"); - } catch (err: any) { - mutate("checkService"); - onError(err); - } - }); - - return ( - - {t("Service Mode")} - - - Current State: {state} - - {(state === "unknown" || state === "uninstall") && ( - - Infomation: Please make sure the Clash Verge Service is installed - and enabled - - )} - - - {state === "uninstall" && ( - - )} - - {(state === "active" || state === "installed") && ( - - )} - - - - ); -}; - -export default ServiceMode; +import useSWR, { useSWRConfig } from "swr"; +import { useLockFn } from "ahooks"; +import { useTranslation } from "react-i18next"; +import { + Button, + Dialog, + DialogContent, + DialogTitle, + Stack, + Typography, +} from "@mui/material"; +import { + checkService, + installService, + uninstallService, + patchVergeConfig, +} from "../../services/cmds"; +import Notice from "../base/base-notice"; +import noop from "../../utils/noop"; + +interface Props { + open: boolean; + enable: boolean; + onClose: () => void; + onError?: (err: Error) => void; +} + +const ServiceMode = (props: Props) => { + const { open, enable, onClose, onError = noop } = props; + + const { t } = useTranslation(); + const { mutate } = useSWRConfig(); + const { data: status } = useSWR("checkService", checkService, { + revalidateIfStale: true, + shouldRetryOnError: false, + }); + + const state = status != null ? status : "pending"; + + const onInstall = useLockFn(async () => { + try { + await installService(); + mutate("checkService"); + onClose(); + Notice.success("Service installed successfully"); + } catch (err: any) { + mutate("checkService"); + onError(err); + } + }); + + const onUninstall = useLockFn(async () => { + try { + if (state === "active" && enable) { + await patchVergeConfig({ enable_service_mode: false }); + } + + await uninstallService(); + mutate("checkService"); + onClose(); + Notice.success("Service uninstalled successfully"); + } catch (err: any) { + mutate("checkService"); + onError(err); + } + }); + + // fix unhandle error of the service mode + const onDisable = useLockFn(async () => { + await patchVergeConfig({ enable_service_mode: false }); + mutate("checkService"); + onClose(); + }); + + return ( + + {t("Service Mode")} + + + Current State: {state} + + {(state === "unknown" || state === "uninstall") && ( + + Infomation: Please make sure the Clash Verge Service is installed + and enabled + + )} + + + {state === "uninstall" && enable && ( + + )} + + {state === "uninstall" && ( + + )} + + {(state === "active" || state === "installed") && ( + + )} + + + + ); +}; + +export default ServiceMode;