diff --git a/src/mpris/player.rs b/src/mpris/player.rs index 0c4460d..9488cc2 100644 --- a/src/mpris/player.rs +++ b/src/mpris/player.rs @@ -3,7 +3,7 @@ use adw::prelude::*; use gtk::glib::SendWeakRef; use std::collections::HashMap; use tracing::{event, Level}; -use zbus::object_server::InterfaceRef; +use zbus::object_server::{InterfaceRef, SignalEmitter}; use zbus::zvariant::{ObjectPath, OwnedObjectPath, OwnedValue, Value}; const MICROSECONDS: f64 = 1e6; // in a second @@ -213,24 +213,6 @@ impl Player { } ), ); - - playbin.connect_notify_future_local( - "volume", - glib::clone!( - #[strong] - player_ref, - move |_, _| { - let player_ref = player_ref.clone(); - async move { - let player = player_ref.get_mut().await; - player - .volume_changed(player_ref.signal_emitter()) - .await - .unwrap(); - } - } - ), - ); */ } @@ -297,6 +279,9 @@ impl Player { Err(zbus::fdo::Error::NotSupported("OpenUri".into())) } + #[zbus(signal)] + async fn seeked(emitter: &SignalEmitter<'_>, position: i64) -> zbus::Result<()>; + #[zbus(property)] fn playback_status(&self) -> String { if self.window().idle_active() { diff --git a/src/ui/window.rs b/src/ui/window.rs index 97fe106..ee74943 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -413,6 +413,22 @@ 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}" + ), + } + }); } fn mute(&self) -> bool {