No more once_cell
Fix system audio check that didn't work because the API returns ()
This commit is contained in:
@@ -11,12 +11,6 @@ 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,
|
||||
@@ -32,8 +26,6 @@ impl IMMNotificationClient_Impl for DeviceNotificationClient {
|
||||
}
|
||||
|
||||
fn OnDeviceRemoved(&self, _pwstrdeviceid: &windows::core::PCWSTR) -> windows::core::Result<()> {
|
||||
println!("OnDeviceRemoved");
|
||||
// TODO: Remove device and all its sessions
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
18
src/main.rs
18
src/main.rs
@@ -12,7 +12,11 @@ use std::{
|
||||
io::{BufRead, BufReader},
|
||||
path::Path,
|
||||
ptr::null_mut,
|
||||
sync::{Arc, Mutex, mpsc::{self, Sender, Receiver}}, thread,
|
||||
sync::{
|
||||
mpsc::{self, Receiver, Sender},
|
||||
Arc, Mutex,
|
||||
},
|
||||
thread,
|
||||
};
|
||||
|
||||
use sm_session_notifier::SMSessionNotifier;
|
||||
@@ -51,11 +55,6 @@ impl SessionMuter {
|
||||
self: &mut SessionMuter,
|
||||
session: IAudioSessionControl2,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
unsafe {
|
||||
if session.IsSystemSoundsSession().is_ok() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
match self.session_to_filename(&session) {
|
||||
Ok(file_name) => {
|
||||
let fn_str = file_name.to_string_lossy().to_string();
|
||||
@@ -68,9 +67,7 @@ impl SessionMuter {
|
||||
self.sessions.push(session);
|
||||
}
|
||||
}
|
||||
Err(err) => {
|
||||
println!("Unable to get filename for session {:?}", err);
|
||||
}
|
||||
Err(_) => {}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -136,7 +133,7 @@ fn main() {
|
||||
.boot_devices()
|
||||
.expect("failed to get initial audio devices and sessions");
|
||||
|
||||
let (tx, rx) : (Sender<String>, Receiver<String>) = mpsc::channel();
|
||||
let (tx, rx): (Sender<String>, Receiver<String>) = mpsc::channel();
|
||||
*WIN_CHANGE_CHANNEL_TX.lock().unwrap().borrow_mut() = Some(tx);
|
||||
|
||||
thread::spawn(move || {
|
||||
@@ -147,5 +144,4 @@ fn main() {
|
||||
let path = rx.recv().unwrap();
|
||||
muter.lock().unwrap().notify_window_changed(&path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,9 +23,3 @@ impl IAudioSessionNotification_Impl for SessionNotification {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for SessionNotification {
|
||||
fn drop(&mut self) {
|
||||
println!("SN drop");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
sync::{mpsc::Sender, Arc, Mutex},
|
||||
sync::{mpsc::Sender, Mutex},
|
||||
};
|
||||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use windows::Win32::{
|
||||
Foundation::{HINSTANCE, HWND},
|
||||
UI::{
|
||||
@@ -18,8 +18,7 @@ use windows::Win32::{
|
||||
|
||||
use crate::pid_to_exe::pid_to_exe_path;
|
||||
|
||||
pub static WIN_CHANGE_CHANNEL_TX: Lazy<Arc<Mutex<RefCell<Option<Sender<String>>>>>> =
|
||||
Lazy::new(|| Arc::new(Mutex::new(RefCell::new(None))));
|
||||
pub static WIN_CHANGE_CHANNEL_TX: Mutex<RefCell<Option<Sender<String>>>> = Mutex::new(RefCell::new(None));
|
||||
|
||||
unsafe extern "system" fn win_event_proc(
|
||||
_hook: HWINEVENTHOOK,
|
||||
|
||||
Reference in New Issue
Block a user