Fix all clippy warnings

This commit is contained in:
Your Name
2023-02-23 19:32:54 -05:00
parent 5d9c8b4d0c
commit 847631d94e
5 changed files with 21 additions and 30 deletions

View File

@@ -62,7 +62,6 @@ impl SessionMuter {
})) }))
}, },
_wn: { _wn: {
let tx = tx.clone();
WindowChangeMonitor::start(Box::new(move |s| { WindowChangeMonitor::start(Box::new(move |s| {
tx.send(MuterMessage::WindowChange(s.to_owned())).unwrap(); tx.send(MuterMessage::WindowChange(s.to_owned())).unwrap();
})) }))
@@ -86,8 +85,7 @@ impl SessionMuter {
self: &mut SessionMuter, self: &mut SessionMuter,
session: IAudioSessionControl2, session: IAudioSessionControl2,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
match self.session_to_filename(&session) { if let Ok(file_name) = self.session_to_filename(&session) {
Ok(file_name) => {
let fn_str = file_name.to_string_lossy().to_string(); let fn_str = file_name.to_string_lossy().to_string();
if self.mute_executables.contains(&fn_str) { if self.mute_executables.contains(&fn_str) {
println!("Adding session from: {:?}", fn_str); println!("Adding session from: {:?}", fn_str);
@@ -98,8 +96,6 @@ impl SessionMuter {
self.sessions.push(session); self.sessions.push(session);
} }
} }
Err(_) => {}
}
Ok(()) Ok(())
} }
@@ -142,7 +138,7 @@ impl SessionMuter {
let file_name = Path::new(&path) let file_name = Path::new(&path)
.file_name() .file_name()
.ok_or("Failed to extract filename from path")?; .ok_or("Failed to extract filename from path")?;
return Ok(file_name.to_os_string()); Ok(file_name.to_os_string())
} }
} }
} }
@@ -178,7 +174,7 @@ impl Drop for MuterThread {
fn load_mute_txt(file_name: &str) -> HashSet<String> { fn load_mute_txt(file_name: &str) -> HashSet<String> {
let file = File::open(file_name).unwrap(); let file = File::open(file_name).unwrap();
return HashSet::from_iter(BufReader::new(file).lines().map(|line| line.unwrap())); HashSet::from_iter(BufReader::new(file).lines().map(|line| line.unwrap()))
} }
fn await_file_change(file_name: &str) -> Result<(), Box<dyn Error>> { fn await_file_change(file_name: &str) -> Result<(), Box<dyn Error>> {
@@ -186,7 +182,7 @@ fn await_file_change(file_name: &str) -> Result<(), Box<dyn Error>> {
let md = fs::metadata(file_name)?.modified()?; let md = fs::metadata(file_name)?.modified()?;
let handle = FindFirstChangeNotificationW(w!("."), false, FILE_NOTIFY_CHANGE_LAST_WRITE)?; let handle = FindFirstChangeNotificationW(w!("."), false, FILE_NOTIFY_CHANGE_LAST_WRITE)?;
while md == fs::metadata(file_name)?.modified()? { while md == fs::metadata(file_name)?.modified()? {
WaitForSingleObject(HANDLE{0: handle.0}, INFINITE).ok()?; WaitForSingleObject(HANDLE(handle.0), INFINITE).ok()?;
FindNextChangeNotification(handle); FindNextChangeNotification(handle);
} }
println!("File change detected, restarting"); println!("File change detected, restarting");

View File

@@ -22,5 +22,5 @@ pub unsafe fn pid_to_exe_path(pid: u32) -> Result<String, Box<dyn Error>> {
} }
exe_name.set_len(size.try_into().unwrap()); exe_name.set_len(size.try_into().unwrap());
let process_name = String::from_utf16_lossy(&exe_name); let process_name = String::from_utf16_lossy(&exe_name);
return Ok(process_name); Ok(process_name)
} }

View File

@@ -17,7 +17,7 @@ pub trait SessionObserver {
fn add_session(&self, session: IAudioSessionControl2); fn add_session(&self, session: IAudioSessionControl2);
} }
impl<'a> IAudioSessionNotification_Impl for SessionNotification { impl IAudioSessionNotification_Impl for SessionNotification {
fn OnSessionCreated( fn OnSessionCreated(
self: &SessionNotification, self: &SessionNotification,
newsession: &core::option::Option<IAudioSessionControl>, newsession: &core::option::Option<IAudioSessionControl>,

View File

@@ -79,7 +79,7 @@ impl SMSessionNotifier {
}), }),
session_notification: IAudioSessionNotification::from(SessionNotification { session_notification: IAudioSessionNotification::from(SessionNotification {
observer: Box::new(SessionToMessage { observer: Box::new(SessionToMessage {
sender: sender.clone(), sender
}), }),
}), }),
notification_function: callback, notification_function: callback,
@@ -99,7 +99,7 @@ impl SMSessionNotifier {
self.add_device(mmdevice)?; self.add_device(mmdevice)?;
} }
println!("All devices initialized."); println!("All devices initialized.");
return Ok(()); Ok(())
} }
} }

View File

@@ -14,7 +14,8 @@ use windows::Win32::{
use crate::pid_to_exe::pid_to_exe_path; use crate::pid_to_exe::pid_to_exe_path;
static WIN_CHANGE_CALLBACK: Mutex<Option<Box<dyn Fn(&str)+Send>>> = Mutex::new(None); type WinCallback = Box<dyn Fn(&str) + Send>;
static WIN_CHANGE_CALLBACK: Mutex<Option<WinCallback>> = Mutex::new(None);
unsafe extern "system" fn win_event_proc( unsafe extern "system" fn win_event_proc(
_hook: HWINEVENTHOOK, _hook: HWINEVENTHOOK,
@@ -48,7 +49,6 @@ unsafe extern "system" fn win_event_proc(
} }
} }
type WinCallback = Box<dyn Fn(&str) + Send>;
pub fn await_win_change_events(callback: WinCallback) { pub fn await_win_change_events(callback: WinCallback) {
*WIN_CHANGE_CALLBACK.lock().unwrap() = Some(callback); *WIN_CHANGE_CALLBACK.lock().unwrap() = Some(callback);
@@ -109,18 +109,13 @@ impl WindowChangeMonitor {
let join_handle = { let join_handle = {
let win_thread_id = win_thread_id.clone(); let win_thread_id = win_thread_id.clone();
thread::spawn(move || { thread::spawn(move || {
win_thread_id.store(unsafe { GetCurrentThreadId() }.into(), std::sync::atomic::Ordering::Relaxed); win_thread_id.store(unsafe { GetCurrentThreadId() }, std::sync::atomic::Ordering::Relaxed);
await_win_change_events(f); await_win_change_events(f);
}) })
}; };
{
let win_thread_id = win_thread_id.clone();
WindowChangeMonitor { WindowChangeMonitor {
join_handle: Some(join_handle), join_handle: Some(join_handle),
win_thread_id win_thread_id
} }
} }
}
} }