From 4945e93c4c55b745a1dc07c56b8d652422aa826a Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 2 Nov 2023 17:12:53 +0000 Subject: [PATCH] [autofix.ci] apply automated fixes --- mitmproxy-rs/src/process_info.rs | 4 +-- src/macos/icons.rs | 25 ++++++++++-------- src/macos/processes.rs | 44 +++++++++++++++++++++----------- 3 files changed, 45 insertions(+), 28 deletions(-) diff --git a/mitmproxy-rs/src/process_info.rs b/mitmproxy-rs/src/process_info.rs index 43030445..45354a01 100644 --- a/mitmproxy-rs/src/process_info.rs +++ b/mitmproxy-rs/src/process_info.rs @@ -3,12 +3,12 @@ use std::path::{Path, PathBuf}; use anyhow::Result; use pyo3::prelude::*; +#[cfg(target_os = "macos")] +use mitmproxy::macos::{icons, processes}; #[allow(unused_imports)] use mitmproxy::processes::image; #[cfg(windows)] use mitmproxy::windows::{icons, processes}; -#[cfg(target_os = "macos")] -use mitmproxy::macos::{processes, icons}; #[pyclass(module = "mitmproxy_rs", frozen)] pub struct Process(mitmproxy::processes::ProcessInfo); diff --git a/src/macos/icons.rs b/src/macos/icons.rs index 58c5e759..c5020ccc 100644 --- a/src/macos/icons.rs +++ b/src/macos/icons.rs @@ -1,14 +1,14 @@ -use once_cell::sync::Lazy; -use std::{sync::Mutex, collections::hash_map::Entry}; +use anyhow::{bail, Result}; use cocoa::base::id; -use sysinfo::{PidExt, ProcessExt, ProcessRefreshKind, System, SystemExt}; use objc::{class, msg_send, sel, sel_impl}; -use std::path::PathBuf; -use std::path::Path; use std::collections::HashMap; +use once_cell::sync::Lazy; use std::collections::hash_map::DefaultHasher; -use anyhow::{bail, Result}; -use std::hash::{Hasher, Hash}; - +use std::collections::HashMap; +use std::hash::{Hash, Hasher}; +use std::path::Path; +use std::path::PathBuf; +use std::{collections::hash_map::Entry, sync::Mutex}; +use sysinfo::{PidExt, ProcessExt, ProcessRefreshKind, System, SystemExt}; pub static ICON_CACHE: Lazy> = Lazy::new(|| Mutex::new(IconCache::default())); @@ -45,8 +45,11 @@ unsafe fn png_data_for_executable(executable: &Path) -> Result> { sys.refresh_processes_specifics(ProcessRefreshKind::new()); for (pid, process) in sys.processes() { let pid = pid.as_u32(); - if executable == process.exe().to_path_buf(){ - let app: id = msg_send![class!(NSRunningApplication), runningApplicationWithProcessIdentifier: pid]; + if executable == process.exe().to_path_buf() { + let app: id = msg_send![ + class!(NSRunningApplication), + runningApplicationWithProcessIdentifier: pid + ]; if !app.is_null() { let img: id = msg_send![app, icon]; let tif: id = msg_send![img, TIFFRepresentation]; @@ -55,7 +58,7 @@ unsafe fn png_data_for_executable(executable: &Path) -> Result> { let length: usize = msg_send![png, length]; let bytes: *const u8 = msg_send![png, bytes]; let data = std::slice::from_raw_parts(bytes, length).to_vec(); - return Ok(data) + return Ok(data); } } } diff --git a/src/macos/processes.rs b/src/macos/processes.rs index b9a7348f..66759791 100644 --- a/src/macos/processes.rs +++ b/src/macos/processes.rs @@ -1,18 +1,21 @@ -use std::collections::{HashMap, HashSet}; -use std::collections::hash_map::Entry; +use crate::intercept_conf::PID; use crate::processes::{ProcessInfo, ProcessList}; use anyhow::Result; use cocoa::base::nil; use cocoa::foundation::NSString; +use core_foundation::number::kCFNumberSInt32Type; use core_foundation::number::CFNumberGetValue; use core_foundation::number::CFNumberRef; -use core_foundation::number::kCFNumberSInt32Type; -use core_graphics::display::{CFDictionaryGetValueIfPresent, CGWindowListCopyWindowInfo, CFArrayGetCount, CFArrayGetValueAtIndex, CFDictionaryRef, kCGNullWindowID, kCGWindowListOptionOnScreenOnly, kCGWindowListExcludeDesktopElements}; +use core_graphics::display::{ + kCGNullWindowID, kCGWindowListExcludeDesktopElements, kCGWindowListOptionOnScreenOnly, + CFArrayGetCount, CFArrayGetValueAtIndex, CFDictionaryGetValueIfPresent, CFDictionaryRef, + CGWindowListCopyWindowInfo, +}; +use std::collections::hash_map::Entry; +use std::collections::{HashMap, HashSet}; use std::ffi::c_void; -use sysinfo::{PidExt, ProcessExt, ProcessRefreshKind, System, SystemExt}; use std::path::PathBuf; -use crate::intercept_conf::PID; - +use sysinfo::{PidExt, ProcessExt, ProcessRefreshKind, System, SystemExt}; pub fn active_executables() -> Result { let mut executables: HashMap = HashMap::new(); @@ -28,7 +31,7 @@ pub fn active_executables() -> Result { match executables.entry(executable) { Entry::Occupied(mut e) => { let process_info = e.get(); - if !process_info.is_visible && visible.contains(&pid){ + if !process_info.is_visible && visible.contains(&pid) { e.get_mut().is_visible = true; } } @@ -47,22 +50,33 @@ pub fn active_executables() -> Result { Ok(executables.into_values().collect()) } - pub fn visible_windows() -> Result> { let mut pids: HashSet = HashSet::new(); - unsafe{ - let windows_info_list = CGWindowListCopyWindowInfo( kCGWindowListOptionOnScreenOnly + kCGWindowListExcludeDesktopElements, kCGNullWindowID); + unsafe { + let windows_info_list = CGWindowListCopyWindowInfo( + kCGWindowListOptionOnScreenOnly + kCGWindowListExcludeDesktopElements, + kCGNullWindowID, + ); let count = CFArrayGetCount(windows_info_list); - for i in 0..count-1 { + for i in 0..count - 1 { let dic_ref = CFArrayGetValueAtIndex(windows_info_list, i); let key = NSString::alloc(nil).init_str("kCGWindowOwnerPID"); let mut pid: *const c_void = std::ptr::null_mut(); - if CFDictionaryGetValueIfPresent(dic_ref as CFDictionaryRef, key as *const c_void, &mut pid) != 0{ + if CFDictionaryGetValueIfPresent( + dic_ref as CFDictionaryRef, + key as *const c_void, + &mut pid, + ) != 0 + { let pid_cf_ref = pid as CFNumberRef; - let mut pid:i32 = 0; - if CFNumberGetValue(pid_cf_ref, kCFNumberSInt32Type, &mut pid as *mut i32 as *mut c_void) { + let mut pid: i32 = 0; + if CFNumberGetValue( + pid_cf_ref, + kCFNumberSInt32Type, + &mut pid as *mut i32 as *mut c_void, + ) { pids.insert(pid as u32); } }