Android build working too

This commit is contained in:
Jonathan Kelley committed 2023-07-05 14:35:08 -07:00
1 parent 5506c568c0
commit ea3b199eb2
10 files changed
+40 -125

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
use anyhow::Result;
#[cfg(target_os = "android")]
use wry::android_binding;
use wry::{
application::{
event::{Event, StartCause, WindowEvent},
event_loop::{ControlFlow, EventLoop, EventLoopWindowTarget},
window::WindowBuilder,
},
http::Response,
webview::{WebView, WebViewBuilder},
};
#[cfg(target_os = "android")]
fn init_logging() {
android_logger::init_once(
android_logger::Config::default()
.with_min_level(log::Level::Trace)
.with_tag("mobile-demo"),
);
}
#[cfg(not(target_os = "android"))]
fn init_logging() {
env_logger::init();
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn stop_unwind<F: FnOnce() -> T, T>(f: F) -> T {
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)) {
Ok(t) => t,
Err(err) => {
eprintln!("attempt to unwind out of `rust` with err: {:?}", err);
std::process::abort()
}
}
}
#[cfg(any(target_os = "android", target_os = "ios"))]
fn _start_app() {
stop_unwind(|| main().unwrap());
}
#[no_mangle]
#[inline(never)]
#[cfg(any(target_os = "android", target_os = "ios"))]
pub extern "C" fn start_app() {
#[cfg(target_os = "android")]
android_binding!(com_example, mobile_demo, _start_app);
#[cfg(target_os = "ios")]
_start_app()
}
pub fn main() -> Result<()> {
init_logging();
use dioxus::prelude::*;
dioxus_desktop::launch(|cx| {
cx.render(rsx! {
"hello world!"
})
});
Ok(())
}