Code cleanup part 2: Huge ass refactor edition

This commit is contained in:
Your Name
2023-02-19 18:14:37 -05:00
parent f2d5263244
commit 9eb15a4a5f
6 changed files with 346 additions and 246 deletions

View File

@@ -0,0 +1,56 @@
use windows::{
Win32::{
Media::Audio::{
IMMNotificationClient, IMMNotificationClient_Impl,
},
},
};
#[windows::core::implement(IMMNotificationClient)]
pub(crate) struct DeviceNotificationClient {
pub(crate) callback: Box<dyn Fn(&windows::core::PCWSTR)>
}
impl Drop for DeviceNotificationClient {
fn drop(&mut self) {
println!("DNC drop");
}
}
impl IMMNotificationClient_Impl for DeviceNotificationClient {
fn OnDeviceStateChanged(
&self,
_pwstrdeviceid: &windows::core::PCWSTR,
_dwnewstate: u32,
) -> windows::core::Result<()> {
Ok(())
}
fn OnDeviceAdded(&self, pwstrdeviceid: &windows::core::PCWSTR) -> windows::core::Result<()> {
(self.callback)(pwstrdeviceid);
Ok(())
}
fn OnDeviceRemoved(&self, _pwstrdeviceid: &windows::core::PCWSTR) -> windows::core::Result<()> {
println!("OnDeviceRemoved");
// TODO: Remove device and all its sessions
Ok(())
}
fn OnDefaultDeviceChanged(
&self,
_flow: windows::Win32::Media::Audio::EDataFlow,
_role: windows::Win32::Media::Audio::ERole,
_pwstrdefaultdeviceid: &windows::core::PCWSTR,
) -> windows::core::Result<()> {
Ok(())
}
fn OnPropertyValueChanged(
&self,
_pwstrdeviceid: &windows::core::PCWSTR,
_key: &windows::Win32::UI::Shell::PropertiesSystem::PROPERTYKEY,
) -> windows::core::Result<()> {
Ok(())
}
}