Quellcode durchsuchen

Fix merge errors

Jonathan Kelley vor 2 Jahren
Ursprung
Commit
6512c153dd

+ 1 - 1
examples/shortcut.rs

@@ -1,5 +1,4 @@
 use dioxus::prelude::*;
-use dioxus_desktop::tao::keyboard::ModifiersState;
 use dioxus_desktop::use_global_shortcut;
 
 fn main() {
@@ -8,6 +7,7 @@ fn main() {
 
 fn app(cx: Scope) -> Element {
     let toggled = use_state(cx, || false);
+
     use_global_shortcut(cx, "ctrl+s", {
         to_owned![toggled];
         move || toggled.modify(|t| !*t)

+ 1 - 0
packages/desktop/src/desktop_context.rs

@@ -72,6 +72,7 @@ pub struct DesktopService {
     pub(crate) views: Rc<RefCell<Vec<*mut objc::runtime::Object>>>,
 }
 
+/// A handle to the [`DesktopService`] that can be passed around.
 pub type DesktopContext = Rc<DesktopService>;
 
 /// A smart pointer to the current window.

+ 6 - 9
packages/desktop/src/element.rs

@@ -1,20 +1,17 @@
-use std::rc::Rc;
-
 use dioxus_core::ElementId;
 use dioxus_html::{geometry::euclid::Rect, MountedResult, RenderedElementBacking};
-use wry::webview::WebView;
 
-use crate::query::QueryEngine;
+use crate::{desktop_context::DesktopContext, query::QueryEngine};
 
 /// A mounted element passed to onmounted events
 pub struct DesktopElement {
     id: ElementId,
-    webview: Rc<WebView>,
+    webview: DesktopContext,
     query: QueryEngine,
 }
 
 impl DesktopElement {
-    pub(crate) fn new(id: ElementId, webview: Rc<WebView>, query: QueryEngine) -> Self {
+    pub(crate) fn new(id: ElementId, webview: DesktopContext, query: QueryEngine) -> Self {
         Self { id, webview, query }
     }
 }
@@ -37,7 +34,7 @@ impl RenderedElementBacking for DesktopElement {
 
         let fut = self
             .query
-            .new_query::<Option<Rect<f64, f64>>>(&script, &self.webview)
+            .new_query::<Option<Rect<f64, f64>>>(&script, &self.webview.webview)
             .resolve();
         Box::pin(async move {
             match fut.await {
@@ -64,7 +61,7 @@ impl RenderedElementBacking for DesktopElement {
 
         let fut = self
             .query
-            .new_query::<bool>(&script, &self.webview)
+            .new_query::<bool>(&script, &self.webview.webview)
             .resolve();
         Box::pin(async move {
             match fut.await {
@@ -90,7 +87,7 @@ impl RenderedElementBacking for DesktopElement {
 
         let fut = self
             .query
-            .new_query::<bool>(&script, &self.webview)
+            .new_query::<bool>(&script, &self.webview.webview)
             .resolve();
 
         Box::pin(async move {

+ 9 - 7
packages/desktop/src/lib.rs

@@ -18,12 +18,11 @@ mod webview;
 
 use crate::query::QueryResult;
 pub use cfg::Config;
+pub use desktop_context::DesktopContext;
 pub use desktop_context::{
     use_window, use_wry_event_handler, DesktopService, WryEventHandler, WryEventHandlerId,
 };
-use desktop_context::{
-    DesktopContext, EventData, UserWindowEvent, WebviewQueue, WindowEventHandlers,
-};
+use desktop_context::{EventData, UserWindowEvent, WebviewQueue, WindowEventHandlers};
 use dioxus_core::*;
 use dioxus_html::MountedData;
 use dioxus_html::{native_bind::NativeFileEngine, FormData, HtmlEvent};
@@ -253,9 +252,11 @@ pub fn launch_with_props<P: 'static>(root: Component<P>, props: P, cfg: Config)
                             .base_scope()
                             .consume_context::<DesktopContext>()
                             .unwrap()
-                            .query;
+                            .query
+                            .clone();
 
-                        let element = DesktopElement::new(element, view.webview.clone(), query);
+                        let element =
+                            DesktopElement::new(element, view.desktop_context.clone(), query);
 
                         Rc::new(MountedData::new(element))
                     } else {
@@ -278,7 +279,8 @@ pub fn launch_with_props<P: 'static>(root: Component<P>, props: P, cfg: Config)
                             .base_scope()
                             .consume_context::<DesktopContext>()
                             .unwrap()
-                            .query;
+                            .query
+                            .clone();
 
                         query.send(result);
                     }
@@ -324,7 +326,7 @@ pub fn launch_with_props<P: 'static>(root: Component<P>, props: P, cfg: Config)
                             view.dom.handle_event(event_name, data, id, event_bubbles);
                         }
 
-                        send_edits(view.dom.render_immediate(), &view.webview);
+                        send_edits(view.dom.render_immediate(), &view.desktop_context.webview);
                     }
                 }