remove some boilerplate
This commit is contained in:
parent
3b3e3166ca
commit
173494c71f
2 changed files with 49 additions and 40 deletions
|
@ -121,13 +121,10 @@ impl Player {
|
|||
.interface::<_, Self>("/org/mpris/MediaPlayer2")
|
||||
.await?;
|
||||
|
||||
playbin.connect_closure(
|
||||
"new-track",
|
||||
false,
|
||||
glib::closure_local!(
|
||||
playbin.connect_new_track(glib::clone!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, song: &crate::playbin::Song| {
|
||||
move |_, song| {
|
||||
let metadata = MetadataMap::from_playbin_song(Some(song));
|
||||
|
||||
let player_ref = player_ref.clone();
|
||||
|
@ -140,16 +137,12 @@ impl Player {
|
|||
.unwrap();
|
||||
});
|
||||
}
|
||||
),
|
||||
);
|
||||
));
|
||||
|
||||
playbin.connect_closure(
|
||||
"seeked",
|
||||
false,
|
||||
glib::closure_local!(
|
||||
playbin.connect_seeked(glib::clone!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, position: f64| {
|
||||
move |_, position| {
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
player_ref
|
||||
|
@ -158,15 +151,14 @@ impl Player {
|
|||
.unwrap();
|
||||
});
|
||||
}
|
||||
),
|
||||
);
|
||||
));
|
||||
|
||||
playbin.connect_notify_local(
|
||||
Some("play-queue-length"),
|
||||
glib::clone!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, _| {
|
||||
move |_, _| {
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let player = player_ref.get_mut().await;
|
||||
|
@ -193,7 +185,7 @@ impl Player {
|
|||
glib::clone!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, _| {
|
||||
move |_, _| {
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let player = player_ref.get_mut().await;
|
||||
|
@ -212,7 +204,7 @@ impl Player {
|
|||
glib::clone!(
|
||||
#[strong]
|
||||
player_ref,
|
||||
move |_playbin: &crate::Playbin, _| {
|
||||
move |_, _| {
|
||||
let player_ref = player_ref.clone();
|
||||
glib::spawn_future_local(async move {
|
||||
let player = player_ref.get_mut().await;
|
||||
|
|
|
@ -49,6 +49,7 @@ pub mod ffi {
|
|||
}
|
||||
}
|
||||
|
||||
use adw::prelude::*;
|
||||
use glib::translate::{from_glib, from_glib_none, IntoGlib, ToGlibPtr};
|
||||
use gtk::{gio, glib};
|
||||
|
||||
|
@ -136,4 +137,20 @@ impl Playbin {
|
|||
pub fn play_queue(&self) -> gio::ListModel {
|
||||
unsafe { from_glib_none(ffi::audrey_playbin_get_play_queue(self.to_glib_none().0)) }
|
||||
}
|
||||
|
||||
pub fn connect_new_track<F: Fn(&Self, &Song) + 'static>(&self, f: F) -> glib::SignalHandlerId {
|
||||
self.connect_closure(
|
||||
"new-track",
|
||||
false,
|
||||
glib::closure_local!(|playbin, song| f(playbin, song)),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn connect_seeked<F: Fn(&Self, f64) + 'static>(&self, f: F) -> glib::SignalHandlerId {
|
||||
self.connect_closure(
|
||||
"seeked",
|
||||
false,
|
||||
glib::closure_local!(|playbin, position| f(playbin, position)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue