diff --git a/src/mpris/player.rs b/src/mpris/player.rs index 62c9ae7..fdb8d3a 100644 --- a/src/mpris/player.rs +++ b/src/mpris/player.rs @@ -153,14 +153,14 @@ impl Player { } )); - playbin.connect_notify_local( - Some("play-queue-length"), + playbin.connect_notify_future_local( + "play-queue-length", glib::clone!( #[strong] player_ref, move |_, _| { let player_ref = player_ref.clone(); - glib::spawn_future_local(async move { + async move { let player = player_ref.get_mut().await; // properties that depend on the play queue length player @@ -175,44 +175,44 @@ impl Player { .can_play_changed(player_ref.signal_emitter()) .await .unwrap(); - }); + } } ), ); - playbin.connect_notify_local( - Some("state"), + playbin.connect_notify_future_local( + "state", glib::clone!( #[strong] player_ref, move |_, _| { let player_ref = player_ref.clone(); - glib::spawn_future_local(async move { + async move { let player = player_ref.get_mut().await; // properties that depend on the playbin state player .playback_status_changed(player_ref.signal_emitter()) .await .unwrap(); - }); + } } ), ); - playbin.connect_notify_local( - Some("volume"), + playbin.connect_notify_future_local( + "volume", glib::clone!( #[strong] player_ref, move |_, _| { let player_ref = player_ref.clone(); - glib::spawn_future_local(async move { + async move { let player = player_ref.get_mut().await; player .volume_changed(player_ref.signal_emitter()) .await .unwrap(); - }); + } } ), ); diff --git a/src/playbin.rs b/src/playbin.rs index 6d6ce73..7ea2f26 100644 --- a/src/playbin.rs +++ b/src/playbin.rs @@ -153,4 +153,18 @@ impl Playbin { glib::closure_local!(|playbin, position| f(playbin, position)), ) } + + // FIXME: this would be useful in other places, probably + pub fn connect_notify_future_local< + F: Fn(&Self, &glib::ParamSpec) -> U + 'static, + U: std::future::Future + 'static, + >( + &self, + name: &str, + f: F, + ) { + self.connect_notify_local(Some(name), move |self_, param_spec| { + glib::spawn_future_local(f(self_, param_spec)); + }); + } }