diff --git a/packages/cli/src/server/desktop/mod.rs b/packages/cli/src/server/desktop/mod.rs index fe78240b4..361d110c5 100644 --- a/packages/cli/src/server/desktop/mod.rs +++ b/packages/cli/src/server/desktop/mod.rs @@ -210,7 +210,7 @@ fn send_msg(msg: HotReloadMsg, channel: &mut impl std::io::Write) -> bool { } } -fn start_desktop(config: &CrateConfig, skip_assets: bool) -> Result<(Child, BuildResult)> { +fn start_desktop(config: &CrateConfig, skip_assets: bool) -> Result<(RAIIChild, BuildResult)> { // Run the desktop application let result = crate::builder::build_desktop(config, true, skip_assets)?; @@ -223,9 +223,9 @@ fn start_desktop(config: &CrateConfig, skip_assets: bool) -> Result<(Child, Buil file.set_extension("exe"); } let active = "DIOXUS_ACTIVE"; - let child = Command::new(file.to_str().unwrap()) + let child = RAIIChild(Command::new(file.to_str().unwrap()) .env(active, "true") - .spawn()?; + .spawn()?); Ok((child, result)) } @@ -233,7 +233,7 @@ fn start_desktop(config: &CrateConfig, skip_assets: bool) -> Result<(Child, Buil } pub(crate) struct DesktopPlatform { - currently_running_child: Child, + currently_running_child: RAIIChild, skip_assets: bool, } @@ -261,9 +261,16 @@ impl Platform for DesktopPlatform { } fn rebuild(&mut self, config: &CrateConfig) -> Result { - self.currently_running_child.kill()?; let (child, result) = start_desktop(config, self.skip_assets)?; self.currently_running_child = child; Ok(result) } } + +struct RAIIChild(Child); + +impl Drop for RAIIChild { + fn drop(&mut self) { + let _ = self.0.kill(); + } +} \ No newline at end of file diff --git a/packages/web/src/lib.rs b/packages/web/src/lib.rs index 30a2952fa..46858b131 100644 --- a/packages/web/src/lib.rs +++ b/packages/web/src/lib.rs @@ -252,13 +252,6 @@ pub async fn run_with_props(root: fn(Scope) -> Element, root_prop pin_mut!(work); #[cfg(all(feature = "hot_reload", debug_assertions))] - // futures_util::select! { - // _ = work => (None, None), - // new_template = hotreload_rx.next() => { - // (None, new_template) - // } - // evt = rx.next() => - // } match select(work, select(hotreload_rx.next(), rx.next())).await { Either::Left((_, _)) => (None, None), Either::Right((Either::Left((new_template, _)), _)) => (None, new_template),