move to newer wry

This commit is contained in:
Jonathan Kelley committed 2023-07-05 13:44:24 -07:00
1 parent 2ce8ded74d
commit 5506c568c0
6 files changed
+119 -61

No files matched your search

+4 -2
View File
@@ -37,8 +37,10 @@ anyhow = "1.0.56"
log = "0.4.11"
im-rc = "15.1.0"
dioxus = { path = "../../packages/dioxus" }
dioxus-desktop = { path = "../../packages/desktop" }
wry = { version = "0.27.2" }
dioxus-desktop = { path = "../../packages/desktop", default-features = false, features = [
"tokio_runtime",
] }
wry = { version = "0.28.0" }
[target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.9.0"
+16 -44
View File
@@ -1,52 +1,13 @@
use anyhow::Result;
use dioxus::prelude::*;
#[cfg(target_os = "android")]
use wry::android_binding;
pub fn main() -> Result<()> {
init_logging();
// Right now we're going through dioxus-desktop but we'd like to go through dioxus-mobile
// That will seed the index.html with some fixes that prevent the page from scrolling/zooming etc
dioxus_desktop::launch_cfg(
app,
// Note that we have to disable the viewport goofiness of the browser.
// Dioxus_mobile should do this for us
Config::default().with_custom_index(include_str!("index.html").to_string()),
);
Ok(())
}
fn app(cx: Scope) -> Element {
let items = use_state(cx, || vec![1, 2, 3]);
render! {
div {
h1 { "Hello, Mobile"}
div { margin_left: "auto", margin_right: "auto", width: "200px", padding: "10px", border: "1px solid black",
button {
onclick: move|_| {
let mut _items = items.make_mut();
let len = _items.len() + 1;
_items.push(len);
},
"Add item"
}
for item in items.iter() {
div { "- {item}" }
}
}
}
}
}
#[cfg(target_os = "android")]
fn init_logging() {
android_logger::init_once(
android_logger::Config::default()
.with_min_level(log::Level::Trace)
.with_tag("rustnl-ios"),
.with_tag("android-taurio"),
);
}
@@ -68,17 +29,28 @@ fn stop_unwind<F: FnOnce() -> T, T>(f: F) -> T {
#[cfg(any(target_os = "android", target_os = "ios"))]
fn _start_app() {
main().unwrap();
stop_unwind(|| main().unwrap());
}
use dioxus_desktop::Config;
#[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, rustnl_ios, _start_app);
android_binding!(com_example, android_taurio, _start_app);
#[cfg(target_os = "ios")]
_start_app()
}
pub fn main() -> Result<()> {
init_logging();
use dioxus::prelude::*;
fn app(cx: Scope) -> Element {
render!("hello dioxus")
}
dioxus_desktop::launch(app);
Ok(())
}
+84
View File
@@ -0,0 +1,84 @@
use anyhow::Result;
use dioxus::prelude::*;
#[cfg(target_os = "android")]
use wry::android_binding;
pub fn main() -> Result<()> {
init_logging();
// Right now we're going through dioxus-desktop but we'd like to go through dioxus-mobile
// That will seed the index.html with some fixes that prevent the page from scrolling/zooming etc
dioxus_desktop::launch_cfg(
app,
// Note that we have to disable the viewport goofiness of the browser.
// Dioxus_mobile should do this for us
Config::default().with_custom_index(include_str!("index.html").to_string()),
);
Ok(())
}
fn app(cx: Scope) -> Element {
let items = use_state(cx, || vec![1, 2, 3]);
render! {
div {
h1 { "Hello, Mobile"}
div { margin_left: "auto", margin_right: "auto", width: "200px", padding: "10px", border: "1px solid black",
button {
onclick: move|_| {
let mut _items = items.make_mut();
let len = _items.len() + 1;
_items.push(len);
},
"Add item"
}
for item in items.iter() {
div { "- {item}" }
}
}
}
}
}
#[cfg(target_os = "android")]
fn init_logging() {
android_logger::init_once(
android_logger::Config::default()
.with_min_level(log::Level::Trace)
.with_tag("rustnl-ios"),
);
}
#[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() {
main().unwrap();
}
use dioxus_desktop::Config;
#[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, rustnl_ios, _start_app);
#[cfg(target_os = "ios")]
_start_app()
}