summaryrefslogtreecommitdiffstats
path: root/src/lib.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv@tobyvin.dev>2024-07-18 18:39:12 -0500
committerToby Vincent <tobyv@tobyvin.dev>2024-07-18 18:39:12 -0500
commit28bcf144224838e9e93d5926dcdbb20a4d45a8bf (patch)
tree8fe29412863efb925473519c0ca899c2a6344cfe /src/lib.rs
parent6e3b66e46c959f4b799e9422bd4d8b3279a06c3b (diff)
rewrite into individual execs
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs69
1 files changed, 62 insertions, 7 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 3adc3b9..0bdb7de 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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(())
+}