From 274d0015007ee988ea413e55b9b13c5a5b34ebaf Mon Sep 17 00:00:00 2001 From: Paul Fariello Date: Tue, 30 Sep 2025 08:50:21 +0200 Subject: [PATCH] feat(mpris): Add support for desktop entry --- src/main.rs | 2 +- src/mpris_event_handler.rs | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9c1c794c..81ffb358 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2021,7 +2021,7 @@ async fn main() { } #[cfg(feature = "with-mpris")] - let mpris = MprisEventHandler::spawn(player.clone(), &setup.connect_config.name) + let mpris = MprisEventHandler::spawn(player.clone(), &setup.connect_config.name, None) .await .unwrap_or_else(|e| { error!("could not initialize MPRIS: {e}"); diff --git a/src/mpris_event_handler.rs b/src/mpris_event_handler.rs index b3d50af9..76731b2e 100644 --- a/src/mpris_event_handler.rs +++ b/src/mpris_event_handler.rs @@ -153,6 +153,7 @@ type TimeInUs = i64; struct MprisService { identity: String, + desktop_entry: Option, } #[zbus::interface(name = "org.mpris.MediaPlayer2")] @@ -277,7 +278,7 @@ impl MprisService { debug!("org.mpris.MediaPlayer2::DesktopEntry"); // FIXME: The spec doesn't say anything about the case when there is no .desktop. // Is there any convention? Any value that common clients handle in a sane way? - "".to_owned() + self.desktop_entry.clone().unwrap_or_default() } // The URI schemes supported by the media player. @@ -1123,9 +1124,14 @@ pub struct MprisEventHandler { } impl MprisEventHandler { - fn connection_builder<'a>(identity: &str, name: &str) -> zbus::Result> { + fn connection_builder<'a>( + identity: &str, + name: &str, + desktop_entry: Option<&str>, + ) -> zbus::Result> { let mpris_service = MprisService { identity: identity.to_string(), + desktop_entry: desktop_entry.map(|desktop_entry| desktop_entry.to_string()), }; let mpris_player_service = MprisPlayerService { spirc: None, @@ -1145,19 +1151,26 @@ impl MprisEventHandler { .serve_at("/org/mpris/MediaPlayer2", mpris_player_service) } - pub async fn spawn(player: Arc, name: &str) -> Result { + pub async fn spawn( + player: Arc, + name: &str, + desktop_entry: Option<&str>, + ) -> Result { let (cmd_tx, cmd_rx) = mpsc::unbounded_channel(); - let connection = Self::connection_builder(name, "org.mpris.MediaPlayer2.librespot")? - .build() - .await; + let connection = + Self::connection_builder(name, "org.mpris.MediaPlayer2.librespot", desktop_entry)? + .build() + .await; let connection = match connection { Err(zbus::Error::NameTaken) => { let pid_name = format!("org.mpris.MediaPlayer2.librespot.instance{}", process::id()); warn!("zbus name taken, trying with pid specific name: {pid_name}"); - Self::connection_builder(name, &pid_name)?.build().await + Self::connection_builder(name, &pid_name, desktop_entry)? + .build() + .await } _ => connection, }?;