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: {
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<dyn Error>> {
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<String> {
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>> {
@@ -186,7 +182,7 @@ fn await_file_change(file_name: &str) -> Result<(), Box<dyn Error>> {
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");

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());
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);
}
impl<'a> IAudioSessionNotification_Impl for SessionNotification {
impl IAudioSessionNotification_Impl for SessionNotification {
fn OnSessionCreated(
self: &SessionNotification,
newsession: &core::option::Option<IAudioSessionControl>,

View File

@@ -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(())
}
}

View File

@@ -14,7 +14,8 @@ use windows::Win32::{
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(
_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) {
*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
}
}
}