mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 05:13:44 +08:00
feat: close all connections when disable sysporxy
This commit is contained in:
parent
41629df189
commit
05b910dc17
@ -15,7 +15,8 @@
|
|||||||
- 使用 tauri window-state 管理窗口,尝试解决各种窗口异常
|
- 使用 tauri window-state 管理窗口,尝试解决各种窗口异常
|
||||||
|
|
||||||
#### 新增了:
|
#### 新增了:
|
||||||
- 允许代理主机地址设置为非 127.0.0.1。对 WSL 代理友好。
|
- 允许代理主机地址设置为非 127.0.0.1 对 WSL 代理友好
|
||||||
|
- 关闭系统代理时关闭已建立的网络连接
|
||||||
|
|
||||||
#### 优化了:
|
#### 优化了:
|
||||||
- 系统代理 Bypass 设置
|
- 系统代理 Bypass 设置
|
||||||
|
@ -10,8 +10,22 @@ use tauri_plugin_clipboard_manager::ClipboardExt;
|
|||||||
pub fn toggle_system_proxy() {
|
pub fn toggle_system_proxy() {
|
||||||
let enable = Config::verge().draft().enable_system_proxy;
|
let enable = Config::verge().draft().enable_system_proxy;
|
||||||
let enable = enable.unwrap_or(false);
|
let enable = enable.unwrap_or(false);
|
||||||
|
let auto_close_connection = Config::verge()
|
||||||
|
.data()
|
||||||
|
.auto_close_connection
|
||||||
|
.unwrap_or(false);
|
||||||
|
|
||||||
AsyncHandler::spawn(move || async move {
|
AsyncHandler::spawn(move || async move {
|
||||||
|
// 如果当前系统代理即将关闭,且自动关闭连接设置为true,则关闭所有连接
|
||||||
|
if enable && auto_close_connection {
|
||||||
|
if let Err(err) = crate::module::mihomo::MihomoManager::global()
|
||||||
|
.close_all_connections()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
log::error!(target: "app", "Failed to close all connections: {}", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
match super::patch_verge(
|
match super::patch_verge(
|
||||||
IVerge {
|
IVerge {
|
||||||
enable_system_proxy: Some(!enable),
|
enable_system_proxy: Some(!enable),
|
||||||
|
@ -95,6 +95,19 @@ impl MihomoManager {
|
|||||||
self.update_providers_proxies(providers_proxies);
|
self.update_providers_proxies(providers_proxies);
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn close_all_connections(&self) -> Result<(), String> {
|
||||||
|
let url = format!("{}/connections", self.mihomo_server);
|
||||||
|
let response = self.send_request(Method::DELETE, url, None).await?;
|
||||||
|
if response["code"] == 204 {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(response["message"]
|
||||||
|
.as_str()
|
||||||
|
.unwrap_or("unknown error")
|
||||||
|
.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MihomoManager {
|
impl MihomoManager {
|
||||||
|
@ -24,6 +24,7 @@ import {
|
|||||||
import { useLockFn } from "ahooks";
|
import { useLockFn } from "ahooks";
|
||||||
import { Button, Tooltip } from "@mui/material";
|
import { Button, Tooltip } from "@mui/material";
|
||||||
import { useSystemState } from "@/hooks/use-system-state";
|
import { useSystemState } from "@/hooks/use-system-state";
|
||||||
|
import { closeAllConnections } from "@/services/api";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
onError?: (err: Error) => void;
|
onError?: (err: Error) => void;
|
||||||
@ -182,6 +183,9 @@ const SettingSystem = ({ onError }: Props) => {
|
|||||||
onFormat={onSwitchFormat}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ enable_system_proxy: e })}
|
onChange={(e) => onChangeData({ enable_system_proxy: e })}
|
||||||
onGuard={async (e) => {
|
onGuard={async (e) => {
|
||||||
|
if (!e && verge?.auto_close_connection) {
|
||||||
|
closeAllConnections();
|
||||||
|
}
|
||||||
await patchVerge({ enable_system_proxy: e });
|
await patchVerge({ enable_system_proxy: e });
|
||||||
await updateProxyStatus();
|
await updateProxyStatus();
|
||||||
}}
|
}}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { useRef, useEffect } from "react";
|
import { useRef } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import useSWR, { mutate } from "swr";
|
import useSWR, { mutate } from "swr";
|
||||||
import {
|
import {
|
||||||
@ -16,7 +16,6 @@ import {
|
|||||||
useTheme,
|
useTheme,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
import { DialogRef, Notice, Switch } from "@/components/base";
|
import { DialogRef, Notice, Switch } from "@/components/base";
|
||||||
import { TooltipIcon } from "@/components/base/base-tooltip-icon";
|
|
||||||
import { GuardState } from "@/components/setting/mods/guard-state";
|
import { GuardState } from "@/components/setting/mods/guard-state";
|
||||||
import { SysproxyViewer } from "@/components/setting/mods/sysproxy-viewer";
|
import { SysproxyViewer } from "@/components/setting/mods/sysproxy-viewer";
|
||||||
import { TunViewer } from "@/components/setting/mods/tun-viewer";
|
import { TunViewer } from "@/components/setting/mods/tun-viewer";
|
||||||
@ -28,7 +27,7 @@ import {
|
|||||||
installService,
|
installService,
|
||||||
} from "@/services/cmds";
|
} from "@/services/cmds";
|
||||||
import { useLockFn } from "ahooks";
|
import { useLockFn } from "ahooks";
|
||||||
import { SettingItem } from "@/components/setting/mods/setting-comp";
|
import { closeAllConnections } from "@/services/api";
|
||||||
|
|
||||||
interface ProxySwitchProps {
|
interface ProxySwitchProps {
|
||||||
label?: string;
|
label?: string;
|
||||||
@ -168,6 +167,9 @@ const ProxyControlSwitches = ({ label, onError }: ProxySwitchProps) => {
|
|||||||
onFormat={onSwitchFormat}
|
onFormat={onSwitchFormat}
|
||||||
onChange={(e) => onChangeData({ enable_system_proxy: e })}
|
onChange={(e) => onChangeData({ enable_system_proxy: e })}
|
||||||
onGuard={async (e) => {
|
onGuard={async (e) => {
|
||||||
|
if (!e && verge?.auto_close_connection) {
|
||||||
|
closeAllConnections();
|
||||||
|
}
|
||||||
await patchVerge({ enable_system_proxy: e });
|
await patchVerge({ enable_system_proxy: e });
|
||||||
await updateProxyStatus();
|
await updateProxyStatus();
|
||||||
}}
|
}}
|
||||||
|
@ -4,7 +4,7 @@ import { useLockFn } from "ahooks";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Box, Button, ButtonGroup } from "@mui/material";
|
import { Box, Button, ButtonGroup } from "@mui/material";
|
||||||
import { closeAllConnections, getClashConfig } from "@/services/api";
|
import { closeAllConnections, getClashConfig } from "@/services/api";
|
||||||
import { patchClashConfig, patchClashMode } from "@/services/cmds";
|
import { patchClashMode } from "@/services/cmds";
|
||||||
import { useVerge } from "@/hooks/use-verge";
|
import { useVerge } from "@/hooks/use-verge";
|
||||||
import { BasePage } from "@/components/base";
|
import { BasePage } from "@/components/base";
|
||||||
import { ProxyGroups } from "@/components/proxy/proxy-groups";
|
import { ProxyGroups } from "@/components/proxy/proxy-groups";
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { createContext, useContext, useMemo } from "react";
|
import { createContext, useContext, useMemo } from "react";
|
||||||
import useSWR from "swr";
|
import useSWR from "swr";
|
||||||
import useSWRSubscription from "swr/subscription";
|
import useSWRSubscription from "swr/subscription";
|
||||||
import { getProxies, getConnections, getRules, getClashConfig, getProxyProviders, getRuleProviders } from "@/services/api";
|
import { getProxies, getRules, getClashConfig, getProxyProviders, getRuleProviders } from "@/services/api";
|
||||||
import { getSystemProxy, getRunningMode, getAppUptime } from "@/services/cmds";
|
import { getSystemProxy, getRunningMode, getAppUptime } from "@/services/cmds";
|
||||||
import { useClashInfo } from "@/hooks/use-clash";
|
import { useClashInfo } from "@/hooks/use-clash";
|
||||||
import { createAuthSockette } from "@/utils/websocket";
|
import { createAuthSockette } from "@/utils/websocket";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user