Fix liveview launch (#3145)

This commit is contained in:
Evan Almloff authored and GitHub committed 2024-10-30 09:32:18 -07:00
1 parent a35655a457
commit 5d99889728
2 files changed
+8 -21

No files matched your search

-18
View File
@@ -19,24 +19,6 @@ pub type LaunchFn = fn(fn() -> Element, Vec<ContextFn>, Vec<Box<dyn Any>>);
/// A context function is a Send and Sync closure that returns a boxed trait object
pub type ContextFn = Box<dyn Fn() -> Box<dyn Any> + 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<dyn Any + Send + Sync> + Send + Sync + 'static;
type UnsendContext = dyn Fn() -> Box<dyn Any> + '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.
+8 -3
View File
@@ -6,16 +6,21 @@ pub type Config = crate::Config<axum::Router>;
/// Launches the WebView and runs the event loop, with configuration and root props.
pub fn launch(
root: fn() -> Element,
contexts: Vec<Box<dyn Fn() -> Box<dyn Any + Send + Sync> + Send + Sync>>,
platform_config: Config,
contexts: Vec<Box<dyn Fn() -> Box<dyn Any> + Send + Sync>>,
platform_configs: Vec<Box<dyn Any>>,
) -> ! {
#[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::<Config>().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);