Skip to content

Commit

Permalink
Improved adding new notifications to manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian-Alberts committed Dec 13, 2023
1 parent d7cf15d commit c30b656
Showing 1 changed file with 9 additions and 24 deletions.
33 changes: 9 additions & 24 deletions i3_notify_bar/src/notification_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,31 +101,16 @@ where
debug!("Finished definitions");
debug!("Final notification_data {:#?}", notification_data);

let notification_position = self.notifications.iter().position(|n| match n.read() {
Ok(n) => n.id == notification_data.id,
Err(_) => {
error!("Could not read notification data");
false
}
});
match notification_position {
Some(index) => {
let mut notification_data_storage = match self.notifications[index].write() {
Ok(nds) => nds,
Err(_) => {
error!("Could not lock notifications");
return;
}
};
*notification_data_storage = notification_data;
drop(notification_data_storage);
}
None => {
let notification = Arc::new(RwLock::new(notification_data));
self.notifications.push(Arc::clone(&notification));
self.events.push(NotificationEvent::Add(notification));
}
if let Some(mut n) = self.notifications
.iter_mut()
.filter_map(|n| n.write().ok())
.find(|n| n.id == notification_data.id) {
*n = notification_data;
return
}
let notification = Arc::new(RwLock::new(notification_data));
self.notifications.push(Arc::clone(&notification));
self.events.push(NotificationEvent::Add(notification));
}

pub fn update(&mut self, dt: f64) {
Expand Down

0 comments on commit c30b656

Please sign in to comment.