1
0
Fork 0
mirror of https://github.com/Zedfrigg/ironbar.git synced 2025-09-18 12:46:58 +02:00

fix(networkmanager): remove icons for removed devices

This commit is contained in:
Reinout Meliesie 2025-09-04 14:25:20 +02:00
commit af49acb40b
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
2 changed files with 20 additions and 3 deletions

View file

@ -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);
}
}

View file

@ -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);
}
}
}