mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 04:43:44 +08:00
feat: quiting when enable tun mode no more blocking system network (#2805)
This commit is contained in:
parent
e7db13af37
commit
dce1395af1
@ -334,7 +334,7 @@ pub fn get_verge_config() -> CmdResult<IVergeResponse> {
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn patch_verge_config(payload: IVerge) -> CmdResult {
|
pub async fn patch_verge_config(payload: IVerge) -> CmdResult {
|
||||||
wrap_err!(feat::patch_verge(payload).await)
|
wrap_err!(feat::patch_verge(payload, false).await)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
|
@ -140,7 +140,7 @@ impl Hotkey {
|
|||||||
"clash_mode_global" => || feat::change_clash_mode("global".into()),
|
"clash_mode_global" => || feat::change_clash_mode("global".into()),
|
||||||
"clash_mode_direct" => || feat::change_clash_mode("direct".into()),
|
"clash_mode_direct" => || feat::change_clash_mode("direct".into()),
|
||||||
"toggle_system_proxy" => || feat::toggle_system_proxy(),
|
"toggle_system_proxy" => || feat::toggle_system_proxy(),
|
||||||
"toggle_tun_mode" => || feat::toggle_tun_mode(),
|
"toggle_tun_mode" => || feat::toggle_tun_mode(None),
|
||||||
"quit" => || feat::quit(Some(0)),
|
"quit" => || feat::quit(Some(0)),
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -87,7 +87,7 @@ impl Tray {
|
|||||||
{
|
{
|
||||||
match tray_event.as_str() {
|
match tray_event.as_str() {
|
||||||
"system_proxy" => feat::toggle_system_proxy(),
|
"system_proxy" => feat::toggle_system_proxy(),
|
||||||
"tun_mode" => feat::toggle_tun_mode(),
|
"tun_mode" => feat::toggle_tun_mode(None),
|
||||||
"main_window" => resolve::create_window(),
|
"main_window" => resolve::create_window(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ impl Tray {
|
|||||||
{
|
{
|
||||||
match tray_event.as_str() {
|
match tray_event.as_str() {
|
||||||
"system_proxy" => feat::toggle_system_proxy(),
|
"system_proxy" => feat::toggle_system_proxy(),
|
||||||
"tun_mode" => feat::toggle_tun_mode(),
|
"tun_mode" => feat::toggle_tun_mode(None),
|
||||||
"main_window" => resolve::create_window(),
|
"main_window" => resolve::create_window(),
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@ -594,7 +594,7 @@ fn on_menu_event(_: &AppHandle, event: MenuEvent) {
|
|||||||
}
|
}
|
||||||
"open_window" => resolve::create_window(),
|
"open_window" => resolve::create_window(),
|
||||||
"system_proxy" => feat::toggle_system_proxy(),
|
"system_proxy" => feat::toggle_system_proxy(),
|
||||||
"tun_mode" => feat::toggle_tun_mode(),
|
"tun_mode" => feat::toggle_tun_mode(None),
|
||||||
"copy_env" => feat::copy_clash_env(),
|
"copy_env" => feat::copy_clash_env(),
|
||||||
"open_app_dir" => crate::log_err!(cmds::open_app_dir()),
|
"open_app_dir" => crate::log_err!(cmds::open_app_dir()),
|
||||||
"open_core_dir" => crate::log_err!(cmds::open_core_dir()),
|
"open_core_dir" => crate::log_err!(cmds::open_core_dir()),
|
||||||
|
@ -151,7 +151,7 @@ pub fn toggle_system_proxy() {
|
|||||||
match patch_verge(IVerge {
|
match patch_verge(IVerge {
|
||||||
enable_system_proxy: Some(!enable),
|
enable_system_proxy: Some(!enable),
|
||||||
..IVerge::default()
|
..IVerge::default()
|
||||||
})
|
}, false)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_) => handle::Handle::refresh_verge(),
|
Ok(_) => handle::Handle::refresh_verge(),
|
||||||
@ -176,7 +176,7 @@ pub fn toggle_proxy_profile(profile_index: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 切换tun模式
|
// 切换tun模式
|
||||||
pub fn toggle_tun_mode() {
|
pub fn toggle_tun_mode(not_save_file: Option<bool>) {
|
||||||
let enable = Config::verge().data().enable_tun_mode;
|
let enable = Config::verge().data().enable_tun_mode;
|
||||||
let enable = enable.unwrap_or(false);
|
let enable = enable.unwrap_or(false);
|
||||||
|
|
||||||
@ -184,7 +184,7 @@ pub fn toggle_tun_mode() {
|
|||||||
match patch_verge(IVerge {
|
match patch_verge(IVerge {
|
||||||
enable_tun_mode: Some(!enable),
|
enable_tun_mode: Some(!enable),
|
||||||
..IVerge::default()
|
..IVerge::default()
|
||||||
})
|
}, not_save_file.unwrap_or(false))
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_) => handle::Handle::refresh_verge(),
|
Ok(_) => handle::Handle::refresh_verge(),
|
||||||
@ -196,6 +196,7 @@ pub fn toggle_tun_mode() {
|
|||||||
pub fn quit(code: Option<i32>) {
|
pub fn quit(code: Option<i32>) {
|
||||||
let app_handle = handle::Handle::global().app_handle().unwrap();
|
let app_handle = handle::Handle::global().app_handle().unwrap();
|
||||||
handle::Handle::global().set_is_exiting();
|
handle::Handle::global().set_is_exiting();
|
||||||
|
toggle_tun_mode(Some(true));
|
||||||
resolve::resolve_reset();
|
resolve::resolve_reset();
|
||||||
log_err!(handle::Handle::global().get_window().unwrap().close());
|
log_err!(handle::Handle::global().get_window().unwrap().close());
|
||||||
app_handle.exit(code.unwrap_or(0));
|
app_handle.exit(code.unwrap_or(0));
|
||||||
@ -236,7 +237,7 @@ pub async fn patch_clash(patch: Mapping) -> Result<()> {
|
|||||||
|
|
||||||
/// 修改verge的订阅
|
/// 修改verge的订阅
|
||||||
/// 一般都是一个个的修改
|
/// 一般都是一个个的修改
|
||||||
pub async fn patch_verge(patch: IVerge) -> Result<()> {
|
pub async fn patch_verge(patch: IVerge, not_save_file: bool) -> Result<()> {
|
||||||
Config::verge().draft().patch_config(patch.clone());
|
Config::verge().draft().patch_config(patch.clone());
|
||||||
|
|
||||||
let tun_mode = patch.enable_tun_mode;
|
let tun_mode = patch.enable_tun_mode;
|
||||||
@ -397,7 +398,9 @@ pub async fn patch_verge(patch: IVerge) -> Result<()> {
|
|||||||
match res {
|
match res {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
Config::verge().apply();
|
Config::verge().apply();
|
||||||
Config::verge().data().save_file()?;
|
if !not_save_file {
|
||||||
|
Config::verge().data().save_file()?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -617,7 +620,8 @@ pub async fn restore_webdav_backup(filename: String) -> Result<()> {
|
|||||||
webdav_username,
|
webdav_username,
|
||||||
webdav_password,
|
webdav_password,
|
||||||
..IVerge::default()
|
..IVerge::default()
|
||||||
})
|
},
|
||||||
|
false)
|
||||||
.await
|
.await
|
||||||
);
|
);
|
||||||
// 最后删除临时文件
|
// 最后删除临时文件
|
||||||
|
Loading…
x
Reference in New Issue
Block a user