From a5d0729bbae0cda1481dcdb731502a33d8bd09be Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 19 Feb 2023 22:27:19 -0500 Subject: [PATCH] No more once_cell Fix system audio check that didn't work because the API returns () --- Cargo.lock | 7 ------- Cargo.toml | 1 - mute.txt | 1 + src/device_notification_client.rs | 8 -------- src/main.rs | 18 +++++++----------- src/session_notification.rs | 6 ------ src/window_change.rs | 7 +++---- 7 files changed, 11 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6a22809..4dfcc90 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,17 +6,10 @@ version = 3 name = "auto_mute_tool" version = "0.1.0" dependencies = [ - "once_cell", "widestring", "windows", ] -[[package]] -name = "once_cell" -version = "1.17.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" - [[package]] name = "proc-macro2" version = "1.0.51" diff --git a/Cargo.toml b/Cargo.toml index 18df8c2..04c87f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,6 @@ edition = "2021" [dependencies] widestring = "1.0.2" -once_cell = "1.17.1" [dependencies.windows] version = "0.44.0" diff --git a/mute.txt b/mute.txt index 3055131..2caf36a 100644 --- a/mute.txt +++ b/mute.txt @@ -14,3 +14,4 @@ sm64.us.f3dex2e.exe teardown.exe underrail.exe valheim.exe +Spotify.exe \ No newline at end of file diff --git a/src/device_notification_client.rs b/src/device_notification_client.rs index b1f9a9d..741373a 100644 --- a/src/device_notification_client.rs +++ b/src/device_notification_client.rs @@ -11,12 +11,6 @@ pub(crate) struct DeviceNotificationClient { pub(crate) callback: Box } -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(()) } diff --git a/src/main.rs b/src/main.rs index 42f5053..eee22d7 100644 --- a/src/main.rs +++ b/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> { - 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, Receiver) = mpsc::channel(); + let (tx, rx): (Sender, Receiver) = 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); } - } diff --git a/src/session_notification.rs b/src/session_notification.rs index ccc0e57..08352e2 100644 --- a/src/session_notification.rs +++ b/src/session_notification.rs @@ -23,9 +23,3 @@ impl IAudioSessionNotification_Impl for SessionNotification { Ok(()) } } - -impl Drop for SessionNotification { - fn drop(&mut self) { - println!("SN drop"); - } -} diff --git a/src/window_change.rs b/src/window_change.rs index c57cdb3..895e3d1 100644 --- a/src/window_change.rs +++ b/src/window_change.rs @@ -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>>>>> = - Lazy::new(|| Arc::new(Mutex::new(RefCell::new(None)))); +pub static WIN_CHANGE_CHANNEL_TX: Mutex>>> = Mutex::new(RefCell::new(None)); unsafe extern "system" fn win_event_proc( _hook: HWINEVENTHOOK,