mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 08:45:41 +08:00
feat: change proxy mode to close connections if enable auto close connections
This commit is contained in:
@@ -37,6 +37,19 @@ pub fn restart_app() {
|
||||
});
|
||||
}
|
||||
|
||||
fn after_change_clash_mode() {
|
||||
tauri::async_runtime::block_on(tauri::async_runtime::spawn_blocking(|| {
|
||||
tauri::async_runtime::block_on(async {
|
||||
let connections = MihomoManager::global().get_connections().await.unwrap();
|
||||
let connections = connections["connections"].as_array().unwrap();
|
||||
for connection in connections {
|
||||
let id = connection["id"].as_str().unwrap();
|
||||
let _ = MihomoManager::global().delete_connection(id).await;
|
||||
}
|
||||
})
|
||||
}));
|
||||
}
|
||||
|
||||
/// Change Clash mode (rule/global/direct/script)
|
||||
pub fn change_clash_mode(mode: String) {
|
||||
let mut mapping = Mapping::new();
|
||||
@@ -57,6 +70,14 @@ pub fn change_clash_mode(mode: String) {
|
||||
logging_error!(Type::Tray, true, tray::Tray::global().update_menu());
|
||||
logging_error!(Type::Tray, true, tray::Tray::global().update_icon(None));
|
||||
}
|
||||
|
||||
let is_auto_close_connection = Config::verge()
|
||||
.data()
|
||||
.auto_close_connection
|
||||
.unwrap_or(false);
|
||||
if is_auto_close_connection {
|
||||
after_change_clash_mode();
|
||||
}
|
||||
}
|
||||
Err(err) => println!("{err}"),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user