StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use crate::notification::NotificationSendError; |
| 2 | use crate::windowing::winit::app::CustomEvent; |
| 3 | use crate::windowing::winit::notifications::NotificationInfo; |
| 4 | use crate::WindowId; |
| 5 | use futures::FutureExt; |
| 6 | use winit::event_loop::EventLoopProxy; |
| 7 | |
| 8 | pub(super) async fn send_notification( |
| 9 | notification_info: NotificationInfo, |
| 10 | _window_id: WindowId, |
| 11 | proxy: EventLoopProxy<CustomEvent>, |
| 12 | ) { |
| 13 | let NotificationInfo { |
| 14 | notification_content, |
| 15 | on_error, |
| 16 | } = notification_info; |
| 17 | |
| 18 | let mut notification = notify_rust::Notification::new(); |
| 19 | notification |
| 20 | .summary(notification_content.title()) |
| 21 | .body(notification_content.body()); |
| 22 | |
| 23 | notification |
| 24 | .show_async() |
| 25 | .then(|handle| async move { |
| 26 | match handle { |
| 27 | Ok(handle) => { |
| 28 | // The call to on_close blocks until the notification is closed, so make the blocking |
| 29 | // call on its own thread in the `blocking` crate threadpool to avoid starving the shared |
| 30 | // background executor. |
| 31 | blocking::unblock(move || { |
| 32 | // Without the on_close handler, the notification will fail to appear. |
| 33 | handle.on_close(|reason| log::info!("Notification closed via {reason:?}")) |
| 34 | }) |
| 35 | .await; |
| 36 | } |
| 37 | Err(err) => { |
| 38 | // Always consider the error to be a `NotificationSendError::Other`. |
| 39 | // Dbus does not report if a notification couldn't be shown because |
| 40 | // the application didn't have permissions, so we can never return a |
| 41 | // `NotificationSendError::PermissionDenied` error. |
| 42 | let error = NotificationSendError::Other { |
| 43 | error_message: err.to_string(), |
| 44 | }; |
| 45 | |
| 46 | let _ = proxy.send_event(CustomEvent::UpdateUIApp(Box::new(|ctx| { |
| 47 | on_error(error, ctx); |
| 48 | }))); |
| 49 | } |
| 50 | } |
| 51 | }) |
| 52 | .await |
| 53 | } |
| 54 |