From 17d3c6469ec07ed9c6abb1c093bf090f6188a9cf Mon Sep 17 00:00:00 2001 From: Skye Date: Sat, 16 Dec 2023 17:25:51 -0500 Subject: [PATCH] Deduplicate network_manager body --- src/tiles/network_manager.rs | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/src/tiles/network_manager.rs b/src/tiles/network_manager.rs index fbc6dae..6cf5dad 100644 --- a/src/tiles/network_manager.rs +++ b/src/tiles/network_manager.rs @@ -14,30 +14,15 @@ pub async fn network_manager( _output: OutputChannel, dbus_conn: Arc, ) -> eyre::Result { - let root_proxy = Proxy::new( - "org.freedesktop.NetworkManager", - "/org/freedesktop/NetworkManager", - Duration::from_secs(5), - dbus_conn.as_ref(), - ); - let primary_connection = root_proxy.primary_connection().await?; - let primary_connection_proxy = Proxy::new( - "org.freedesktop.NetworkManager", - primary_connection, - Duration::from_secs(5), - dbus_conn.as_ref(), - ); + let destination = "org.freedesktop.NetworkManager"; + let timeout = Duration::from_secs(5); + let connection = dbus_conn.as_ref(); + let make_proxy = |path| Proxy::new(destination, path, timeout, connection); - let specific_object = primary_connection_proxy.specific_object().await?; - let specific_object_proxy = Proxy::new( - "org.freedesktop.NetworkManager", - specific_object, - Duration::from_secs(5), - dbus_conn.as_ref(), - ); - - let ssid = specific_object_proxy.ssid().await?; + let primary_connection = make_proxy("/org/freedesktop/NetworkManager".into()).primary_connection().await?; + let specific_object = make_proxy(primary_connection).specific_object().await?; + let ssid = make_proxy(specific_object).ssid().await?; log::warn!("got ssid: {}", String::from_utf8_lossy(&ssid));