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