diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 69 |
1 files changed, 62 insertions, 7 deletions
@@ -1,13 +1,68 @@ +use dbus::{ + player::{PlaybackStatus, PlayerProxy}, + playerctld::PlayerctldProxy, +}; pub use error::{Error, Result}; +use futures_util::StreamExt; +use tokio::sync::mpsc::Sender; + pub mod color; -pub mod components; pub mod dbus; pub mod error; pub mod i3bar; -//pub mod mpris; -pub mod client; -pub mod dbus_server; -pub mod player; -pub mod printer; -pub mod server; + +const BLACK: &str = "#1d2021"; +const YELLOW: &str = "#fabd2f"; +const CYAN: &str = "#8ec07c"; + +const IGNORED: [&str; 2] = ["playerctld", "kdeconnect"]; + +impl From<PlaybackStatus> for (Option<String>, Option<String>) { + fn from(value: PlaybackStatus) -> Self { + match value { + PlaybackStatus::Playing => (Some(BLACK.into()), Some(CYAN.into())), + PlaybackStatus::Paused => (Some(BLACK.into()), Some(YELLOW.into())), + PlaybackStatus::Stopped => (None, None), + } + } +} + +pub async fn color_listener( + tx: Sender<(Option<String>, Option<String>)>, + proxy: PlayerProxy<'_>, +) -> Result<()> { + let mut stream = proxy.receive_playback_status_changed().await; + while let Some(signal) = stream.next().await { + if let Ok(value) = signal.get().await { + tx.send(value.into()).await?; + } + } + Ok(()) +} + +pub async fn player_listener(tx: Sender<String>, proxy: PlayerctldProxy<'_>) -> Result<(), Error> { + let mut last = proxy + .player_names() + .await? + .into_iter() + .next() + .unwrap_or_default(); + + tx.send(last.clone()).await?; + + let mut stream = proxy.receive_active_player_change_end().await?; + while let Some(signal) = stream.next().await { + let name = signal.args()?.name.to_owned(); + if name != last + && name + .split('.') + .nth(3) + .is_some_and(|s| !IGNORED.contains(&s)) + { + last.clone_from(&name); + tx.send(name).await?; + } + } + Ok(()) +} |