1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-04-19 19:34:24 +02:00

fix: add explicit failure message for DBus property downcasting

This commit is contained in:
Reinout Meliesie 2024-03-31 22:45:24 +02:00
parent 68ca8da302
commit c41d37ca38
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6

View file

@ -56,9 +56,9 @@ impl Module<gtk::Box> for NetworkManagerModule {
spawn(async move { spawn(async move {
/* TODO: This should be moved into a client à la the upower module, however that /* TODO: This should be moved into a client à la the upower module, however that
requires additional refactoring as both would request a PropertyProxy but on requires additional refactoring as both would request a PropertyProxy but on
different buses. The proper solution will be to rewrite both to use trait-derived different buses. The proper solution will be to rewrite both to use trait-derived
proxies. */ proxies. */
let nm_proxy = { let nm_proxy = {
let dbus = zbus::Connection::system().await?; let dbus = zbus::Connection::system().await?;
PropertiesProxy::builder(&dbus) PropertiesProxy::builder(&dbus)
@ -133,12 +133,12 @@ async fn get_network_state(
let primary_connection_path = properties["PrimaryConnection"] let primary_connection_path = properties["PrimaryConnection"]
.downcast_ref::<ObjectPath>() .downcast_ref::<ObjectPath>()
.unwrap(); .expect("PrimaryConnection was not an object path, violation of NetworkManager D-Bus interface");
if primary_connection_path != "/" { if primary_connection_path != "/" {
let primary_connection_type = properties["PrimaryConnectionType"] let primary_connection_type = properties["PrimaryConnectionType"]
.downcast_ref::<str>() .downcast_ref::<str>()
.unwrap() .expect("PrimaryConnectionType was not a string, violation of NetworkManager D-Bus interface")
.to_string(); .to_string();
match primary_connection_type.as_str() { match primary_connection_type.as_str() {
@ -159,7 +159,7 @@ async fn get_network_state(
} else { } else {
let wireless_enabled = *properties["WirelessEnabled"] let wireless_enabled = *properties["WirelessEnabled"]
.downcast_ref::<bool>() .downcast_ref::<bool>()
.unwrap(); .expect("WirelessEnabled was not a boolean, violation of NetworkManager D-Bus interface");
if wireless_enabled { if wireless_enabled {
Ok(NetworkManagerState::WirelessDisconnected) Ok(NetworkManagerState::WirelessDisconnected)
} else { } else {