mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-09-18 04:36:57 +02:00
refactor(networkmanager): rename DeviceStateChanged event to DeviceChanged
Also add a little TODO about icon order.
This commit is contained in:
parent
ec00b2ce69
commit
4c516a1c2a
3 changed files with 15 additions and 15 deletions
|
@ -2,10 +2,10 @@ use crate::clients::networkmanager::dbus::{DeviceState, DeviceType};
|
|||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ClientToModuleEvent {
|
||||
DeviceStateChanged {
|
||||
DeviceChanged {
|
||||
interface: String,
|
||||
r#type: DeviceType,
|
||||
state: DeviceState,
|
||||
new_state: DeviceState,
|
||||
},
|
||||
DeviceRemoved {
|
||||
interface: String,
|
||||
|
|
|
@ -118,14 +118,13 @@ async fn handle_received_events(
|
|||
for device_path in devices_snapshot {
|
||||
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 r#type = device.device_type().await?;
|
||||
let state = device.state().await?;
|
||||
controller_sender.send(ClientToModuleEvent::DeviceStateChanged {
|
||||
let new_state = device.state().await?;
|
||||
controller_sender.send(ClientToModuleEvent::DeviceChanged {
|
||||
interface,
|
||||
r#type,
|
||||
state,
|
||||
new_state,
|
||||
})?;
|
||||
}
|
||||
}
|
||||
|
@ -163,20 +162,20 @@ async fn watch_device_state(
|
|||
let r#type = device.device_type().await?;
|
||||
|
||||
// Send an event communicating the initial state
|
||||
let state = device.state().await?;
|
||||
controller_sender.send(ClientToModuleEvent::DeviceStateChanged {
|
||||
let new_state = device.state().await?;
|
||||
controller_sender.send(ClientToModuleEvent::DeviceChanged {
|
||||
interface: interface.to_string(),
|
||||
r#type: r#type.clone(),
|
||||
state,
|
||||
new_state,
|
||||
})?;
|
||||
|
||||
let mut state_changes = device.receive_state_changed().await;
|
||||
while let Some(state_change) = state_changes.next().await {
|
||||
let state = state_change.get().await?;
|
||||
controller_sender.send(ClientToModuleEvent::DeviceStateChanged {
|
||||
let new_state = state_change.get().await?;
|
||||
controller_sender.send(ClientToModuleEvent::DeviceChanged {
|
||||
interface: interface.to_string(),
|
||||
r#type: r#type.clone(),
|
||||
state,
|
||||
new_state,
|
||||
})?;
|
||||
}
|
||||
|
||||
|
|
|
@ -89,14 +89,15 @@ async fn handle_update_events(
|
|||
icon_size: i32,
|
||||
image_provider: Provider,
|
||||
) -> Result<()> {
|
||||
// TODO: Ensure the visible icons are always in the same order
|
||||
let mut icons = HashMap::<String, Image>::new();
|
||||
|
||||
while let Result::Ok(event) = receiver.recv().await {
|
||||
match event {
|
||||
ClientToModuleEvent::DeviceStateChanged {
|
||||
ClientToModuleEvent::DeviceChanged {
|
||||
interface,
|
||||
r#type,
|
||||
state,
|
||||
new_state,
|
||||
} => {
|
||||
let icon: &_ = icons.entry(interface).or_insert_with(|| {
|
||||
let icon = Image::new();
|
||||
|
@ -106,7 +107,7 @@ async fn handle_update_events(
|
|||
});
|
||||
|
||||
// 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 {
|
||||
Some(icon_name) => {
|
||||
image_provider
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue