notification.rs 956 B

1234567891011121314151617181920212223242526272829303132333435
  1. use flowy_notification::entities::SubscribeObject;
  2. use flowy_notification::NotificationSender;
  3. use serde::Serialize;
  4. use tauri::{AppHandle, Event, Manager, Wry};
  5. #[allow(dead_code)]
  6. pub const AF_EVENT: &str = "af-event";
  7. pub const AF_NOTIFICATION: &str = "af-notification";
  8. #[tracing::instrument(level = "trace")]
  9. pub fn on_event(app_handler: AppHandle<Wry>, event: Event) {}
  10. #[allow(dead_code)]
  11. pub fn send_notification<P: Serialize + Clone>(app_handler: AppHandle<Wry>, payload: P) {
  12. app_handler.emit_all(AF_NOTIFICATION, payload).unwrap();
  13. }
  14. pub struct TSNotificationSender {
  15. handler: AppHandle<Wry>,
  16. }
  17. impl TSNotificationSender {
  18. pub fn new(handler: AppHandle<Wry>) -> Self {
  19. Self { handler }
  20. }
  21. }
  22. impl NotificationSender for TSNotificationSender {
  23. fn send_subject(&self, subject: SubscribeObject) -> Result<(), String> {
  24. self
  25. .handler
  26. .emit_all(AF_NOTIFICATION, subject)
  27. .map_err(|e| format!("{:?}", e))
  28. }
  29. }