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

refactor(networkmanager): rename DeviceStateChanged event to DeviceChanged

Also add a little TODO about icon order.
This commit is contained in:
Reinout Meliesie 2025-09-02 22:44:14 +02:00
commit 4c516a1c2a
Signed by: zedfrigg
GPG key ID: 3AFCC06481308BC6
3 changed files with 15 additions and 15 deletions

View file

@ -2,10 +2,10 @@ use crate::clients::networkmanager::dbus::{DeviceState, DeviceType};
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum ClientToModuleEvent { pub enum ClientToModuleEvent {
DeviceStateChanged { DeviceChanged {
interface: String, interface: String,
r#type: DeviceType, r#type: DeviceType,
state: DeviceState, new_state: DeviceState,
}, },
DeviceRemoved { DeviceRemoved {
interface: String, interface: String,

View file

@ -118,14 +118,13 @@ async fn handle_received_events(
for device_path in devices_snapshot { for device_path in devices_snapshot {
let device = DeviceDbusProxy::new(&dbus_connection, device_path).await?; let device = DeviceDbusProxy::new(&dbus_connection, device_path).await?;
// TODO: Create DeviceDbusProxy -> DeviceStateChanged function and use it in the watcher as well
let interface = device.interface().await?.to_string(); let interface = device.interface().await?.to_string();
let r#type = device.device_type().await?; let r#type = device.device_type().await?;
let state = device.state().await?; let new_state = device.state().await?;
controller_sender.send(ClientToModuleEvent::DeviceStateChanged { controller_sender.send(ClientToModuleEvent::DeviceChanged {
interface, interface,
r#type, r#type,
state, new_state,
})?; })?;
} }
} }
@ -163,20 +162,20 @@ async fn watch_device_state(
let r#type = device.device_type().await?; let r#type = device.device_type().await?;
// Send an event communicating the initial state // Send an event communicating the initial state
let state = device.state().await?; let new_state = device.state().await?;
controller_sender.send(ClientToModuleEvent::DeviceStateChanged { controller_sender.send(ClientToModuleEvent::DeviceChanged {
interface: interface.to_string(), interface: interface.to_string(),
r#type: r#type.clone(), r#type: r#type.clone(),
state, new_state,
})?; })?;
let mut state_changes = device.receive_state_changed().await; let mut state_changes = device.receive_state_changed().await;
while let Some(state_change) = state_changes.next().await { while let Some(state_change) = state_changes.next().await {
let state = state_change.get().await?; let new_state = state_change.get().await?;
controller_sender.send(ClientToModuleEvent::DeviceStateChanged { controller_sender.send(ClientToModuleEvent::DeviceChanged {
interface: interface.to_string(), interface: interface.to_string(),
r#type: r#type.clone(), r#type: r#type.clone(),
state, new_state,
})?; })?;
} }

View file

@ -89,14 +89,15 @@ async fn handle_update_events(
icon_size: i32, icon_size: i32,
image_provider: Provider, image_provider: Provider,
) -> Result<()> { ) -> Result<()> {
// TODO: Ensure the visible icons are always in the same order
let mut icons = HashMap::<String, Image>::new(); let mut icons = HashMap::<String, Image>::new();
while let Result::Ok(event) = receiver.recv().await { while let Result::Ok(event) = receiver.recv().await {
match event { match event {
ClientToModuleEvent::DeviceStateChanged { ClientToModuleEvent::DeviceChanged {
interface, interface,
r#type, r#type,
state, new_state,
} => { } => {
let icon: &_ = icons.entry(interface).or_insert_with(|| { let icon: &_ = icons.entry(interface).or_insert_with(|| {
let icon = Image::new(); let icon = Image::new();
@ -106,7 +107,7 @@ async fn handle_update_events(
}); });
// TODO: Make this configurable at runtime // TODO: Make this configurable at runtime
let icon_name = get_icon_for_device_state(&r#type, &state); let icon_name = get_icon_for_device_state(&r#type, &new_state);
match icon_name { match icon_name {
Some(icon_name) => { Some(icon_name) => {
image_provider image_provider