diff --git a/src-tauri/src/cmd/profile.rs b/src-tauri/src/cmd/profile.rs index 74876d28..5c72968b 100644 --- a/src-tauri/src/cmd/profile.rs +++ b/src-tauri/src/cmd/profile.rs @@ -176,7 +176,34 @@ pub async fn update_profile(index: String, option: Option) -> CmdResu /// 删除配置文件 #[tauri::command] pub async fn delete_profile(index: String) -> CmdResult { - let should_update = wrap_err!({ Config::profiles().data().delete_item(index) })?; + let should_update; + + { + let profiles_config = Config::profiles(); + let mut profiles_data = profiles_config.data(); + should_update = profiles_data.delete_item(index.clone()).map_err(|e| e.to_string())?; + + let was_last_profile = profiles_data.items.as_ref().map_or(true, |items| { + !items.iter().any(|item| + item.itype == Some("remote".to_string()) || item.itype == Some("local".to_string()) + ) + }); + + if was_last_profile { + logging!(info, Type::Cmd, true, "The last profile has been deleted. Disabling proxy modes..."); + let verge_config = Config::verge(); + let mut verge_data = verge_config.data(); + + if verge_data.enable_tun_mode == Some(true) || verge_data.enable_system_proxy == Some(true) { + verge_data.enable_tun_mode = Some(false); + verge_data.enable_system_proxy = Some(false); + verge_data.save_file().map_err(|e| e.to_string())?; + + handle::Handle::refresh_verge(); + handle::Handle::notice_message("info", "All profiles deleted, proxy disabled."); + } + } + } // 删除后自动清理冗余文件 let _ = Config::profiles().latest().auto_cleanup(); diff --git a/src/components/home/power-button.tsx b/src/components/home/power-button.tsx index d1d94cab..eedd5823 100644 --- a/src/components/home/power-button.tsx +++ b/src/components/home/power-button.tsx @@ -17,7 +17,8 @@ export const PowerButton = React.forwardRef
@@ -33,11 +34,18 @@ export const PowerButton = React.forwardRef 'data-[state=on]:text-green-500 dark:data-[state=on]:text-white', 'data-[state=on]:shadow-[0_0_50px_rgba(34,197,94,1)]', 'transition-all duration-300 hover:scale-105 active:scale-95 focus:outline-none', + 'disabled:cursor-not-allowed disabled:scale-100', + + // Стили ТОЛЬКО для отключенного состояния (но не для загрузки) + (props.disabled && !loading) && 'grayscale opacity-50 shadow-none bg-slate-100/70 border-slate-300/80', className )} {...props} > - + {loading && ( diff --git a/src/components/profile/profile-viewer.tsx b/src/components/profile/profile-viewer.tsx index df3084cb..c35c2d83 100644 --- a/src/components/profile/profile-viewer.tsx +++ b/src/components/profile/profile-viewer.tsx @@ -296,7 +296,7 @@ export const ProfileViewer = forwardRef( {!isUrlValid && importUrl && (

- {t("Please enter a valid URL")} + {t("Invalid Profile URL")}

)}
diff --git a/src/components/setting/setting-system.tsx b/src/components/setting/setting-system.tsx index f631cbe4..1cf0a678 100644 --- a/src/components/setting/setting-system.tsx +++ b/src/components/setting/setting-system.tsx @@ -1,4 +1,4 @@ -import { useRef, useState } from "react"; +import {useMemo, useRef, useState} from "react"; import { useTranslation } from "react-i18next"; import { useLockFn } from "ahooks"; import { mutate } from "swr"; @@ -56,6 +56,7 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select"; +import {useProfiles} from "@/hooks/use-profiles"; const isWIN = getSystem() === "windows"; interface Props { @@ -106,6 +107,12 @@ const SettingSystem = ({ onError }: Props) => { const { verge, patchVerge, mutateVerge } = useVerge(); const { installServiceAndRestartCore } = useServiceInstaller(); + const { profiles } = useProfiles(); + const hasProfiles = useMemo(() => { + const items = profiles?.items ?? []; + return items.some(p => p.type === 'local' || p.type === 'remote'); + }, [profiles]); + const { actualState: systemProxyActualState, indicator: systemProxyIndicator, @@ -261,7 +268,7 @@ const SettingSystem = ({ onError }: Props) => { }} onCatch={onError} > - + @@ -297,7 +304,7 @@ const SettingSystem = ({ onError }: Props) => { }} onCatch={onError} > - +