Skip to content

Commit 5036953

Browse files
committed
feat(mpris): serve identity based on configured name
1 parent 34b44bc commit 5036953

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1997,7 +1997,7 @@ async fn main() {
19971997
}
19981998

19991999
#[cfg(feature = "with-mpris")]
2000-
let mpris = MprisEventHandler::spawn(player.clone())
2000+
let mpris = MprisEventHandler::spawn(player.clone(), &setup.connect_config.name)
20012001
.await
20022002
.unwrap_or_else(|e| {
20032003
error!("could not initialize MPRIS: {e}");

src/mpris_event_handler.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ type Volume = f64;
150150
// Time in microseconds.
151151
type TimeInUs = i64;
152152

153-
struct MprisService {}
153+
struct MprisService {
154+
identity: String,
155+
}
154156

155157
#[zbus::interface(name = "org.mpris.MediaPlayer2")]
156158
impl MprisService {
@@ -259,8 +261,7 @@ impl MprisService {
259261
#[zbus(property)]
260262
async fn identity(&self) -> String {
261263
debug!("org.mpris.MediaPlayer2::Identity");
262-
// TOOD: use name from config
263-
"Librespot".to_owned()
264+
self.identity.clone()
264265
}
265266

266267
// The basename of an installed .desktop file which complies with the
@@ -831,10 +832,12 @@ pub struct MprisEventHandler {
831832
}
832833

833834
impl MprisEventHandler {
834-
pub async fn spawn(player: Arc<Player>) -> Result<MprisEventHandler, MprisError> {
835+
pub async fn spawn(player: Arc<Player>, name: &str) -> Result<MprisEventHandler, MprisError> {
835836
let (cmd_tx, cmd_rx) = mpsc::unbounded_channel();
836837

837-
let mpris_service = MprisService {};
838+
let mpris_service = MprisService {
839+
identity: name.to_string(),
840+
};
838841
let mpris_player_service = MprisPlayerService {
839842
spirc: None,
840843
// FIXME: obtain current values from Player

0 commit comments

Comments
 (0)