launch.rs 843 B

123456789101112131415161718192021222324252627282930
  1. use dioxus_core::*;
  2. use std::any::Any;
  3. pub type Config = crate::Config<axum::Router>;
  4. /// Launches the WebView and runs the event loop, with configuration and root props.
  5. pub fn launch(
  6. root: fn() -> Element,
  7. contexts: Vec<Box<dyn Fn() -> Box<dyn Any> + Send + Sync>>,
  8. platform_config: Config,
  9. ) {
  10. tokio::runtime::Builder::new_multi_thread()
  11. .enable_all()
  12. .build()
  13. .unwrap()
  14. .block_on(async move {
  15. platform_config
  16. .with_virtual_dom(move || {
  17. let mut virtual_dom = VirtualDom::new(root);
  18. for context in &contexts {
  19. virtual_dom.insert_any_root_context(context());
  20. }
  21. virtual_dom
  22. })
  23. .launch()
  24. .await;
  25. });
  26. }