Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 3fdfa008 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

MPRIS: Add an option if we want a unique name (with the pid) or not

parent a18d5035
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -5,13 +5,12 @@ use commons::log; ...@@ -5,13 +5,12 @@ use commons::log;
use smallstring::SmallString; use smallstring::SmallString;
use zbus::{dbus_interface, Connection, ConnectionBuilder, SignalContext as ZSignalCtx}; use zbus::{dbus_interface, Connection, ConnectionBuilder, SignalContext as ZSignalCtx};
pub struct Server { pub struct Server(Connection);
connexion: Connection,
}
pub struct ServerBuilder { pub struct ServerBuilder {
identity: SmallString, identity: SmallString,
desktop_entry: Option<SmallString>, desktop_entry: Option<SmallString>,
is_unique: bool,
} }
impl Server { impl Server {
...@@ -19,6 +18,7 @@ impl Server { ...@@ -19,6 +18,7 @@ impl Server {
ServerBuilder { ServerBuilder {
identity: identity.as_ref().into(), identity: identity.as_ref().into(),
desktop_entry: None, desktop_entry: None,
is_unique: false,
} }
} }
} }
...@@ -29,23 +29,34 @@ impl ServerBuilder { ...@@ -29,23 +29,34 @@ impl ServerBuilder {
self self
} }
pub fn unique(mut self) -> Self {
self.is_unique = true;
self
}
/// Try to build the DBus server. /// Try to build the DBus server.
pub async fn try_build(self) -> zbus::Result<Server> { pub async fn try_build(self) -> zbus::Result<Server> {
let desktop_entry = self.desktop_entry.unwrap_or_else(|| self.identity.clone()); Ok(Server(
let main = Main { ConnectionBuilder::session()?
.name(format!(
"org.mpris.MediaPlayer2.{}{}",
self.identity,
self.is_unique
.then_some(format!("-{}", std::process::id()))
.unwrap_or_default()
))?
.serve_at(
"/org/mpris/MediaPlayer2",
Main {
desktop_entry: self.desktop_entry.unwrap_or_else(|| self.identity.clone()),
identity: self.identity, identity: self.identity,
desktop_entry, },
}; )?
let player = Player {}; .serve_at("/org/mpris/MediaPlayer2", Player {})?
let track_list = TrackList {}; .serve_at("/org/mpris/MediaPlayer2", TrackList {})?
let connexion = ConnectionBuilder::session()?
.name("org.mpris.MediaPlayer2.mpris")?
.serve_at("/org/mpris/MediaPlayer2", main)?
.serve_at("/org/mpris/MediaPlayer2", player)?
.serve_at("/org/mpris/MediaPlayer2", track_list)?
.build() .build()
.await?; .await?,
Ok(Server { connexion }) ))
} }
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter