diff --git a/packages/desktop/src/desktop_context.rs b/packages/desktop/src/desktop_context.rs index 09bed730e..cb5a62635 100644 --- a/packages/desktop/src/desktop_context.rs +++ b/packages/desktop/src/desktop_context.rs @@ -1,4 +1,3 @@ -use std::cell::RefCell; use std::rc::Rc; use crate::eval::EvalResult; @@ -42,10 +41,7 @@ pub struct DesktopContext { pub proxy: ProxyType, /// The receiver for eval results since eval is async - pub(super) eval_sender: tokio::sync::mpsc::UnboundedSender, - - /// The receiver for eval results since eval is async - pub(super) eval_reciever: Rc>>, + pub(super) eval: tokio::sync::broadcast::Sender, #[cfg(target_os = "ios")] pub(crate) views: Rc>>, @@ -62,14 +58,10 @@ impl std::ops::Deref for DesktopContext { impl DesktopContext { pub(crate) fn new(webview: Rc, proxy: ProxyType) -> Self { - let (eval_sender, eval_reciever) = tokio::sync::mpsc::unbounded_channel(); - Self { webview, proxy, - eval_reciever: Rc::new(RefCell::new(eval_reciever)), - eval_sender, - + eval: tokio::sync::broadcast::channel(8).0, #[cfg(target_os = "ios")] views: Default::default(), } @@ -156,9 +148,7 @@ impl DesktopContext { log::warn!("Eval script error: {e}"); } - EvalResult { - reciever: self.eval_reciever.clone(), - } + EvalResult::new(self.eval.clone()) } /// Push an objc view to the window diff --git a/packages/desktop/src/eval.rs b/packages/desktop/src/eval.rs index 80baba2d4..7a92bedf5 100644 --- a/packages/desktop/src/eval.rs +++ b/packages/desktop/src/eval.rs @@ -1,4 +1,3 @@ -use std::cell::RefCell; use std::rc::Rc; use crate::use_window; @@ -10,7 +9,13 @@ use std::pin::Pin; /// A future that resolves to the result of a JavaScript evaluation. pub struct EvalResult { - pub(crate) reciever: Rc>>, + pub(crate) broadcast: tokio::sync::broadcast::Sender, +} + +impl EvalResult { + pub(crate) fn new(sender: tokio::sync::broadcast::Sender) -> Self { + Self { broadcast: sender } + } } impl IntoFuture for EvalResult { @@ -20,10 +25,10 @@ impl IntoFuture for EvalResult { fn into_future(self) -> Self::IntoFuture { Box::pin(async move { - let mut reciever = self.reciever.borrow_mut(); + let mut reciever = self.broadcast.subscribe(); match reciever.recv().await { - Some(result) => Ok(result), - None => Err(serde_json::Error::custom("No result returned")), + Ok(result) => Ok(result), + Err(_) => Err(serde_json::Error::custom("No result returned")), } }) as Pin>>> } diff --git a/packages/desktop/src/lib.rs b/packages/desktop/src/lib.rs index 9d10f36f5..e3002f539 100644 --- a/packages/desktop/src/lib.rs +++ b/packages/desktop/src/lib.rs @@ -183,7 +183,7 @@ pub fn launch_with_props(root: Component

, props: P, mut cfg: Conf dom.base_scope() .consume_context::() .unwrap() - .eval_sender + .eval .send(msg.params()) .unwrap(); } diff --git a/packages/html/src/events/drag.rs b/packages/html/src/events/drag.rs index f8ee6ff92..fa3219631 100644 --- a/packages/html/src/events/drag.rs +++ b/packages/html/src/events/drag.rs @@ -9,7 +9,7 @@ pub type DragEvent = Event; /// (such as another DOM element). Applications are free to interpret a drag and drop interaction in an /// application-specific way. #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub struct DragData { /// Inherit mouse data pub mouse: MouseData, diff --git a/packages/html/src/events/mouse.rs b/packages/html/src/events/mouse.rs index f8446b7d1..7899393ff 100644 --- a/packages/html/src/events/mouse.rs +++ b/packages/html/src/events/mouse.rs @@ -10,7 +10,7 @@ pub type MouseEvent = Event; /// A synthetic event that wraps a web-style [`MouseEvent`](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent) #[cfg_attr(feature = "serialize", derive(serde::Serialize, serde::Deserialize))] -#[derive(Clone, Default, PartialEq)] +#[derive(Clone, Default, PartialEq, Eq)] /// Data associated with a mouse event /// /// Do not use the deprecated fields; they may change or become private in the future.