Use friendly names for audio devices, clean up logs
This commit is contained in:
@@ -23,5 +23,6 @@ features = [
|
|||||||
"Win32_System_Threading",
|
"Win32_System_Threading",
|
||||||
"Win32_UI_WindowsAndMessaging",
|
"Win32_UI_WindowsAndMessaging",
|
||||||
"Win32_System_Com",
|
"Win32_System_Com",
|
||||||
"Win32_System_Com_StructuredStorage"
|
"Win32_System_Com_StructuredStorage",
|
||||||
|
"Win32_Devices_FunctionDiscovery"
|
||||||
]
|
]
|
||||||
14
src/main.rs
14
src/main.rs
@@ -1,5 +1,6 @@
|
|||||||
mod pid_to_exe;
|
mod pid_to_exe;
|
||||||
|
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashSet,
|
collections::HashSet,
|
||||||
@@ -23,7 +24,7 @@ use windows::{
|
|||||||
IMMNotificationClient, IMMNotificationClient_Impl, ISimpleAudioVolume,
|
IMMNotificationClient, IMMNotificationClient_Impl, ISimpleAudioVolume,
|
||||||
MMDeviceEnumerator, DEVICE_STATE_ACTIVE,
|
MMDeviceEnumerator, DEVICE_STATE_ACTIVE,
|
||||||
},
|
},
|
||||||
System::Com::{CoCreateInstance, CoInitializeEx, CLSCTX_ALL, COINIT_MULTITHREADED},
|
System::Com::{CoCreateInstance, CoInitializeEx, CLSCTX_ALL, COINIT_MULTITHREADED, STGM_READ},
|
||||||
UI::{
|
UI::{
|
||||||
Accessibility::{SetWinEventHook, HWINEVENTHOOK},
|
Accessibility::{SetWinEventHook, HWINEVENTHOOK},
|
||||||
WindowsAndMessaging::{
|
WindowsAndMessaging::{
|
||||||
@@ -31,7 +32,7 @@ use windows::{
|
|||||||
TranslateMessage, EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_MINIMIZEEND, MSG,
|
TranslateMessage, EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_MINIMIZEEND, MSG,
|
||||||
WINEVENT_OUTOFCONTEXT, WINEVENT_SKIPOWNPROCESS,
|
WINEVENT_OUTOFCONTEXT, WINEVENT_SKIPOWNPROCESS,
|
||||||
},
|
},
|
||||||
},
|
}, Devices::FunctionDiscovery::PKEY_Device_FriendlyName,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -213,8 +214,8 @@ impl SessionMuter {
|
|||||||
.to_os_string()
|
.to_os_string()
|
||||||
.to_string_lossy()
|
.to_string_lossy()
|
||||||
.to_string();
|
.to_string();
|
||||||
println!("Adding session from: {:?}", fn_str);
|
|
||||||
if self.mute_executables.contains(&fn_str) {
|
if self.mute_executables.contains(&fn_str) {
|
||||||
|
println!("Adding session from: {:?}", fn_str);
|
||||||
unsafe {
|
unsafe {
|
||||||
let volume: ISimpleAudioVolume = session.cast()?;
|
let volume: ISimpleAudioVolume = session.cast()?;
|
||||||
volume.SetMute(self.mute_flag, null_mut())?;
|
volume.SetMute(self.mute_flag, null_mut())?;
|
||||||
@@ -309,8 +310,11 @@ impl SessionMuter {
|
|||||||
for session in device_sessions {
|
for session in device_sessions {
|
||||||
self.add_session_if_interesting(session)?;
|
self.add_session_if_interesting(session)?;
|
||||||
}
|
}
|
||||||
let str = U16CStr::from_ptr_str(device.GetId()?.0).to_string_lossy();
|
let prop_store = device.OpenPropertyStore(STGM_READ)?;
|
||||||
println!("Device Added: {} {}", str, session_count);
|
// this definition isn't in windows-rs yet apparently :(
|
||||||
|
let prop_var = prop_store.GetValue(&PKEY_Device_FriendlyName)?;
|
||||||
|
let str = U16CStr::from_ptr_str(prop_var.Anonymous.Anonymous.Anonymous.pwszVal.0).to_string_lossy();
|
||||||
|
println!("Device Added: {} Existing Sessions: {}", str, session_count);
|
||||||
self.session_managers.push(sm);
|
self.session_managers.push(sm);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user