feat: sync auto-start status

This commit is contained in:
wonfen 2025-03-17 09:48:44 +08:00
parent 697d200ffe
commit 6239f81f36
6 changed files with 30 additions and 2 deletions

View File

@ -70,6 +70,13 @@ pub fn get_app_dir() -> CmdResult<String> {
Ok(app_home_dir)
}
/// 获取当前自启动状态
#[tauri::command]
pub fn get_auto_launch_status() -> CmdResult<bool> {
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<String> {

View File

@ -229,6 +229,13 @@ impl Sysopt {
Ok(())
}
/// 获取当前自启动的实际状态
pub fn get_launch_status(&self) -> Result<bool> {
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();

View File

@ -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,

View File

@ -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";

View File

@ -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": "增强模式",

View File

@ -118,6 +118,10 @@ export async function getAutotemProxy() {
}>("get_auto_proxy");
}
export async function getAutoLaunchStatus() {
return invoke<boolean>("get_auto_launch_status");
}
export async function changeClashCore(clashCore: string) {
return invoke<string | null>("change_clash_core", { clashCore });
}