diff --git a/src-tauri/src/cmd/app.rs b/src-tauri/src/cmd/app.rs index 4fbc2d1f..cd54de3a 100644 --- a/src-tauri/src/cmd/app.rs +++ b/src-tauri/src/cmd/app.rs @@ -70,6 +70,13 @@ pub fn get_app_dir() -> CmdResult { Ok(app_home_dir) } +/// 获取当前自启动状态 +#[tauri::command] +pub fn get_auto_launch_status() -> CmdResult { + use crate::core::sysopt::Sysopt; + wrap_err!(Sysopt::global().get_launch_status()) +} + /// 下载图标缓存 #[tauri::command] pub async fn download_icon_cache(url: String, name: String) -> CmdResult { diff --git a/src-tauri/src/core/sysopt.rs b/src-tauri/src/core/sysopt.rs index 492fc53f..25ce95b6 100644 --- a/src-tauri/src/core/sysopt.rs +++ b/src-tauri/src/core/sysopt.rs @@ -229,6 +229,13 @@ impl Sysopt { Ok(()) } + /// 获取当前自启动的实际状态 + pub fn get_launch_status(&self) -> Result { + let app_handle = Handle::global().app_handle().unwrap(); + let autostart_manager = app_handle.autolaunch(); + Ok(autostart_manager.is_enabled()?) + } + fn guard_proxy(&self) { let _lock = self.guard_state.lock(); diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 43420a21..2f35a97c 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -154,6 +154,7 @@ pub fn run() { cmd::get_running_mode, cmd::install_service, cmd::get_app_uptime, + cmd::get_auto_launch_status, // clash cmd::get_clash_info, cmd::patch_clash_config, diff --git a/src/components/setting/setting-system.tsx b/src/components/setting/setting-system.tsx index 69c08855..fdeffd56 100644 --- a/src/components/setting/setting-system.tsx +++ b/src/components/setting/setting-system.tsx @@ -1,5 +1,5 @@ import useSWR, { mutate } from "swr"; -import { useRef } from "react"; +import { useRef, useEffect } from "react"; import { useTranslation } from "react-i18next"; import { SettingsRounded, @@ -20,6 +20,7 @@ import { getAutotemProxy, getRunningMode, installService, + getAutoLaunchStatus, } from "@/services/cmds"; import { useLockFn } from "ahooks"; import { Box, Button, Tooltip } from "@mui/material"; @@ -39,6 +40,14 @@ const SettingSystem = ({ onError }: Props) => { "getRunningMode", getRunningMode, ); + const { data: autoLaunchEnabled } = useSWR("getAutoLaunchStatus", getAutoLaunchStatus); + + // 当实际自启动状态与配置不同步时更新配置 + useEffect(() => { + if (autoLaunchEnabled !== undefined && verge && verge.enable_auto_launch !== autoLaunchEnabled) { + patchVerge({ enable_auto_launch: autoLaunchEnabled }); + } + }, [autoLaunchEnabled, verge]); // 是否以sidecar模式运行 const isSidecarMode = runningMode === "sidecar"; diff --git a/src/locales/zh.json b/src/locales/zh.json index ced5bc58..97b765ea 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -479,7 +479,7 @@ "Service Administrator Prompt": "Clash Verge 需要使用管理员权限来重新安装系统服务", "DNS Settings": "DNS 设置", "DNS Overwrite": "DNS 覆写", - "DNS Settings Warning": "如果你不清楚这里的设置请不要修改,并保持 DNS 设置开启", + "DNS Settings Warning": "如果你不清楚这里的设置请不要修改,并保持 DNS 覆写开启", "Enable DNS": "启用 DNS", "DNS Listen": "DNS 监听地址", "Enhanced Mode": "增强模式", diff --git a/src/services/cmds.ts b/src/services/cmds.ts index c9592944..d2d64e2e 100644 --- a/src/services/cmds.ts +++ b/src/services/cmds.ts @@ -118,6 +118,10 @@ export async function getAutotemProxy() { }>("get_auto_proxy"); } +export async function getAutoLaunchStatus() { + return invoke("get_auto_launch_status"); +} + export async function changeClashCore(clashCore: string) { return invoke("change_clash_core", { clashCore }); }