feat: --silent flag to disable notifications
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -1,19 +1,26 @@
|
||||
mod instructions;
|
||||
pub mod mixer;
|
||||
pub mod playerctl;
|
||||
pub mod pulseaudio;
|
||||
pub mod utils;
|
||||
pub mod playerctl;
|
||||
|
||||
use mixer::Mixer;
|
||||
use pulseaudio::PulseInstruction;
|
||||
use std::sync::mpsc::channel;
|
||||
use std::{env, sync::mpsc::channel};
|
||||
|
||||
fn main() {
|
||||
let mainloop = pulse::mainloop::standard::Mainloop::new().expect("Error getting PulseAudio main loop");
|
||||
let mainloop =
|
||||
pulse::mainloop::standard::Mainloop::new().expect("Error getting PulseAudio main loop");
|
||||
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let silent_mode = match args.iter().nth(1) {
|
||||
Some(arg) => arg == "--silent",
|
||||
None => false,
|
||||
};
|
||||
|
||||
let (pulse_ix_tx, pulse_ix_rx) = channel::<PulseInstruction>();
|
||||
|
||||
let mut mixer = Mixer::new(mainloop, pulse_ix_tx);
|
||||
let mut mixer = Mixer::new(mainloop, pulse_ix_tx, silent_mode);
|
||||
|
||||
mixer.run(pulse_ix_rx);
|
||||
}
|
||||
|
||||
54
src/mixer.rs
54
src/mixer.rs
@@ -42,10 +42,15 @@ pub struct Mixer {
|
||||
selected_index: Arc<Mutex<Option<usize>>>,
|
||||
mainloop: Mainloop,
|
||||
context: pulse::context::Context,
|
||||
silent_mode: bool,
|
||||
}
|
||||
|
||||
impl Mixer {
|
||||
pub fn new(mut mainloop: Mainloop, pulse_ix_tx: Sender<PulseInstruction>) -> Self {
|
||||
pub fn new(
|
||||
mut mainloop: Mainloop,
|
||||
pulse_ix_tx: Sender<PulseInstruction>,
|
||||
silent_mode: bool,
|
||||
) -> Self {
|
||||
let mut context =
|
||||
pulse::context::Context::new(&mainloop, "Mixrs").expect("Error creating pulse context");
|
||||
|
||||
@@ -105,6 +110,7 @@ impl Mixer {
|
||||
selected_index,
|
||||
mainloop,
|
||||
context,
|
||||
silent_mode,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,15 +429,18 @@ impl Mixer {
|
||||
.set_sink_input_volume(
|
||||
*sink_index,
|
||||
&volume,
|
||||
Some(Box::new(move |success| {
|
||||
if success {
|
||||
let volume = volume_to_percentage(volume);
|
||||
let _ = send_notification_with_progress(
|
||||
&format!("{sink_name}: {}%", volume),
|
||||
volume,
|
||||
);
|
||||
}
|
||||
})),
|
||||
match self.silent_mode {
|
||||
true => None,
|
||||
false => Some(Box::new(move |success| {
|
||||
if success {
|
||||
let volume = volume_to_percentage(volume);
|
||||
let _ = send_notification_with_progress(
|
||||
&format!("{sink_name}: {}%", volume),
|
||||
volume,
|
||||
);
|
||||
}
|
||||
})),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -466,19 +475,26 @@ impl Mixer {
|
||||
.set_sink_input_volume(
|
||||
*sink_index,
|
||||
&volume,
|
||||
Some(Box::new(move |success| {
|
||||
if success {
|
||||
let volume = volume_to_percentage(volume);
|
||||
let _ = send_notification_with_progress(
|
||||
&format!("{sink_name}: {}%", volume),
|
||||
volume,
|
||||
);
|
||||
}
|
||||
})),
|
||||
match self.silent_mode {
|
||||
true => None,
|
||||
false => Some(Box::new(move |success| {
|
||||
if success {
|
||||
let volume = volume_to_percentage(volume);
|
||||
let _ = send_notification_with_progress(
|
||||
&format!("{sink_name}: {}%", volume),
|
||||
volume,
|
||||
);
|
||||
}
|
||||
})),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
pub fn get_current(&self) {
|
||||
if self.silent_mode {
|
||||
return;
|
||||
}
|
||||
|
||||
let index_lock = self.selected_index.lock().unwrap();
|
||||
|
||||
let Some(index) = *index_lock else {
|
||||
|
||||
Reference in New Issue
Block a user