diff --git a/applets/cosmic-applet-audio/src/main.rs b/applets/cosmic-applet-audio/src/main.rs index 69fd8c2c..ea0388e9 100644 --- a/applets/cosmic-applet-audio/src/main.rs +++ b/applets/cosmic-applet-audio/src/main.rs @@ -5,6 +5,7 @@ extern crate relm4_macros; mod icons; mod input; +mod now_playing; mod output; mod pa; mod task; @@ -21,6 +22,7 @@ use libpulse_binding::{ context::subscribe::{Facility, InterestMaskSet, Operation}, volume::Volume, }; +use mpris2_zbus::metadata::Metadata; use once_cell::sync::Lazy; use pulsectl::Handler; use tokio::runtime::Runtime; @@ -44,6 +46,7 @@ fn app(application: &Application) { })); let (refresh_output_tx, refresh_output_rx) = MainContext::channel::<()>(PRIORITY_DEFAULT); let (refresh_input_tx, refresh_input_rx) = MainContext::channel::<()>(PRIORITY_DEFAULT); + let (now_playing_tx, now_playing_rx) = MainContext::channel::>(PRIORITY_DEFAULT); handler .context .borrow_mut() @@ -168,5 +171,11 @@ fn app(application: &Application) { Continue(true) }), ); + now_playing_rx.attach( + None, + clone!(@weak playing_apps => @default-return Continue(true), move |all_metadata| { + Continue(true) + }), + ); window.show(); } diff --git a/applets/cosmic-applet-audio/src/now_playing.rs b/applets/cosmic-applet-audio/src/now_playing.rs new file mode 100644 index 00000000..37d79a83 --- /dev/null +++ b/applets/cosmic-applet-audio/src/now_playing.rs @@ -0,0 +1,17 @@ +use gtk4::{glib::Sender, prelude::*, Button, Image, Label, ListBox}; +use mpris2_zbus::{media_player::MediaPlayer, metadata::Metadata}; +use std::time::Duration; +use tokio::time::sleep; +use zbus::Connection; + +pub async fn metadata_update(tx: Sender>) { + let connection = Connection::session() + .await + .expect("failed to connect to zbus"); + loop { + sleep(Duration::from_secs(1)).await; + let media_players = MediaPlayer::new_all(&connection) + .await + .expect("failed to get media players"); + } +}