Skip to content

Commit

Permalink
reuse code across macos_list.rs and linux_list.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
errorxyz committed Dec 19, 2024
1 parent f3773dc commit 050682e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 67 deletions.
60 changes: 0 additions & 60 deletions src/processes/linux_list.rs

This file was deleted.

8 changes: 4 additions & 4 deletions src/processes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ pub use image;
use std::path::PathBuf;

#[cfg(target_os = "macos")]
mod macos_list;
mod nix_list;
#[cfg(target_os = "macos")]
pub use self::macos_list::active_executables;
pub use self::nix_list::active_executables;

#[cfg(windows)]
mod windows_list;
Expand All @@ -14,9 +14,9 @@ pub use self::windows_list::active_executables;
pub use self::windows_list::get_process_name;

#[cfg(target_os = "linux")]
mod linux_list;
mod nix_list;
#[cfg(target_os = "linux")]
pub use self::linux_list::active_executables;
pub use self::nix_list::active_executables;

#[cfg(target_os = "macos")]
mod macos_icons;
Expand Down
19 changes: 16 additions & 3 deletions src/processes/macos_list.rs → src/processes/nix_list.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
use crate::intercept_conf::PID;
use crate::processes::{ProcessInfo, ProcessList};
use anyhow::Result;

#[cfg(target_os = "macos")]
use cocoa::base::nil;
#[cfg(target_os = "macos")]
use cocoa::foundation::NSString;
use core_foundation::number::kCFNumberSInt32Type;
use core_foundation::number::CFNumberGetValue;
use core_foundation::number::CFNumberRef;
#[cfg(target_os = "macos")]
use core_foundation::number::{kCFNumberSInt32Type, CFNumberGetValue, CFNumberRef};
#[cfg(target_os = "macos")]
use core_graphics::display::{
kCGNullWindowID, kCGWindowListExcludeDesktopElements, kCGWindowListOptionOnScreenOnly,
CFArrayGetCount, CFArrayGetValueAtIndex, CFDictionaryGetValueIfPresent, CFDictionaryRef,
CGWindowListCopyWindowInfo,
};

use std::collections::hash_map::Entry;
use std::collections::{HashMap, HashSet};
#[cfg(target_os = "macos")]
use std::ffi::c_void;
use std::path::PathBuf;
use sysinfo::{ProcessRefreshKind, ProcessesToUpdate, System, UpdateKind};
Expand Down Expand Up @@ -65,6 +70,7 @@ pub fn active_executables() -> Result<ProcessList> {
Ok(executables.into_values().collect())
}

#[cfg(target_os = "macos")]
pub fn visible_windows() -> Result<HashSet<PID>> {
let mut pids: HashSet<PID> = HashSet::new();
unsafe {
Expand Down Expand Up @@ -100,6 +106,12 @@ pub fn visible_windows() -> Result<HashSet<PID>> {
}
}

#[cfg(target_os = "linux")]
pub fn visible_windows() -> Result<HashSet<PID>> {
// Finding visible windows on linux is not worth the effort
Ok(HashSet::new())
}

#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -117,6 +129,7 @@ mod tests {
dbg!(lst.len());
}

#[cfg(target_os = "macos")]
#[test]
fn visible_windows_list() {
let open_windows_pids = visible_windows().unwrap();
Expand Down

0 comments on commit 050682e

Please sign in to comment.