2024-01-07 23:50:10 +00:00
|
|
|
use crate::register_client;
|
2023-03-19 02:16:49 +05:30
|
|
|
use std::sync::Arc;
|
|
|
|
use upower_dbus::UPowerProxy;
|
|
|
|
use zbus::fdo::PropertiesProxy;
|
|
|
|
|
2024-01-07 23:50:10 +00:00
|
|
|
pub async fn create_display_proxy() -> Arc<PropertiesProxy<'static>> {
|
|
|
|
let dbus = Box::pin(zbus::Connection::system())
|
|
|
|
.await
|
|
|
|
.expect("failed to create connection to system bus");
|
2023-03-19 02:16:49 +05:30
|
|
|
|
2024-01-07 23:50:10 +00:00
|
|
|
let device_proxy = UPowerProxy::new(&dbus)
|
|
|
|
.await
|
|
|
|
.expect("failed to create upower proxy");
|
2023-03-19 02:16:49 +05:30
|
|
|
|
2024-01-07 23:50:10 +00:00
|
|
|
let display_device = device_proxy
|
|
|
|
.get_display_device()
|
|
|
|
.await
|
|
|
|
.unwrap_or_else(|_| panic!("failed to get display device for {device_proxy:?}"));
|
2023-03-19 02:16:49 +05:30
|
|
|
|
2024-01-07 23:50:10 +00:00
|
|
|
let path = display_device.path().to_owned();
|
2023-03-19 02:16:49 +05:30
|
|
|
|
2024-01-07 23:50:10 +00:00
|
|
|
let proxy = PropertiesProxy::builder(&dbus)
|
|
|
|
.destination("org.freedesktop.UPower")
|
|
|
|
.expect("failed to set proxy destination address")
|
|
|
|
.path(path)
|
|
|
|
.expect("failed to set proxy path")
|
|
|
|
.cache_properties(zbus::CacheProperties::No)
|
|
|
|
.build()
|
|
|
|
.await
|
|
|
|
.expect("failed to build proxy");
|
2023-03-19 02:16:49 +05:30
|
|
|
|
2024-01-07 23:50:10 +00:00
|
|
|
Arc::new(proxy)
|
2023-03-19 02:16:49 +05:30
|
|
|
}
|
|
|
|
|
2024-01-07 23:50:10 +00:00
|
|
|
register_client!(PropertiesProxy<'static>, upower);
|