Răsfoiți Sursa

fix conditional compilation for hot reloading

Evan Almloff 2 ani în urmă
părinte
comite
773a87d701

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

@@ -9,6 +9,7 @@ use crate::Config;
 use crate::WebviewHandler;
 use dioxus_core::ScopeState;
 use dioxus_core::VirtualDom;
+#[cfg(all(feature = "hot-reload", debug_assertions))]
 use dioxus_hot_reload::HotReloadMsg;
 use serde_json::Value;
 use slab::Slab;
@@ -285,6 +286,7 @@ pub enum EventData {
 
     Ipc(IpcMessage),
 
+    #[cfg(all(feature = "hot-reload", debug_assertions))]
     HotReloadEvent(HotReloadMsg),
 
     NewWindow,

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

@@ -185,6 +185,7 @@ pub fn launch_with_props<P: 'static>(root: Component<P>, props: P, cfg: Config)
             }
 
             Event::UserEvent(event) => match event.0 {
+                #[cfg(all(feature = "hot-reload", debug_assertions))]
                 EventData::HotReloadEvent(msg) => match msg {
                     dioxus_hot_reload::HotReloadMsg::UpdateTemplate(template) => {
                         for webview in webviews.values_mut() {

+ 11 - 10
packages/liveview/src/pool.rs

@@ -134,7 +134,7 @@ where
         #[cfg(all(feature = "hot-reload", debug_assertions))]
         let hot_reload_wait = hot_reload_rx.recv();
         #[cfg(not(all(feature = "hot-reload", debug_assertions)))]
-        let hot_reload_wait = std::future::pending();
+        let hot_reload_wait: std::future::Pending<Option<()>> = std::future::pending();
 
         tokio::select! {
             // poll any futures or suspense
@@ -157,17 +157,18 @@ where
                 }
             }
 
-            msg = hot_reload_wait => {
-                if let Some(msg) = msg {
-                    match msg{
-                        dioxus_hot_reload::HotReloadMsg::UpdateTemplate(new_template) => {
-                            vdom.replace_template(new_template);
-                        }
-                        dioxus_hot_reload::HotReloadMsg::Shutdown => {
-                            std::process::exit(0);
-                        },
+            Some(msg) = hot_reload_wait => {
+                #[cfg(all(feature = "hot-reload", debug_assertions))]
+                match msg{
+                    dioxus_hot_reload::HotReloadMsg::UpdateTemplate(new_template) => {
+                        vdom.replace_template(new_template);
                     }
+                    dioxus_hot_reload::HotReloadMsg::Shutdown => {
+                        std::process::exit(0);
+                    },
                 }
+                #[cfg(not(all(feature = "hot-reload", debug_assertions)))]
+                let () = msg;
             }
         }
 

+ 11 - 4
packages/tui/src/lib.rs

@@ -22,7 +22,7 @@ use std::{
 use std::{io, time::Duration};
 use taffy::Taffy;
 pub use taffy::{geometry::Point, prelude::*};
-use tokio::{select, sync::mpsc::unbounded_channel};
+use tokio::select;
 use tui::{backend::CrosstermBackend, layout::Rect, Terminal};
 
 mod config;
@@ -148,7 +148,7 @@ fn render_vdom(
             #[cfg(all(feature = "hot-reload", debug_assertions))]
             let mut hot_reload_rx = {
                 let (hot_reload_tx, hot_reload_rx) =
-                    unbounded_channel::<dioxus_hot_reload::HotReloadMsg>();
+                    tokio::sync::mpsc::unbounded_channel::<dioxus_hot_reload::HotReloadMsg>();
                 dioxus_hot_reload::connect(move |msg| {
                     let _ = hot_reload_tx.send(msg);
                 });
@@ -233,13 +233,14 @@ fn render_vdom(
                     }
                 }
 
+                #[cfg(all(feature = "hot-reload", debug_assertions))]
                 let mut hot_reload_msg = None;
                 {
                     let wait = vdom.wait_for_work();
                     #[cfg(all(feature = "hot-reload", debug_assertions))]
                     let hot_reload_wait = hot_reload_rx.recv();
                     #[cfg(not(all(feature = "hot-reload", debug_assertions)))]
-                    let hot_reload_wait = std::future::pending();
+                    let hot_reload_wait: std::future::Pending<Option<()>> = std::future::pending();
 
                     pin_mut!(wait);
 
@@ -269,12 +270,18 @@ fn render_vdom(
                             }
                         },
                         Some(msg) = hot_reload_wait => {
-                            hot_reload_msg = Some(msg);
+                            #[cfg(all(feature = "hot-reload", debug_assertions))]
+                            {
+                                hot_reload_msg = Some(msg);
+                            }
+                            #[cfg(not(all(feature = "hot-reload", debug_assertions)))]
+                            let () = msg;
                         }
                     }
                 }
 
                 // if we have a new template, replace the old one
+                #[cfg(all(feature = "hot-reload", debug_assertions))]
                 if let Some(msg) = hot_reload_msg {
                     match msg {
                         dioxus_hot_reload::HotReloadMsg::UpdateTemplate(template) => {