diff options
Diffstat (limited to 'src/component/next.rs')
-rw-r--r-- | src/component/next.rs | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/src/component/next.rs b/src/component/next.rs deleted file mode 100644 index 52e72ff..0000000 --- a/src/component/next.rs +++ /dev/null @@ -1,77 +0,0 @@ -use std::sync::Arc; - -use tokio::sync::{mpsc::Sender, Mutex}; -use zbus::Connection; - -use crate::{ - dbus::player::{PlaybackStatus, PlayerProxy}, - i3bar::{Align, Block, Click, MinWidth}, - Error, -}; - -use super::{Button, Component, Output, Update}; - -pub struct Next; - -impl Component for Next { - type Updater = Self; - type Colorer = PlaybackStatus; - type Handler = Self; - - fn initialize() -> Block { - Block { - name: Some("mpris-next".into()), - full_text: ''.into(), - min_width: Some(MinWidth::Text("xx".to_string())), - align: Align::Center, - separator: Some(false), - separator_block_width: Some(0), - ..Default::default() - } - } -} - -impl Update for Next { - type Value = bool; - - async fn listen(tx: Sender<Self::Value>, proxy: PlayerProxy<'_>) -> Result<(), Error> { - use futures_util::StreamExt; - - let mut stream = proxy.receive_can_go_next_changed().await; - while let Some(signal) = stream.next().await { - if let Ok(value) = signal.get().await { - tx.send(value).await?; - } - } - Ok(()) - } - - async fn update(value: Self::Value, _: Arc<Mutex<Block>>) -> Result<Output, Error> { - if value { - Ok(Output::Print) - } else { - Ok(Output::Clear) - } - } -} - -impl Button for Next { - async fn handle(conn: Connection, click: Click) -> Result<(), Error> { - let Some(name) = click.instance else { - return Ok(()); - }; - - let proxy = PlayerProxy::builder(&conn) - .destination(name)? - .build() - .await?; - - match click.button { - 1 if proxy.can_go_next().await? => proxy.next().await?, - 3 if proxy.can_seek().await? => proxy.seek(5000).await?, - _ => {} - } - - Ok(()) - } -} |