fixed an issue with enabling tun and system proxy if profiles are missing

This commit is contained in:
coolcoala
2025-08-05 19:05:44 +03:00
parent d2d26cc822
commit ffd32426b5
4 changed files with 49 additions and 7 deletions

View File

@@ -176,7 +176,34 @@ pub async fn update_profile(index: String, option: Option<PrfOption>) -> 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();

View File

@@ -17,7 +17,8 @@ export const PowerButton = React.forwardRef<HTMLButtonElement, PowerButtonProps>
<div
className={cn(
'absolute h-28 w-28 rounded-full blur-3xl transition-all duration-500',
state === 'on' ? 'bg-green-400/60' : 'bg-red-500/40'
state === 'on' ? 'bg-green-400/60' : 'bg-red-500/40',
props.disabled && 'opacity-0'
)}
/>
@@ -33,11 +34,18 @@ export const PowerButton = React.forwardRef<HTMLButtonElement, PowerButtonProps>
'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}
>
<Power className="h-20 w-20 transition-transform duration-300 active:scale-90" />
<Power className={cn(
"h-20 w-20",
!props.disabled && "active:scale-90 transition-transform duration-300"
)} />
</button>
{loading && (

View File

@@ -296,7 +296,7 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
</Button>
{!isUrlValid && importUrl && (
<p className="text-sm text-destructive px-1">
{t("Please enter a valid URL")}
{t("Invalid Profile URL")}
</p>
)}
</div>

View File

@@ -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}
>
<Switch disabled={!isTunAvailable} />
<Switch disabled={!isTunAvailable || !hasProfiles} />
</GuardState>
</SettingRow>
@@ -297,7 +304,7 @@ const SettingSystem = ({ onError }: Props) => {
}}
onCatch={onError}
>
<Switch />
<Switch disabled={!hasProfiles} />
</GuardState>
</SettingRow>