StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | //! Module to display system desktop notifications through the winit windowing backend. |
| 2 | |
| 3 | use crate::platform::NotificationInfo; |
| 4 | use crate::platform::{RequestNotificationPermissionsCallback, SendNotificationErrorCallback}; |
| 5 | use crate::windowing::winit::app::CustomEvent; |
| 6 | use crate::{notification, WindowId}; |
| 7 | use winit::event_loop::EventLoopProxy; |
| 8 | |
| 9 | #[cfg_attr(target_os = "linux", path = "linux.rs")] |
| 10 | #[cfg_attr(target_os = "windows", path = "windows.rs")] |
| 11 | #[cfg_attr(target_family = "wasm", path = "wasm.rs")] |
| 12 | mod imp; |
| 13 | |
| 14 | #[cfg(target_family = "wasm")] |
| 15 | pub(super) use imp::request_notification_permissions; |
| 16 | |
| 17 | pub async fn send_notification( |
| 18 | notification_info: NotificationInfo, |
| 19 | window_id: WindowId, |
| 20 | event_loop_proxy: EventLoopProxy<CustomEvent>, |
| 21 | ) { |
| 22 | imp::send_notification(notification_info, window_id, event_loop_proxy).await |
| 23 | } |
| 24 | |
| 25 | pub(super) fn request_desktop_notification_permissions( |
| 26 | on_completion: RequestNotificationPermissionsCallback, |
| 27 | event_loop_proxy: &EventLoopProxy<CustomEvent>, |
| 28 | ) { |
| 29 | let _ = event_loop_proxy.send_event(CustomEvent::RequestNotificationPermissions(Box::new( |
| 30 | |outcome, ctx| on_completion(outcome, ctx), |
| 31 | ))); |
| 32 | } |
| 33 | |
| 34 | pub(super) fn send_desktop_notification( |
| 35 | notification_content: notification::UserNotification, |
| 36 | window_id: WindowId, |
| 37 | on_error: SendNotificationErrorCallback, |
| 38 | event_loop_proxy: &EventLoopProxy<CustomEvent>, |
| 39 | ) { |
| 40 | use crate::platform::NotificationInfo; |
| 41 | |
| 42 | let _ = event_loop_proxy.send_event(CustomEvent::SendNotification { |
| 43 | window_id, |
| 44 | notification_info: NotificationInfo { |
| 45 | notification_content, |
| 46 | on_error, |
| 47 | }, |
| 48 | }); |
| 49 | } |
| 50 |