fix: prevent MPRIS D-Bus duplicate name
Append `instance<pid>` to the MPRIS bus name to prevent two instances from fighting over the same bus name.
This commit is contained in:
committed by
Henrik Friedrichsen
parent
edee66aeed
commit
b27b067a47
12
src/mpris.rs
12
src/mpris.rs
@@ -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()
|
||||
@@ -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()
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user