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, notifications::NotificationInfo}; |
| 3 | use crate::WindowId; |
| 4 | use tauri_winrt_notification::Toast; |
| 5 | use winit::event_loop::EventLoopProxy; |
| 6 | |
| 7 | pub(super) async fn send_notification( |
| 8 | notification_info: NotificationInfo, |
| 9 | window_id: WindowId, |
| 10 | proxy: EventLoopProxy<CustomEvent>, |
| 11 | ) { |
| 12 | let NotificationInfo { |
| 13 | notification_content, |
| 14 | on_error, |
| 15 | } = notification_info; |
| 16 | |
| 17 | let powershell_app_id = Toast::POWERSHELL_APP_ID.to_string(); |
| 18 | let app_id = unsafe { fetch_windows_app_id() } |
| 19 | .ok() |
| 20 | .unwrap_or(powershell_app_id); |
| 21 | let proxy_clone = proxy.clone(); |
| 22 | let toast = Toast::new(&app_id) |
| 23 | .title(notification_content.title()) |
| 24 | .text1(notification_content.body()) |
| 25 | .on_activated(move |_activated_arguments| { |
| 26 | let _ = proxy_clone |
| 27 | .send_event(CustomEvent::FocusWindow { window_id }) |
| 28 | .map_err(|err| { |
| 29 | log::warn!("Unable to focus window after event loop closed: {err:?}"); |
| 30 | }); |
| 31 | Ok(()) |
| 32 | }); |
| 33 | |
| 34 | if let Err(err) = toast.show() { |
| 35 | let error = NotificationSendError::Other { |
| 36 | error_message: err.to_string(), |
| 37 | }; |
| 38 | |
| 39 | let _ = proxy.send_event(CustomEvent::UpdateUIApp(Box::new(|ctx| { |
| 40 | on_error(error, ctx); |
| 41 | }))); |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | unsafe fn fetch_windows_app_id() -> Result<String, anyhow::Error> { |
| 46 | let app_id_pwstr = windows::Win32::UI::Shell::GetCurrentProcessExplicitAppUserModelID() |
| 47 | .map_err(|win_err| { |
| 48 | log::warn!("error retrieving Win32 AppUserModel ID: {win_err:?}"); |
| 49 | anyhow::anyhow!(win_err) |
| 50 | })?; |
| 51 | Ok(app_id_pwstr.to_string()?) |
| 52 | } |
| 53 |