fix: don't have Rc cycles in DioxusElement or Queries (#3618)

This commit is contained in:
Jonathan Kelley authored and GitHub committed 2025-01-21 14:57:31 -08:00
1 parent d42b1d5146
commit d8850c7666
3 files changed
+26 -20

No files matched your search

+5 -4
View File
@@ -1,4 +1,4 @@
use crate::DesktopContext;
use crate::{DesktopContext, WeakDesktopContext};
use futures_util::{FutureExt, StreamExt};
use generational_box::Owner;
use serde::{de::DeserializeOwned, Deserialize};
@@ -107,7 +107,7 @@ impl QueryEngine {
id: request_id,
receiver: rx,
return_receiver: Some(return_rx),
desktop: context,
desktop: Rc::downgrade(&context),
phantom: std::marker::PhantomData,
}
}
@@ -140,7 +140,7 @@ impl QueryEngine {
}
pub(crate) struct Query<V: DeserializeOwned> {
desktop: DesktopContext,
desktop: WeakDesktopContext,
receiver: futures_channel::mpsc::UnboundedReceiver<Value>,
return_receiver: Option<futures_channel::oneshot::Receiver<Result<Value, String>>>,
pub id: usize,
@@ -161,7 +161,8 @@ impl<V: DeserializeOwned> Query<V> {
let data = message.to_string();
let script = format!(r#"window.getQuery({queue_id}).rustSend({data});"#);
self.desktop
let desktop = self.desktop.upgrade().ok_or(QueryError::Finished)?;
desktop
.webview
.evaluate_script(&script)
.map_err(|e| QueryError::Send(e.to_string()))?;