From 847631d94e7c94693d12754964a4db1507c95e62 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 23 Feb 2023 19:32:54 -0500 Subject: [PATCH] Fix all clippy warnings --- src/main.rs | 26 +++++++++++--------------- src/pid_to_exe.rs | 2 +- src/session_notification.rs | 2 +- src/sm_session_notifier.rs | 4 ++-- src/window_change.rs | 17 ++++++----------- 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/main.rs b/src/main.rs index e9dacfc..bd0314b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -62,7 +62,6 @@ impl SessionMuter { })) }, _wn: { - let tx = tx.clone(); WindowChangeMonitor::start(Box::new(move |s| { tx.send(MuterMessage::WindowChange(s.to_owned())).unwrap(); })) @@ -86,19 +85,16 @@ impl SessionMuter { self: &mut SessionMuter, session: IAudioSessionControl2, ) -> Result<(), Box> { - match self.session_to_filename(&session) { - Ok(file_name) => { - let fn_str = file_name.to_string_lossy().to_string(); - if self.mute_executables.contains(&fn_str) { - println!("Adding session from: {:?}", fn_str); - unsafe { - let volume: ISimpleAudioVolume = session.cast()?; - volume.SetMute(self.mute_flag, null_mut())?; - } - self.sessions.push(session); + if let Ok(file_name) = self.session_to_filename(&session) { + let fn_str = file_name.to_string_lossy().to_string(); + if self.mute_executables.contains(&fn_str) { + println!("Adding session from: {:?}", fn_str); + unsafe { + let volume: ISimpleAudioVolume = session.cast()?; + volume.SetMute(self.mute_flag, null_mut())?; } + self.sessions.push(session); } - Err(_) => {} } Ok(()) } @@ -142,7 +138,7 @@ impl SessionMuter { let file_name = Path::new(&path) .file_name() .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 { 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> { @@ -186,7 +182,7 @@ fn await_file_change(file_name: &str) -> Result<(), Box> { let md = fs::metadata(file_name)?.modified()?; let handle = FindFirstChangeNotificationW(w!("."), false, FILE_NOTIFY_CHANGE_LAST_WRITE)?; while md == fs::metadata(file_name)?.modified()? { - WaitForSingleObject(HANDLE{0: handle.0}, INFINITE).ok()?; + WaitForSingleObject(HANDLE(handle.0), INFINITE).ok()?; FindNextChangeNotification(handle); } println!("File change detected, restarting"); diff --git a/src/pid_to_exe.rs b/src/pid_to_exe.rs index 8a175fc..3118eb9 100644 --- a/src/pid_to_exe.rs +++ b/src/pid_to_exe.rs @@ -22,5 +22,5 @@ pub unsafe fn pid_to_exe_path(pid: u32) -> Result> { } exe_name.set_len(size.try_into().unwrap()); let process_name = String::from_utf16_lossy(&exe_name); - return Ok(process_name); + Ok(process_name) } diff --git a/src/session_notification.rs b/src/session_notification.rs index 5a18f20..b56c391 100644 --- a/src/session_notification.rs +++ b/src/session_notification.rs @@ -17,7 +17,7 @@ pub trait SessionObserver { fn add_session(&self, session: IAudioSessionControl2); } -impl<'a> IAudioSessionNotification_Impl for SessionNotification { +impl IAudioSessionNotification_Impl for SessionNotification { fn OnSessionCreated( self: &SessionNotification, newsession: &core::option::Option, diff --git a/src/sm_session_notifier.rs b/src/sm_session_notifier.rs index c7e00c1..22f7a5d 100644 --- a/src/sm_session_notifier.rs +++ b/src/sm_session_notifier.rs @@ -79,7 +79,7 @@ impl SMSessionNotifier { }), session_notification: IAudioSessionNotification::from(SessionNotification { observer: Box::new(SessionToMessage { - sender: sender.clone(), + sender }), }), notification_function: callback, @@ -99,7 +99,7 @@ impl SMSessionNotifier { self.add_device(mmdevice)?; } println!("All devices initialized."); - return Ok(()); + Ok(()) } } diff --git a/src/window_change.rs b/src/window_change.rs index 1981a56..4f4d3d8 100644 --- a/src/window_change.rs +++ b/src/window_change.rs @@ -14,7 +14,8 @@ use windows::Win32::{ use crate::pid_to_exe::pid_to_exe_path; -static WIN_CHANGE_CALLBACK: Mutex>> = Mutex::new(None); +type WinCallback = Box; +static WIN_CHANGE_CALLBACK: Mutex> = Mutex::new(None); unsafe extern "system" fn win_event_proc( _hook: HWINEVENTHOOK, @@ -48,7 +49,6 @@ unsafe extern "system" fn win_event_proc( } } -type WinCallback = Box; pub fn await_win_change_events(callback: WinCallback) { *WIN_CHANGE_CALLBACK.lock().unwrap() = Some(callback); @@ -109,18 +109,13 @@ impl WindowChangeMonitor { let join_handle = { let win_thread_id = win_thread_id.clone(); 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); }) }; - - { - let win_thread_id = win_thread_id.clone(); - WindowChangeMonitor { - join_handle: Some(join_handle), - win_thread_id - } + WindowChangeMonitor { + join_handle: Some(join_handle), + win_thread_id } - } } \ No newline at end of file