mirror of
https://github.com/Zedfrigg/ironbar.git
synced 2025-09-18 04:36:57 +02:00
fix(networkmanager): notify upon new device from watch_device()
Additionally: - Pass the device proxy to watch_device_state() now that we've had to create one anyway - Improve event received logging in module widget
This commit is contained in:
parent
db88e12b8e
commit
a106f41b0a
2 changed files with 33 additions and 20 deletions
|
@ -109,7 +109,7 @@ impl ClientInner {
|
|||
for added_device_path in added_device_paths {
|
||||
debug_assert!(!watchers.contains_key(added_device_path));
|
||||
|
||||
let watcher = self.watch_device(added_device_path.clone());
|
||||
let watcher = self.watch_device(added_device_path.clone()).await?;
|
||||
watchers.insert(added_device_path.clone(), watcher);
|
||||
}
|
||||
|
||||
|
@ -162,23 +162,15 @@ impl ClientInner {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn watch_device(&'static self, path: ObjectPath<'static>) -> DeviceWatcher {
|
||||
let state_watcher = Arc::new(spawn(self.watch_device_state(path)));
|
||||
|
||||
DeviceWatcher { state_watcher }
|
||||
}
|
||||
|
||||
async fn watch_device_state(&'static self, path: ObjectPath<'_>) -> Result<()> {
|
||||
debug!("D-Bus device state watcher for {} starting", path);
|
||||
|
||||
let dbus_connection = Connection::system().await?;
|
||||
let device = DeviceDbusProxy::new(&dbus_connection, path.clone()).await?;
|
||||
async fn watch_device(&'static self, path: ObjectPath<'_>) -> Result<DeviceWatcher> {
|
||||
let dbus_connection = &self.dbus_connection().await?;
|
||||
let proxy = DeviceDbusProxy::new(dbus_connection, path.to_owned()).await?;
|
||||
|
||||
let number = get_number_from_dbus_path(&path);
|
||||
let r#type = device.device_type().await?;
|
||||
let r#type = proxy.device_type().await?;
|
||||
let new_state = proxy.state().await?;
|
||||
|
||||
// Send an event communicating the initial state
|
||||
let new_state = device.state().await?;
|
||||
// Notify modules that the device exists even if its properties don't change
|
||||
self.controller_sender
|
||||
.send(ClientToModuleEvent::DeviceChanged {
|
||||
number,
|
||||
|
@ -186,9 +178,22 @@ impl ClientInner {
|
|||
new_state,
|
||||
})?;
|
||||
|
||||
let mut state_changes = device.receive_state_changed().await;
|
||||
while let Some(state_change) = state_changes.next().await {
|
||||
let new_state = state_change.get().await?;
|
||||
let state_watcher = Arc::new(spawn(self.watch_device_state(proxy)));
|
||||
|
||||
Ok(DeviceWatcher { state_watcher })
|
||||
}
|
||||
|
||||
async fn watch_device_state(&'static self, proxy: DeviceDbusProxy<'_>) -> Result<()> {
|
||||
let path = proxy.inner().path();
|
||||
|
||||
debug!("D-Bus device state watcher for {} starting", path);
|
||||
|
||||
let number = get_number_from_dbus_path(path);
|
||||
let r#type = proxy.device_type().await?;
|
||||
|
||||
let mut changes = proxy.receive_state_changed().await;
|
||||
while let Some(change) = changes.next().await {
|
||||
let new_state = change.get().await?;
|
||||
self.controller_sender
|
||||
.send(ClientToModuleEvent::DeviceChanged {
|
||||
number,
|
||||
|
|
|
@ -100,6 +100,11 @@ async fn handle_update_events(
|
|||
r#type,
|
||||
new_state,
|
||||
} => {
|
||||
debug!(
|
||||
"Module widget received DeviceChanged event for number {}",
|
||||
number
|
||||
);
|
||||
|
||||
let icon: &_ = icons.entry(number).or_insert_with(|| {
|
||||
debug!("Adding icon for device {}", number);
|
||||
|
||||
|
@ -124,13 +129,16 @@ async fn handle_update_events(
|
|||
}
|
||||
}
|
||||
ClientToModuleEvent::DeviceRemoved { number } => {
|
||||
debug!(
|
||||
"Module widget received DeviceRemoved event for number {}",
|
||||
number
|
||||
);
|
||||
|
||||
let icon = icons
|
||||
.get(&number)
|
||||
.expect("The icon for {} was about to be removed but was not present");
|
||||
container.remove(icon);
|
||||
icons.remove(&number);
|
||||
|
||||
debug!("Removed icon for device {}", number);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue