fix: optimize process ID collection and remove unnecessary async handler in window destruction

fix: remove unnecessary condition check in process name matching
This commit is contained in:
Tunglies
2025-10-21 22:59:59 +08:00
parent a8b17926ed
commit d9fdf261d1
2 changed files with 4 additions and 13 deletions

View File

@@ -83,7 +83,7 @@ impl CoreManager {
let process_name_clone = process_name.clone(); let process_name_clone = process_name.clone();
let pids = AsyncHandler::spawn_blocking(move || -> Result<Vec<u32>> { let pids = AsyncHandler::spawn_blocking(move || -> Result<Vec<u32>> {
let mut pids = Vec::with_capacity(8); let mut pids = Vec::new();
unsafe { unsafe {
let snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); let snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
@@ -102,12 +102,10 @@ impl CoreManager {
.position(|&x| x == 0) .position(|&x| x == 0)
.unwrap_or(pe32.szExeFile.len()); .unwrap_or(pe32.szExeFile.len());
if end_pos > 0 {
let exe_file = String::from_utf16_lossy(&pe32.szExeFile[..end_pos]); let exe_file = String::from_utf16_lossy(&pe32.szExeFile[..end_pos]);
if exe_file.eq_ignore_ascii_case(&process_name_clone) { if exe_file.eq_ignore_ascii_case(&process_name_clone) {
pids.push(pe32.th32ProcessID); pids.push(pe32.th32ProcessID);
} }
}
if Process32NextW(snapshot, &mut pe32) == 0 { if Process32NextW(snapshot, &mut pe32) == 0 {
break; break;

View File

@@ -339,13 +339,6 @@ pub fn run() {
} }
pub fn handle_window_destroyed() { pub fn handle_window_destroyed() {
AsyncHandler::spawn(|| async {
let _ = handle::Handle::mihomo()
.await
.clear_all_ws_connections()
.await;
});
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
{ {
use crate::core::hotkey::SystemHotkey; use crate::core::hotkey::SystemHotkey;