Add mute change notification, remove nwg trash, package updates

This commit is contained in:
Your Name
2025-02-16 11:19:29 -05:00
parent 5f69fc664a
commit 989c5c05a5
7 changed files with 182 additions and 318 deletions

View File

@@ -1,4 +1,3 @@
use std::{
collections::HashSet,
error::Error,
@@ -13,10 +12,12 @@ use crate::sm_session_notifier::SMSessionNotifierThread;
use crate::window_change::WindowChangeMonitor;
use windows::{
core::Interface,
Win32::Media::Audio::{IAudioSessionControl2, ISimpleAudioVolume},
Win32::{
Media::Audio::{IAudioSessionControl2, ISimpleAudioVolume},
System::Com::{CoInitializeEx, COINIT_MULTITHREADED},
},
};
use crate::pid_to_exe::pid_to_exe_path;
enum MuterMessage {
WindowChange(String),
@@ -24,6 +25,10 @@ enum MuterMessage {
Exit(),
}
pub enum MuteChangeNotification {
MuteChanged(bool),
}
unsafe impl Send for MuterMessage {}
struct SessionMuter {
@@ -33,6 +38,7 @@ struct SessionMuter {
_session_notifier: SMSessionNotifierThread,
_win_change_mon: WindowChangeMonitor,
rx: Receiver<MuterMessage>,
notify_tx: Option<Sender<MuteChangeNotification>>,
}
impl SessionMuter {
@@ -40,6 +46,7 @@ impl SessionMuter {
mute_executables: HashSet<String>,
rx: Receiver<MuterMessage>,
tx: Sender<MuterMessage>,
notify_tx: Option<Sender<MuteChangeNotification>>,
) -> SessionMuter {
SessionMuter {
sessions: Vec::new(),
@@ -57,6 +64,7 @@ impl SessionMuter {
}))
},
rx,
notify_tx,
}
}
@@ -84,6 +92,8 @@ impl SessionMuter {
volume.SetMute(self.mute_flag, null_mut())?;
}
self.sessions.push(session);
} else {
println!("Skipping session from: {:?}", fn_str);
}
}
Ok(())
@@ -91,6 +101,9 @@ impl SessionMuter {
fn set_mute_all(self: &mut SessionMuter, mute: bool) {
unsafe {
self.notify_tx
.as_ref()
.and_then(|x| x.send(MuteChangeNotification::MuteChanged(mute)).ok());
let results = self
.sessions
.iter()
@@ -141,12 +154,18 @@ pub struct MuterThread {
}
impl MuterThread {
pub fn new(s: HashSet<String>) -> MuterThread {
pub fn com_init() {
unsafe { CoInitializeEx(None, COINIT_MULTITHREADED).unwrap() };
}
pub fn new(
s: HashSet<String>,
notify_tx: Option<Sender<MuteChangeNotification>>,
) -> MuterThread {
let (sender, receiver) = mpsc::channel::<MuterMessage>();
MuterThread {
sender: sender.clone(),
handle: Some(thread::spawn(move || {
let mut muter = SessionMuter::new(s, receiver, sender);
let mut muter = SessionMuter::new(s, receiver, sender, notify_tx);
muter.run();
})),
}