waker.rs 970 B

1234567891011121314151617181920212223242526
  1. use crate::desktop_context::UserWindowEvent;
  2. use futures_util::task::ArcWake;
  3. use std::sync::Arc;
  4. use wry::application::event_loop::EventLoopProxy;
  5. /// Create a waker that will send a poll event to the event loop.
  6. ///
  7. /// This lets the VirtualDom "come up for air" and process events while the main thread is blocked by the WebView.
  8. ///
  9. /// All other IO lives in the Tokio runtime,
  10. pub fn tao_waker(proxy: &EventLoopProxy<UserWindowEvent>) -> std::task::Waker {
  11. struct DomHandle(EventLoopProxy<UserWindowEvent>);
  12. // this should be implemented by most platforms, but ios is missing this until
  13. // https://github.com/tauri-apps/wry/issues/830 is resolved
  14. unsafe impl Send for DomHandle {}
  15. unsafe impl Sync for DomHandle {}
  16. impl ArcWake for DomHandle {
  17. fn wake_by_ref(arc_self: &Arc<Self>) {
  18. _ = arc_self.0.send_event(UserWindowEvent::Poll);
  19. }
  20. }
  21. futures_util::task::waker(Arc::new(DomHandle(proxy.clone())))
  22. }