perf(core): batch close connections on mode change

This commit is contained in:
Tunglies
2026-09-04 18:20:39 +08:00
parent 836199cfe2
commit d8b94d12dd
3 changed files with 7 additions and 25 deletions
+6 -12
View File
@@ -68,18 +68,12 @@ pub async fn restart_app() {
fn after_change_clash_mode() {
AsyncHandler::spawn(move || async {
let mihomo = handle::Handle::mihomo();
match mihomo.get_connections().await {
Ok(connections) => {
if let Some(connections_array) = connections.connections {
for connection in connections_array {
let _ = mihomo.close_connection(&connection.id).await;
}
}
}
Err(err) => {
logging!(error, Type::Core, "Failed to get connections: {err}");
}
if let Err(err) = handle::Handle::mihomo().close_all_connections().await {
logging!(
error,
Type::Core,
"Failed to close all connections after changing clash mode: {err}"
);
}
});
}