Improve session filename error handling

This commit is contained in:
Your Name
2023-02-19 11:20:21 -05:00
parent 270a256444
commit f2d5263244

View File

@@ -105,7 +105,7 @@ impl IAudioSessionNotification_Impl for SessionNotification {
MUTER MUTER
.lock() .lock()
.unwrap() .unwrap()
.add_session_if_interesting(ses) .add_session(ses)
.unwrap(); .unwrap();
Ok(()) Ok(())
} }
@@ -201,17 +201,18 @@ impl SessionMuter {
} }
} }
fn add_session_if_interesting( fn add_session(
self: &mut SessionMuter, self: &mut SessionMuter,
session: IAudioSessionControl2, session: IAudioSessionControl2,
) -> Result<(), Box<dyn Error>> { ) -> Result<(), Box<dyn Error>> {
let file_name = self.session_to_filename(&session); unsafe {
if file_name.is_err() { if session.IsSystemSoundsSession().is_ok() {
return Ok(()); return Ok(());
} }
}
match self.session_to_filename(&session) {
Ok(file_name) => {
let fn_str = file_name let fn_str = file_name
.unwrap()
.to_os_string()
.to_string_lossy() .to_string_lossy()
.to_string(); .to_string();
if self.mute_executables.contains(&fn_str) { if self.mute_executables.contains(&fn_str) {
@@ -222,7 +223,12 @@ impl SessionMuter {
} }
self.sessions.lock().unwrap().push(session); self.sessions.lock().unwrap().push(session);
} }
return Ok(()); },
Err(err) => {
println!("Unable to get filename for session {:?}", err);
},
}
Ok(())
} }
unsafe fn set_mute_all(self: &mut SessionMuter, mute: bool) { unsafe fn set_mute_all(self: &mut SessionMuter, mute: bool) {
@@ -308,7 +314,7 @@ impl SessionMuter {
}) })
.collect::<Result<Vec<IAudioSessionControl2>, _>>()?; .collect::<Result<Vec<IAudioSessionControl2>, _>>()?;
for session in device_sessions { for session in device_sessions {
self.add_session_if_interesting(session)?; self.add_session(session)?;
} }
let prop_store = device.OpenPropertyStore(STGM_READ)?; let prop_store = device.OpenPropertyStore(STGM_READ)?;
// this definition isn't in windows-rs yet apparently :( // this definition isn't in windows-rs yet apparently :(