notify mpris on playback status change
This commit is contained in:
parent
4c90d0f10e
commit
eab11095c8
1 changed files with 40 additions and 15 deletions
|
@ -407,6 +407,26 @@ mod imp {
|
|||
self.setup.present(Some(self.obj().as_ref()));
|
||||
}
|
||||
|
||||
fn mpris_player(&self) -> Option<InterfaceRef<mpris::Player>> {
|
||||
let borrowed = self.mpris_player.borrow();
|
||||
borrowed.as_ref().cloned()
|
||||
}
|
||||
|
||||
fn mpris_player_playback_status_changed(&self) {
|
||||
if let Some(iface_ref) = self.mpris_player() {
|
||||
glib::spawn_future_local(async move {
|
||||
let iface = iface_ref.get().await;
|
||||
match iface.playback_status_changed(iface_ref.signal_emitter()).await {
|
||||
Ok(()) => {}
|
||||
Err(err) => event!(
|
||||
Level::ERROR,
|
||||
"could not notify new playback status through mpris interface: {err}"
|
||||
),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn volume(&self) -> i64 {
|
||||
self.mpv.get_property("volume").unwrap()
|
||||
}
|
||||
|
@ -414,21 +434,18 @@ mod imp {
|
|||
fn set_volume(&self, volume: i64) {
|
||||
self.mpv.set_property("volume", volume).unwrap();
|
||||
|
||||
let iface_borrowed = self.mpris_player.borrow();
|
||||
let iface_ref = match iface_borrowed.as_ref() {
|
||||
None => return, // zbus not set up yet
|
||||
Some(iface_ref) => iface_ref.clone(),
|
||||
};
|
||||
glib::spawn_future_local(async move {
|
||||
let iface = iface_ref.get().await;
|
||||
match iface.volume_changed(iface_ref.signal_emitter()).await {
|
||||
Ok(()) => {}
|
||||
Err(err) => event!(
|
||||
Level::ERROR,
|
||||
"could not notify new volume through mpris interface: {err}"
|
||||
),
|
||||
}
|
||||
});
|
||||
if let Some(iface_ref) = self.mpris_player() {
|
||||
glib::spawn_future_local(async move {
|
||||
let iface = iface_ref.get().await;
|
||||
match iface.volume_changed(iface_ref.signal_emitter()).await {
|
||||
Ok(()) => {}
|
||||
Err(err) => event!(
|
||||
Level::ERROR,
|
||||
"could not notify new volume through mpris interface: {err}"
|
||||
),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn mute(&self) -> bool {
|
||||
|
@ -445,6 +462,10 @@ mod imp {
|
|||
|
||||
fn set_pause(&self, pause: bool) {
|
||||
self.mpv.set_property("pause", pause).unwrap();
|
||||
|
||||
if !self.idle_active() {
|
||||
self.mpris_player_playback_status_changed();
|
||||
}
|
||||
}
|
||||
|
||||
fn time_pos(&self) -> f64 {
|
||||
|
@ -641,6 +662,8 @@ mod imp {
|
|||
|
||||
self.obj().set_playing_cover_art(None::<gdk::Texture>);
|
||||
self.obj().set_background(None::<gdk::Texture>);
|
||||
|
||||
self.mpris_player_playback_status_changed();
|
||||
}
|
||||
|
||||
fn on_start_file(&self) {
|
||||
|
@ -668,6 +691,8 @@ mod imp {
|
|||
event!(target: "audrey::playback", Level::DEBUG, "duration is now {duration} (from subsonic)");
|
||||
self.obj().notify("duration");
|
||||
|
||||
self.mpris_player_playback_status_changed();
|
||||
|
||||
let window = self.obj().clone();
|
||||
let song_id = window.song().unwrap().id();
|
||||
if let Some(handle) = self
|
||||
|
|
Loading…
Reference in a new issue