Skip to content

Commit

Permalink
fix: prevent MPRIS D-Bus duplicate name
Browse files Browse the repository at this point in the history
Append `instance<pid>` to the MPRIS bus name to prevent two instances
from fighting over the same bus name.
  • Loading branch information
ThomasFrans authored and hrkfdn committed Oct 3, 2023
1 parent edee66a commit b27b067
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/mpris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ impl MprisManager {
player: MprisPlayer,
) -> Result<(), Box<dyn Error + Sync + Send>> {
let conn = ConnectionBuilder::session()?
.name("org.mpris.MediaPlayer2.ncspot")?
.name(instance_bus_name())?
.serve_at("/org/mpris/MediaPlayer2", root)?
.serve_at("/org/mpris/MediaPlayer2", player)?
.build()
Expand Down Expand Up @@ -529,3 +529,13 @@ impl MprisManager {
}
}
}

/// Get the D-Bus bus name for this instance according to the MPRIS specification.
///
/// https://specifications.freedesktop.org/mpris-spec/2.2/#Bus-Name-Policy
pub fn instance_bus_name() -> String {
format!(
"org.mpris.MediaPlayer2.ncspot.instance{}",
std::process::id()
)
}

0 comments on commit b27b067

Please sign in to comment.