From 5d998897287ba8fc6ad61b650fe631e5fb44dc29 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Wed, 30 Oct 2024 11:32:18 -0500 Subject: [PATCH] Fix liveview launch (#3145) --- packages/dioxus/src/launch.rs | 18 ------------------ packages/liveview/src/launch.rs | 11 ++++++++--- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/packages/dioxus/src/launch.rs b/packages/dioxus/src/launch.rs index dee19e183..97e15d90a 100644 --- a/packages/dioxus/src/launch.rs +++ b/packages/dioxus/src/launch.rs @@ -19,24 +19,6 @@ pub type LaunchFn = fn(fn() -> Element, Vec, Vec>); /// A context function is a Send and Sync closure that returns a boxed trait object pub type ContextFn = Box Box + Send + Sync + 'static>; -#[cfg(any( - feature = "fullstack", - feature = "static-generation", - feature = "liveview" -))] -type ValidContext = SendContext; - -#[cfg(not(any( - feature = "fullstack", - feature = "static-generation", - feature = "liveview" -)))] -type ValidContext = UnsendContext; - -type SendContext = dyn Fn() -> Box + Send + Sync + 'static; - -type UnsendContext = dyn Fn() -> Box + 'static; - #[allow(clippy::redundant_closure)] // clippy doesnt doesn't understand our coercion to fn impl LaunchBuilder { /// Create a new builder for your application. This will create a launch configuration for the current platform based on the features enabled on the `dioxus` crate. diff --git a/packages/liveview/src/launch.rs b/packages/liveview/src/launch.rs index 766a7a25f..b51dc3b24 100644 --- a/packages/liveview/src/launch.rs +++ b/packages/liveview/src/launch.rs @@ -6,16 +6,21 @@ pub type Config = crate::Config; /// Launches the WebView and runs the event loop, with configuration and root props. pub fn launch( root: fn() -> Element, - contexts: Vec Box + Send + Sync>>, - platform_config: Config, + contexts: Vec Box + Send + Sync>>, + platform_configs: Vec>, ) -> ! { #[cfg(feature = "multi-thread")] let mut builder = tokio::runtime::Builder::new_multi_thread(); #[cfg(not(feature = "multi-thread"))] let mut builder = tokio::runtime::Builder::new_current_thread(); + let config = platform_configs + .into_iter() + .find_map(|cfg| cfg.downcast::().ok().map(|cfg| *cfg)) + .unwrap_or_default(); + builder.enable_all().build().unwrap().block_on(async move { - platform_config + config .with_virtual_dom(move || { let mut virtual_dom = VirtualDom::new(root);