diff --git a/src/mpris/player.rs b/src/mpris/player.rs index e830936..8b158e0 100644 --- a/src/mpris/player.rs +++ b/src/mpris/player.rs @@ -222,6 +222,16 @@ impl Player { */ } + pub async fn on_playlist_count_changed( + &self, + emitter: &SignalEmitter<'_>, + ) -> Result<(), zbus::fdo::Error> { + self.can_go_next_changed(emitter).await?; + self.can_go_previous_changed(emitter).await?; + self.can_play_changed(emitter).await?; + Ok(()) + } + fn window(&self) -> Window { self.window.upgrade().unwrap() } @@ -370,17 +380,17 @@ impl Player { #[zbus(property)] fn can_go_next(&self) -> bool { - true // TODO + self.window().playlist_count() > 0 } #[zbus(property)] fn can_go_previous(&self) -> bool { - true // TODO + self.window().playlist_count() > 0 } #[zbus(property)] fn can_play(&self) -> bool { - true // TODO + self.window().playlist_count() > 0 } #[zbus(property)] diff --git a/src/ui/window.rs b/src/ui/window.rs index cadce24..6a9477a 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -597,6 +597,18 @@ mod imp { 6 => { assert_eq!(event.name, "playlist-count"); self.obj().notify("playlist-count"); + + // mpris can-go-next depends on this + if let Some(iface_ref) = self.mpris_player() { + glib::spawn_future_local(async move { + iface_ref + .get() + .await + .on_playlist_count_changed(iface_ref.signal_emitter()) + .await + .unwrap(); + }); + } } 7 => {