Improve session filename error handling
This commit is contained in:
44
src/main.rs
44
src/main.rs
@@ -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,28 +201,34 @@ 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(());
|
||||||
}
|
|
||||||
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())?;
|
|
||||||
}
|
}
|
||||||
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) {
|
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 :(
|
||||||
|
|||||||
Reference in New Issue
Block a user