#![doc = include_str!("../README.md")]
#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
pub use dioxus_desktop::*;
use dioxus_lib::prelude::*;
use std::any::Any;
use std::sync::Mutex;
pub mod launch_bindings {
use super::*;
pub fn launch(
root: fn() -> Element,
contexts: Vec Box + Send + Sync>>,
platform_config: Vec>,
) {
super::launch_cfg(root, contexts, platform_config);
}
pub fn launch_virtual_dom(_virtual_dom: VirtualDom, _desktop_config: Config) -> ! {
todo!()
}
}
/// Launch via the binding API
pub fn launch(root: fn() -> Element) {
launch_cfg(root, vec![], vec![]);
}
pub fn launch_cfg(
root: fn() -> Element,
contexts: Vec Box + Send + Sync>>,
platform_config: Vec>,
) {
#[cfg(target_os = "android")]
{
*APP_OBJECTS.lock().unwrap() = Some(BoundLaunchObjects {
root,
contexts,
platform_config,
});
}
#[cfg(not(target_os = "android"))]
{
dioxus_desktop::launch::launch(root, contexts, platform_config);
}
}
/// We need to store the root function and contexts in a static so that when the tao bindings call
/// "start_app", that the original function arguments are still around.
///
/// If you look closely, you'll notice that we impl Send for this struct. This would normally be
/// unsound. However, we know that the thread that created these objects ("main()" - see JNI_OnLoad)
/// is finished once `start_app` is called. This is similar to how an `Rc` is technically safe
/// to move between threads if you can prove that no other thread is using the `Rc` at the same time.
/// Crates like exist that build on this idea but with runtime
/// validation that the current thread is the one that created the object.
///
/// Since `main()` completes, the only reader of this data will be `start_app`, so it's okay to
/// impl this as Send/Sync.
///
/// Todo(jon): the visibility of functions in this module is too public. Make sure to hide them before
/// releasing 0.7.
struct BoundLaunchObjects {
root: fn() -> Element,
contexts: Vec Box + Send + Sync>>,
platform_config: Vec>,
}
unsafe impl Send for BoundLaunchObjects {}
unsafe impl Sync for BoundLaunchObjects {}
static APP_OBJECTS: Mutex