azalea_core/
dbus.rs

1use zbus::blocking::fdo::DBusProxy;
2
3pub struct DBusWrapper {
4    conn: zbus::blocking::Connection,
5}
6
7impl DBusWrapper {
8    pub fn new() -> Result<Self, zbus::Error> {
9        Ok(Self {
10            conn: zbus::blocking::Connection::session()?,
11        })
12    }
13
14    pub fn name_has_owner(&self, name: &str) -> Result<bool, zbus::Error> {
15        Ok(DBusProxy::new(&self.conn)?.name_has_owner(zbus_names::BusName::try_from(name)?)?)
16    }
17
18    pub fn wait_for_name_owner(&self, name: &str) -> Result<(), zbus::Error> {
19        let mut stream = DBusProxy::new(&self.conn)?.receive_name_owner_changed()?;
20
21        while let Some(message) = stream.next() {
22            if let Ok(args) = message.args() {
23                if let zbus_names::BusName::WellKnown(dbus_name) = args.name {
24                    if dbus_name == name {
25                        break;
26                    }
27                }
28            }
29        }
30
31        Ok(())
32    }
33}