Merge branch 'dev'
This commit is contained in:
49
src/mixer.rs
49
src/mixer.rs
@@ -30,7 +30,10 @@ use crate::{
|
|||||||
instructions::MixerInstruction,
|
instructions::MixerInstruction,
|
||||||
playerctl::{playerctl_next, playerctl_play_pause, playerctl_previous},
|
playerctl::{playerctl_next, playerctl_play_pause, playerctl_previous},
|
||||||
pulseaudio::{PulseInstruction, SinkInputMixerData},
|
pulseaudio::{PulseInstruction, SinkInputMixerData},
|
||||||
utils::{get_sink_input_name, percentage_to_total_volume, send_notification, volume_to_percentage},
|
utils::{
|
||||||
|
get_sink_input_name, percentage_to_total_volume, send_notification,
|
||||||
|
send_notification_with_progress, volume_to_percentage,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Mixer {
|
pub struct Mixer {
|
||||||
@@ -401,11 +404,19 @@ impl Mixer {
|
|||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.introspect()
|
.introspect()
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.set_sink_input_volume(*sink_index, &volume, Some(Box::new(move |success| {
|
.set_sink_input_volume(
|
||||||
if success {
|
*sink_index,
|
||||||
let _ = send_notification(&format!("{sink_name}: {}%", volume_to_percentage(volume)));
|
&volume,
|
||||||
}
|
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 decrease_volume_current(&mut self) {
|
pub fn decrease_volume_current(&mut self) {
|
||||||
@@ -436,11 +447,19 @@ impl Mixer {
|
|||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.introspect()
|
.introspect()
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.set_sink_input_volume(*sink_index, &volume, Some(Box::new(move |success| {
|
.set_sink_input_volume(
|
||||||
if success {
|
*sink_index,
|
||||||
let _ = send_notification(&format!("{sink_name}: {}%", volume_to_percentage(volume)));
|
&volume,
|
||||||
}
|
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) {
|
pub fn get_current(&self) {
|
||||||
@@ -456,8 +475,12 @@ impl Mixer {
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let current_name = &self.sink_inputs.get(&sink_index).unwrap().name;
|
let current_sink = &self.sink_inputs.get(&sink_index).unwrap();
|
||||||
let _ = send_notification(&format!("{current_name}"));
|
let current_sink_volume_percent = current_sink.get_volume_percent();
|
||||||
|
let _ = send_notification_with_progress(
|
||||||
|
&format!("{}: {}%", ¤t_sink.name, current_sink_volume_percent),
|
||||||
|
current_sink_volume_percent,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play_pause_current(&self) {
|
pub fn play_pause_current(&self) {
|
||||||
|
|||||||
25
src/utils.rs
25
src/utils.rs
@@ -67,3 +67,28 @@ pub fn send_notification(message: &str) -> Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn send_notification_with_progress(message: &str, percent: u8) -> Result<()> {
|
||||||
|
let user_id = unsafe { getuid() };
|
||||||
|
|
||||||
|
Command::new("notify-send")
|
||||||
|
.args(vec![
|
||||||
|
"Mixrs",
|
||||||
|
message,
|
||||||
|
"-t",
|
||||||
|
&NOTIFICATION_DURATION_MILLIS.to_string(),
|
||||||
|
"-r",
|
||||||
|
&NOTIFY_SEND_REPLACE_ID.to_string(),
|
||||||
|
"-i",
|
||||||
|
"/",
|
||||||
|
"-h",
|
||||||
|
&format!("int:value:{percent}"),
|
||||||
|
])
|
||||||
|
.env(
|
||||||
|
"DBUS_SESSION_BUS_ADDRESS",
|
||||||
|
format!("unix:path=/run/user/{user_id}/bus"),
|
||||||
|
)
|
||||||
|
.spawn()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user