summaryrefslogtreecommitdiffstats
path: root/src/bin/volume.rs
diff options
context:
space:
mode:
authorToby Vincent <tobyv@tobyvin.dev>2024-07-19 19:06:43 -0500
committerToby Vincent <tobyv@tobyvin.dev>2024-07-19 19:06:43 -0500
commit61edce3cf70798d46df234de356e37ad7dde18a8 (patch)
treec7f03a467e65e2292e1ba58257bdcb1f045dad8b /src/bin/volume.rs
parent8b0c211cb489b20e58d3f5da9a772ae7e808324f (diff)
fix: clean up unused modules and rename bins
Diffstat (limited to 'src/bin/volume.rs')
-rw-r--r--src/bin/volume.rs77
1 files changed, 0 insertions, 77 deletions
diff --git a/src/bin/volume.rs b/src/bin/volume.rs
deleted file mode 100644
index b5182b3..0000000
--- a/src/bin/volume.rs
+++ /dev/null
@@ -1,77 +0,0 @@
-use std::sync::Arc;
-
-use i3blocks::{
- dbus::player::{PlaybackStatus, PlayerProxy},
- i3bar::{Block, Click},
- Button, Component, Error, Update,
-};
-use tokio::sync::{mpsc::Sender, Mutex};
-use zbus::Connection;
-
-#[tokio::main]
-async fn main() -> Result<(), main_error::MainError> {
- i3blocks::run::<Volume>(Default::default())
- .await
- .map_err(Into::into)
-}
-
-pub struct Volume;
-
-impl Component for Volume {
- const NAME: &'static str = "volume";
- type Updater = Self;
- type Colorer = PlaybackStatus;
- type Handler = Self;
-}
-
-impl Update for Volume {
- type Value = f64;
-
- async fn listen(tx: Sender<Self::Value>, proxy: PlayerProxy<'_>) -> Result<(), Error> {
- use futures_util::StreamExt;
-
- tx.send(proxy.volume().await?).await?;
- let mut stream = proxy.receive_volume_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, block: Arc<Mutex<Block>>) -> Result<bool, Error> {
- let mut block = block.lock().await;
- block.full_text = match (value * 100_f64) as u32 {
- v @ 66.. => format!("󰕾 {v}% "),
- v @ 33.. => format!("󰖀 {v}% "),
- v @ 0.. => format!("󰕿 {v}% "),
- };
- Ok(true)
- }
-}
-
-impl Button for Volume {
- 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 {
- 4 if proxy.can_control().await? => {
- proxy.set_volume(proxy.volume().await? - 0.05).await?
- }
- 5 if proxy.can_control().await? => {
- proxy.set_volume(proxy.volume().await? + 0.05).await?
- }
- _ => {}
- }
-
- Ok(())
- }
-}