Merge branch 'dev'
This commit is contained in:
15
src/main.rs
15
src/main.rs
@@ -1,19 +1,26 @@
|
|||||||
mod instructions;
|
mod instructions;
|
||||||
pub mod mixer;
|
pub mod mixer;
|
||||||
|
pub mod playerctl;
|
||||||
pub mod pulseaudio;
|
pub mod pulseaudio;
|
||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod playerctl;
|
|
||||||
|
|
||||||
use mixer::Mixer;
|
use mixer::Mixer;
|
||||||
use pulseaudio::PulseInstruction;
|
use pulseaudio::PulseInstruction;
|
||||||
use std::sync::mpsc::channel;
|
use std::{env, sync::mpsc::channel};
|
||||||
|
|
||||||
fn main() {
|
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 (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);
|
mixer.run(pulse_ix_rx);
|
||||||
}
|
}
|
||||||
|
|||||||
35
src/mixer.rs
35
src/mixer.rs
@@ -7,6 +7,7 @@ use std::{
|
|||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
os::unix::net::{UnixListener, UnixStream},
|
os::unix::net::{UnixListener, UnixStream},
|
||||||
path::Path,
|
path::Path,
|
||||||
|
process::exit,
|
||||||
sync::{
|
sync::{
|
||||||
mpsc::{channel, Receiver, Sender},
|
mpsc::{channel, Receiver, Sender},
|
||||||
Arc, Mutex,
|
Arc, Mutex,
|
||||||
@@ -41,10 +42,15 @@ pub struct Mixer {
|
|||||||
selected_index: Arc<Mutex<Option<usize>>>,
|
selected_index: Arc<Mutex<Option<usize>>>,
|
||||||
mainloop: Mainloop,
|
mainloop: Mainloop,
|
||||||
context: pulse::context::Context,
|
context: pulse::context::Context,
|
||||||
|
silent_mode: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Mixer {
|
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 =
|
let mut context =
|
||||||
pulse::context::Context::new(&mainloop, "Mixrs").expect("Error creating pulse context");
|
pulse::context::Context::new(&mainloop, "Mixrs").expect("Error creating pulse context");
|
||||||
|
|
||||||
@@ -104,6 +110,7 @@ impl Mixer {
|
|||||||
selected_index,
|
selected_index,
|
||||||
mainloop,
|
mainloop,
|
||||||
context,
|
context,
|
||||||
|
silent_mode,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -422,7 +429,9 @@ impl Mixer {
|
|||||||
.set_sink_input_volume(
|
.set_sink_input_volume(
|
||||||
*sink_index,
|
*sink_index,
|
||||||
&volume,
|
&volume,
|
||||||
Some(Box::new(move |success| {
|
match self.silent_mode {
|
||||||
|
true => None,
|
||||||
|
false => Some(Box::new(move |success| {
|
||||||
if success {
|
if success {
|
||||||
let volume = volume_to_percentage(volume);
|
let volume = volume_to_percentage(volume);
|
||||||
let _ = send_notification_with_progress(
|
let _ = send_notification_with_progress(
|
||||||
@@ -431,6 +440,7 @@ impl Mixer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -465,7 +475,9 @@ impl Mixer {
|
|||||||
.set_sink_input_volume(
|
.set_sink_input_volume(
|
||||||
*sink_index,
|
*sink_index,
|
||||||
&volume,
|
&volume,
|
||||||
Some(Box::new(move |success| {
|
match self.silent_mode {
|
||||||
|
true => None,
|
||||||
|
false => Some(Box::new(move |success| {
|
||||||
if success {
|
if success {
|
||||||
let volume = volume_to_percentage(volume);
|
let volume = volume_to_percentage(volume);
|
||||||
let _ = send_notification_with_progress(
|
let _ = send_notification_with_progress(
|
||||||
@@ -474,10 +486,15 @@ impl Mixer {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
})),
|
})),
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_current(&self) {
|
pub fn get_current(&self) {
|
||||||
|
if self.silent_mode {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let index_lock = self.selected_index.lock().unwrap();
|
let index_lock = self.selected_index.lock().unwrap();
|
||||||
|
|
||||||
let Some(index) = *index_lock else {
|
let Some(index) = *index_lock else {
|
||||||
@@ -592,6 +609,16 @@ impl Mixer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn iterate_mainloop(mainloop: &mut pulse::mainloop::standard::Mainloop) {
|
pub fn iterate_mainloop(mainloop: &mut pulse::mainloop::standard::Mainloop) {
|
||||||
mainloop.borrow_mut().iterate(false);
|
match mainloop.borrow_mut().iterate(false) {
|
||||||
|
IterateResult::Success(s) => {
|
||||||
|
if s == 0 {
|
||||||
thread::sleep(Duration::from_millis(5));
|
thread::sleep(Duration::from_millis(5));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
IterateResult::Quit(_) => exit(0),
|
||||||
|
IterateResult::Err(e) => {
|
||||||
|
println!("Err: {:?}", e);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user