@@ -153,6 +153,7 @@ type TimeInUs = i64;
153
153
154
154
struct MprisService {
155
155
identity : String ,
156
+ desktop_entry : Option < String > ,
156
157
}
157
158
158
159
#[ zbus:: interface( name = "org.mpris.MediaPlayer2" ) ]
@@ -277,7 +278,7 @@ impl MprisService {
277
278
debug ! ( "org.mpris.MediaPlayer2::DesktopEntry" ) ;
278
279
// FIXME: The spec doesn't say anything about the case when there is no .desktop.
279
280
// Is there any convention? Any value that common clients handle in a sane way?
280
- "" . to_owned ( )
281
+ self . desktop_entry . clone ( ) . unwrap_or_default ( )
281
282
}
282
283
283
284
// The URI schemes supported by the media player.
@@ -1123,9 +1124,14 @@ pub struct MprisEventHandler {
1123
1124
}
1124
1125
1125
1126
impl MprisEventHandler {
1126
- fn connection_builder < ' a > ( identity : & str , name : & str ) -> zbus:: Result < connection:: Builder < ' a > > {
1127
+ fn connection_builder < ' a > (
1128
+ identity : & str ,
1129
+ name : & str ,
1130
+ desktop_entry : Option < & str > ,
1131
+ ) -> zbus:: Result < connection:: Builder < ' a > > {
1127
1132
let mpris_service = MprisService {
1128
1133
identity : identity. to_string ( ) ,
1134
+ desktop_entry : desktop_entry. map ( |desktop_entry| desktop_entry. to_string ( ) ) ,
1129
1135
} ;
1130
1136
let mpris_player_service = MprisPlayerService {
1131
1137
spirc : None ,
@@ -1145,19 +1151,26 @@ impl MprisEventHandler {
1145
1151
. serve_at ( "/org/mpris/MediaPlayer2" , mpris_player_service)
1146
1152
}
1147
1153
1148
- pub async fn spawn ( player : Arc < Player > , name : & str ) -> Result < MprisEventHandler , MprisError > {
1154
+ pub async fn spawn (
1155
+ player : Arc < Player > ,
1156
+ name : & str ,
1157
+ desktop_entry : Option < & str > ,
1158
+ ) -> Result < MprisEventHandler , MprisError > {
1149
1159
let ( cmd_tx, cmd_rx) = mpsc:: unbounded_channel ( ) ;
1150
1160
1151
- let connection = Self :: connection_builder ( name, "org.mpris.MediaPlayer2.librespot" ) ?
1152
- . build ( )
1153
- . await ;
1161
+ let connection =
1162
+ Self :: connection_builder ( name, "org.mpris.MediaPlayer2.librespot" , desktop_entry) ?
1163
+ . build ( )
1164
+ . await ;
1154
1165
let connection = match connection {
1155
1166
Err ( zbus:: Error :: NameTaken ) => {
1156
1167
let pid_name =
1157
1168
format ! ( "org.mpris.MediaPlayer2.librespot.instance{}" , process:: id( ) ) ;
1158
1169
warn ! ( "zbus name taken, trying with pid specific name: {pid_name}" ) ;
1159
1170
1160
- Self :: connection_builder ( name, & pid_name) ?. build ( ) . await
1171
+ Self :: connection_builder ( name, & pid_name, desktop_entry) ?
1172
+ . build ( )
1173
+ . await
1161
1174
}
1162
1175
_ => connection,
1163
1176
} ?;
0 commit comments