feat: handling of notifications events
This commit is contained in:
parent
060b316365
commit
68dec69d4c
2 changed files with 26 additions and 13 deletions
|
|
@ -7,6 +7,7 @@ use cosmic::iced::{
|
|||
window, Alignment, Application, Color, Command, Length, Subscription,
|
||||
};
|
||||
use cosmic::iced_core::image;
|
||||
use cosmic::iced_futures::subscription;
|
||||
use cosmic::iced_widget::button::StyleSheet;
|
||||
use cosmic_applet::{applet_button_theme, CosmicAppletHelper};
|
||||
|
||||
|
|
@ -191,7 +192,19 @@ impl Application for Notifications {
|
|||
Command::none()
|
||||
}
|
||||
Message::NotificationEvent(e) => {
|
||||
dbg!(e);
|
||||
match e {
|
||||
AppletEvent::Notification(n) => {
|
||||
self.notifications.push(n);
|
||||
}
|
||||
AppletEvent::Replace(n) => {
|
||||
if let Some(old) = self.notifications.iter_mut().find(|n| n.id == n.id) {
|
||||
*old = n;
|
||||
}
|
||||
}
|
||||
AppletEvent::Closed(id) => {
|
||||
self.notifications.retain(|n| n.id != id);
|
||||
}
|
||||
}
|
||||
Command::none()
|
||||
}
|
||||
Message::Ignore => Command::none(),
|
||||
|
|
|
|||
|
|
@ -117,21 +117,21 @@ pub fn notifications() -> Subscription<AppletEvent> {
|
|||
}
|
||||
State::WaitingForNotificationEvent(stream) => {
|
||||
info!("Waiting for notification event");
|
||||
let mut reader = BufReader::new(stream);
|
||||
let reader = BufReader::new(stream);
|
||||
// todo read messages
|
||||
let mut request_buf = String::with_capacity(1024);
|
||||
if let Err(err) = reader.read_line(&mut request_buf).await {
|
||||
error!("Failed to read line from stream {}", err);
|
||||
continue;
|
||||
}
|
||||
let Ok(event) = ron::de::from_str::<AppletEvent>(request_buf.as_str()) else {
|
||||
error!("Failed to deserialize event from notification stream");
|
||||
continue;
|
||||
};
|
||||
|
||||
if let Err(err) = output.send(event).await {
|
||||
error!("Error sending event: {}", err);
|
||||
let mut lines = reader.lines();
|
||||
while let Ok(Some(line)) = lines.next_line().await {
|
||||
if let Ok(event) = ron::de::from_str::<AppletEvent>(line.as_str()) {
|
||||
if let Err(_err) = output.send(event).await {
|
||||
error!("Error sending event");
|
||||
}
|
||||
} else {
|
||||
error!("Failed to deserialize event from notification stream");
|
||||
}
|
||||
}
|
||||
warn!("Notification stream closed");
|
||||
state = State::Finished;
|
||||
}
|
||||
State::Finished => {
|
||||
let () = futures::future::pending().await;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue