Use friendly names for audio devices, clean up logs
This commit is contained in:
@@ -23,5 +23,6 @@ features = [
|
||||
"Win32_System_Threading",
|
||||
"Win32_UI_WindowsAndMessaging",
|
||||
"Win32_System_Com",
|
||||
"Win32_System_Com_StructuredStorage"
|
||||
"Win32_System_Com_StructuredStorage",
|
||||
"Win32_Devices_FunctionDiscovery"
|
||||
]
|
||||
16
src/main.rs
16
src/main.rs
@@ -1,5 +1,6 @@
|
||||
mod pid_to_exe;
|
||||
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
@@ -23,7 +24,7 @@ use windows::{
|
||||
IMMNotificationClient, IMMNotificationClient_Impl, ISimpleAudioVolume,
|
||||
MMDeviceEnumerator, DEVICE_STATE_ACTIVE,
|
||||
},
|
||||
System::Com::{CoCreateInstance, CoInitializeEx, CLSCTX_ALL, COINIT_MULTITHREADED},
|
||||
System::Com::{CoCreateInstance, CoInitializeEx, CLSCTX_ALL, COINIT_MULTITHREADED, STGM_READ},
|
||||
UI::{
|
||||
Accessibility::{SetWinEventHook, HWINEVENTHOOK},
|
||||
WindowsAndMessaging::{
|
||||
@@ -31,7 +32,7 @@ use windows::{
|
||||
TranslateMessage, EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_MINIMIZEEND, MSG,
|
||||
WINEVENT_OUTOFCONTEXT, WINEVENT_SKIPOWNPROCESS,
|
||||
},
|
||||
},
|
||||
}, Devices::FunctionDiscovery::PKEY_Device_FriendlyName,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -213,8 +214,8 @@ impl SessionMuter {
|
||||
.to_os_string()
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
println!("Adding session from: {:?}", fn_str);
|
||||
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())?;
|
||||
@@ -309,8 +310,11 @@ impl SessionMuter {
|
||||
for session in device_sessions {
|
||||
self.add_session_if_interesting(session)?;
|
||||
}
|
||||
let str = U16CStr::from_ptr_str(device.GetId()?.0).to_string_lossy();
|
||||
println!("Device Added: {} {}", str, session_count);
|
||||
let prop_store = device.OpenPropertyStore(STGM_READ)?;
|
||||
// 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);
|
||||
Ok(())
|
||||
}
|
||||
@@ -319,7 +323,7 @@ impl SessionMuter {
|
||||
unsafe impl Send for SessionMuter {}
|
||||
unsafe impl Sync for SessionMuter {}
|
||||
|
||||
static MUTER: Lazy<Arc<Mutex<SessionMuter>>> =
|
||||
static MUTER: Lazy<Arc<Mutex<SessionMuter>>> =
|
||||
Lazy::new(|| Arc::new(Mutex::new(SessionMuter::new())));
|
||||
|
||||
fn main() {
|
||||
|
||||
Reference in New Issue
Block a user