From e6a5a2b4961dba4e891b1b62d6f35db4ca9ee5ce Mon Sep 17 00:00:00 2001 From: HZ <99131470+hustler-not-chatty@users.noreply.github.com> Date: Sun, 31 Mar 2024 15:55:51 +0000 Subject: [PATCH] fixup! feat: Service Mode for Linux (#804) --- src-tauri/src/feat.rs | 20 +++++---------- .../setting/mods/stack-mode-switch.tsx | 25 ++++++------------- 2 files changed, 13 insertions(+), 32 deletions(-) diff --git a/src-tauri/src/feat.rs b/src-tauri/src/feat.rs index 4e12f28d..c212af00 100644 --- a/src-tauri/src/feat.rs +++ b/src-tauri/src/feat.rs @@ -185,22 +185,14 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> { let tun_tray_icon = patch.tun_tray_icon; match { - #[cfg(any(target_os = "windows", target_os = "linux"))] - { - let service_mode = patch.enable_service_mode; + let service_mode = patch.enable_service_mode; - if service_mode.is_some() { - log::debug!(target: "app", "change service mode to {}", service_mode.unwrap()); + if service_mode.is_some() { + log::debug!(target: "app", "change service mode to {}", service_mode.unwrap()); - Config::generate()?; - CoreManager::global().run_core().await?; - } else if tun_mode.is_some() { - update_core_config().await?; - } - } - - #[cfg(not(target_os = "windows"))] - if tun_mode.is_some() { + Config::generate()?; + CoreManager::global().run_core().await?; + } else if tun_mode.is_some() { update_core_config().await?; } diff --git a/src/components/setting/mods/stack-mode-switch.tsx b/src/components/setting/mods/stack-mode-switch.tsx index d671d339..55ad8dd0 100644 --- a/src/components/setting/mods/stack-mode-switch.tsx +++ b/src/components/setting/mods/stack-mode-switch.tsx @@ -2,11 +2,8 @@ import { useTranslation } from "react-i18next"; import { Button, ButtonGroup, Tooltip } from "@mui/material"; import { checkService } from "@/services/cmds"; import { useVerge } from "@/hooks/use-verge"; -import getSystem from "@/utils/get-system"; import useSWR from "swr"; -const isWIN = getSystem() === "windows"; - interface Props { value?: string; onChange?: (value: string) => void; @@ -17,21 +14,17 @@ export const StackModeSwitch = (props: Props) => { const { verge } = useVerge(); const { enable_service_mode } = verge ?? {}; // service mode - const { data: serviceStatus } = useSWR( - isWIN ? "checkService" : null, - checkService, - { - revalidateIfStale: false, - shouldRetryOnError: false, - } - ); + const { data: serviceStatus } = useSWR("checkService", checkService, { + revalidateIfStale: false, + shouldRetryOnError: false, + }); const { t } = useTranslation(); return ( {