feat: device hot-reload, tools-relative adb, auto port bind (#3586)

* wip: bind to 0.0.0.0 instead of 127.0.0.1

* dont hang in background - ignore suspend commands when tty is disabled

* use system adb

* pass configs through to android mobile launch

* fix: line sizes + clear pushes frame

* dont resume window state on mobile

* fix screen sizing for ipad

* attempt and fail to implement codesigning

* Clippy and note about safety in android bindings
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2025-01-20 17:42:13 -08:00
1 parent e199e86dad
commit 8334f7fbaa
22 files changed
+620 -212

No files matched your search

+54 -10
View File
@@ -4,18 +4,18 @@
pub use dioxus_desktop::*;
use dioxus_lib::prelude::*;
use std::any::Any;
use std::sync::Mutex;
pub mod launch_bindings {
use std::any::Any;
use super::*;
pub fn launch(
root: fn() -> Element,
_contexts: Vec<Box<dyn Fn() -> Box<dyn Any> + Send + Sync>>,
_platform_config: Vec<Box<dyn Any>>,
contexts: Vec<Box<dyn Fn() -> Box<dyn Any> + Send + Sync>>,
platform_config: Vec<Box<dyn Any>>,
) {
super::launch(root);
super::launch_cfg(root, contexts, platform_config);
}
pub fn launch_virtual_dom(_virtual_dom: VirtualDom, _desktop_config: Config) -> ! {
@@ -24,27 +24,71 @@ pub mod launch_bindings {
}
/// Launch via the binding API
pub fn launch(incoming: fn() -> Element) {
pub fn launch(root: fn() -> Element) {
launch_cfg(root, vec![], vec![]);
}
pub fn launch_cfg(
root: fn() -> Element,
contexts: Vec<Box<dyn Fn() -> Box<dyn Any> + Send + Sync>>,
platform_config: Vec<Box<dyn Any>>,
) {
#[cfg(target_os = "android")]
{
*APP_FN_PTR.lock().unwrap() = Some(incoming);
*APP_OBJECTS.lock().unwrap() = Some(BoundLaunchObjects {
root,
contexts,
platform_config,
});
}
#[cfg(not(target_os = "android"))]
{
dioxus_desktop::launch::launch(incoming, vec![], Default::default());
dioxus_desktop::launch::launch(root, contexts, platform_config);
}
}
static APP_FN_PTR: Mutex<Option<fn() -> Element>> = Mutex::new(None);
/// 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<T> is technically safe
/// to move between threads if you can prove that no other thread is using the Rc<T> at the same time.
/// Crates like https://crates.io/crates/sendable exist that build on this idea but with runtimk,
/// 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<dyn Fn() -> Box<dyn Any> + Send + Sync>>,
platform_config: Vec<Box<dyn Any>>,
}
unsafe impl Send for BoundLaunchObjects {}
unsafe impl Sync for BoundLaunchObjects {}
static APP_OBJECTS: Mutex<Option<BoundLaunchObjects>> = Mutex::new(None);
#[doc(hidden)]
pub fn root() {
let app = APP_FN_PTR
let app = APP_OBJECTS
.lock()
.expect("APP_FN_PTR lock failed")
.take()
.expect("Android to have set the app trampoline");
dioxus_desktop::launch::launch(app, vec![], Default::default());
let BoundLaunchObjects {
root,
contexts,
platform_config,
} = app;
dioxus_desktop::launch::launch(root, contexts, platform_config);
}
/// Expose the `Java_dev_dioxus_main_WryActivity_create` function to the JNI layer.