mirror of
https://mzte.de/git/LordMZTE/dotfiles.git
synced 2024-12-14 08:13:50 +01:00
i3status: pulseaudio is now refreshed on event
This commit is contained in:
parent
56172c3141
commit
73360c9c1e
2 changed files with 29 additions and 3 deletions
|
@ -19,4 +19,4 @@ features = ["derive"]
|
|||
|
||||
[dependencies.tokio]
|
||||
version = "1.9.0"
|
||||
features = ["macros", "rt-multi-thread", "time", "sync", "process"]
|
||||
features = ["macros", "rt-multi-thread", "time", "sync", "process", "io-util"]
|
||||
|
|
|
@ -4,6 +4,11 @@ use heim::{
|
|||
memory::os::linux::MemoryExt,
|
||||
units::{frequency::megahertz, information::megabyte, ratio},
|
||||
};
|
||||
use std::process::Stdio;
|
||||
use tokio::{
|
||||
io::{AsyncBufReadExt, BufReader},
|
||||
process::Child,
|
||||
};
|
||||
|
||||
use std::{sync::Arc, time::Duration};
|
||||
use tokio::{process::Command, sync::RwLock};
|
||||
|
@ -40,7 +45,22 @@ pub(crate) async fn time(bar: Arc<RwLock<Bar>>) {
|
|||
}
|
||||
|
||||
pub(crate) async fn pulseaudio_vol(bar: Arc<RwLock<Bar>>) {
|
||||
let mut int = tokio::time::interval(Duration::from_secs(2));
|
||||
let child = Command::new("pactl")
|
||||
.arg("subscribe")
|
||||
.stdout(Stdio::piped())
|
||||
.spawn();
|
||||
dbg!(&child);
|
||||
let stdout = match child {
|
||||
Ok(Child {
|
||||
stdout: Some(stdout),
|
||||
..
|
||||
}) => stdout,
|
||||
_ => {
|
||||
bar.write().await.vol = String::from("failed to spawn pactl :(");
|
||||
return;
|
||||
},
|
||||
};
|
||||
let mut stdout = BufReader::new(stdout);
|
||||
|
||||
loop {
|
||||
let res = Command::new("pactl")
|
||||
|
@ -85,7 +105,13 @@ pub(crate) async fn pulseaudio_vol(bar: Arc<RwLock<Bar>>) {
|
|||
}
|
||||
|
||||
bar.write().await.vol = msg;
|
||||
int.tick().await;
|
||||
loop {
|
||||
let mut buf = String::new();
|
||||
let _ = stdout.read_line(&mut buf).await;
|
||||
if buf.contains("change") {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue