From af49acb40bb393ecfe1619268c8c3a1b2a61013f Mon Sep 17 00:00:00 2001 From: Reinout Meliesie Date: Thu, 4 Sep 2025 14:25:20 +0200 Subject: [PATCH] fix(networkmanager): remove icons for removed devices --- src/clients/networkmanager/mod.rs | 8 +++++++- src/modules/networkmanager.rs | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/clients/networkmanager/mod.rs b/src/clients/networkmanager/mod.rs index 4ee6a6f..350a68f 100644 --- a/src/clients/networkmanager/mod.rs +++ b/src/clients/networkmanager/mod.rs @@ -113,7 +113,6 @@ impl ClientInner { watchers.insert(added_device_path.clone(), watcher); } - // TODO: Inform module of removed devices let removed_device_paths = device_paths.difference(&new_device_paths); for removed_device_path in removed_device_paths { let watcher = watchers @@ -122,6 +121,13 @@ impl ClientInner { watcher.state_watcher.abort(); watchers.remove(removed_device_path); + // TODO: Replace the identifier sent to modules with the dbus device number (last segment of its path) + let dbus_connection = &self.dbus_connection().await?; + let device = DeviceDbusProxy::new(dbus_connection, removed_device_path).await?; + let interface = device.interface().await?.to_string(); + self.controller_sender + .send(ClientToModuleEvent::DeviceRemoved { interface })?; + debug!("D-bus device watchers for {} stopped", removed_device_path); } } diff --git a/src/modules/networkmanager.rs b/src/modules/networkmanager.rs index 2ee5e9c..34225b7 100644 --- a/src/modules/networkmanager.rs +++ b/src/modules/networkmanager.rs @@ -13,6 +13,7 @@ use gtk::{Image, Orientation}; use serde::Deserialize; use std::collections::HashMap; use tokio::sync::{broadcast, mpsc}; +use tracing::debug; #[derive(Debug, Deserialize, Clone)] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] @@ -99,7 +100,9 @@ async fn handle_update_events( r#type, new_state, } => { - let icon: &_ = icons.entry(interface).or_insert_with(|| { + let icon: &_ = icons.entry(interface.clone()).or_insert_with(|| { + debug!("Adding icon for {}", interface); + let icon = Image::new(); icon.add_class("icon"); container.add(&icon); @@ -120,7 +123,15 @@ async fn handle_update_events( } } } - ClientToModuleEvent::DeviceRemoved { .. } => {} + ClientToModuleEvent::DeviceRemoved { interface } => { + let icon = icons + .get(interface.as_str()) + .expect("The icon for {} was about to be removed but was not present"); + container.remove(icon); + icons.remove(interface.as_str()); + + debug!("Removed icon for {}", interface); + } } }