1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-08-17 14:51:04 +02:00

fix(upower): avoid panic on client init error

This commit is contained in:
Jake Stanger 2024-08-09 23:16:00 +01:00
parent 9d125353c4
commit 474e1fe364
No known key found for this signature in database
GPG key ID: C51FC8F9CB0BEA61
4 changed files with 25 additions and 24 deletions

View file

@ -164,12 +164,17 @@ impl Clients {
} }
#[cfg(feature = "upower")] #[cfg(feature = "upower")]
pub fn upower(&mut self) -> Arc<zbus::fdo::PropertiesProxy<'static>> { pub fn upower(&mut self) -> ClientResult<zbus::fdo::PropertiesProxy<'static>> {
self.upower let client = match &self.upower {
.get_or_insert_with(|| { Some(client) => client.clone(),
crate::await_sync(async { upower::create_display_proxy().await }) None => {
}) let client = await_sync(async { upower::create_display_proxy().await })?;
.clone() self.upower.replace(client.clone());
client
}
};
Ok(client)
} }
#[cfg(feature = "volume")] #[cfg(feature = "volume")]

View file

@ -1,21 +1,15 @@
use crate::register_client; use crate::clients::ClientResult;
use crate::register_fallible_client;
use std::sync::Arc; use std::sync::Arc;
use upower_dbus::UPowerProxy; use upower_dbus::UPowerProxy;
use zbus::fdo::PropertiesProxy; use zbus::fdo::PropertiesProxy;
pub async fn create_display_proxy() -> Arc<PropertiesProxy<'static>> { pub async fn create_display_proxy() -> ClientResult<PropertiesProxy<'static>> {
let dbus = Box::pin(zbus::Connection::system()) let dbus = Box::pin(zbus::Connection::system()).await?;
.await
.expect("failed to create connection to system bus");
let device_proxy = UPowerProxy::new(&dbus) let device_proxy = UPowerProxy::new(&dbus).await?;
.await
.expect("failed to create upower proxy");
let display_device = device_proxy let display_device = device_proxy.get_display_device().await?;
.get_display_device()
.await
.unwrap_or_else(|_| panic!("failed to get display device for {device_proxy:?}"));
let path = display_device.path().to_owned(); let path = display_device.path().to_owned();
@ -26,10 +20,9 @@ pub async fn create_display_proxy() -> Arc<PropertiesProxy<'static>> {
.expect("failed to set proxy path") .expect("failed to set proxy path")
.cache_properties(zbus::CacheProperties::No) .cache_properties(zbus::CacheProperties::No)
.build() .build()
.await .await?;
.expect("failed to build proxy");
Arc::new(proxy) Ok(Arc::new(proxy))
} }
register_client!(PropertiesProxy<'static>, upower); register_fallible_client!(PropertiesProxy<'static>, upower);

View file

@ -78,7 +78,10 @@ fn run_with_args() {
#[cfg(feature = "schema")] #[cfg(feature = "schema")]
if args.print_schema { if args.print_schema {
let schema = schemars::schema_for!(Config); let schema = schemars::schema_for!(Config);
println!("{}", serde_json::to_string_pretty(&schema).expect("to be serializable")); println!(
"{}",
serde_json::to_string_pretty(&schema).expect("to be serializable")
);
return; return;
} }

View file

@ -73,7 +73,7 @@ impl Module<gtk::Button> for UpowerModule {
) -> Result<()> { ) -> Result<()> {
let tx = context.tx.clone(); let tx = context.tx.clone();
let display_proxy = context.client::<PropertiesProxy>(); let display_proxy = context.try_client::<PropertiesProxy>()?;
spawn(async move { spawn(async move {
let mut prop_changed_stream = display_proxy.receive_properties_changed().await?; let mut prop_changed_stream = display_proxy.receive_properties_changed().await?;