Skip to content

Commit c46b90a

Browse files
authored
refactor: improve list_windows (#184)
1 parent 2fe3762 commit c46b90a

File tree

1 file changed

+14
-22
lines changed

1 file changed

+14
-22
lines changed

src/utils/window.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -235,37 +235,29 @@ pub fn list_windows(
235235
owner_hwnds.push(get_owner_window(hwnd))
236236
}
237237
for (hwnd, title) in valid_hwnds.into_iter() {
238-
let mut rs_module_path = "".to_string();
239-
if let Some(module_path) = get_module_path(get_window_pid(hwnd)) {
240-
rs_module_path = module_path;
238+
let mut module_path = "".to_string();
239+
if let Some(v) = get_module_path(get_window_pid(hwnd)) {
240+
module_path = v;
241241
}
242-
if !rs_module_path.is_empty()
243-
&& rs_module_path != "C:\\Windows\\System32\\ApplicationFrameHost.exe"
244-
{
245-
result
246-
.entry(rs_module_path)
247-
.or_default()
248-
.push((hwnd, title));
249-
continue;
250-
}
251-
if let Some((i, _)) = owner_hwnds.iter().enumerate().find(|(_, v)| **v == hwnd) {
252-
if let Some(module_path) = get_module_path(get_window_pid(hwnds[i])) {
253-
rs_module_path = module_path;
242+
if !is_valid_module_path(&module_path) {
243+
if let Some((i, _)) = owner_hwnds.iter().enumerate().find(|(_, v)| **v == hwnd) {
244+
if let Some(v) = get_module_path(get_window_pid(hwnds[i])) {
245+
module_path = v;
246+
}
254247
}
255248
}
256-
if !rs_module_path.is_empty()
257-
&& rs_module_path != "C:\\Windows\\System32\\ApplicationFrameHost.exe"
258-
{
259-
result
260-
.entry(rs_module_path)
261-
.or_default()
262-
.push((hwnd, title));
249+
if is_valid_module_path(&module_path) {
250+
result.entry(module_path).or_default().push((hwnd, title));
263251
}
264252
}
265253
debug!("list windows {:?}", result);
266254
Ok(result)
267255
}
268256

257+
fn is_valid_module_path(module_path: &str) -> bool {
258+
!module_path.is_empty() && module_path != "C:\\Windows\\System32\\ApplicationFrameHost.exe"
259+
}
260+
269261
extern "system" fn enum_window(hwnd: HWND, lparam: LPARAM) -> BOOL {
270262
let windows: &mut Vec<HWND> = unsafe { &mut *(lparam.0 as *mut Vec<HWND>) };
271263
windows.push(hwnd);

0 commit comments

Comments
 (0)