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