From 5506c568c068d397935925e6b5fc67fe9d268f07 Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Wed, 5 Jul 2023 13:44:24 -0700 Subject: [PATCH] move to newer wry --- examples/ios_demo/Cargo.toml | 6 ++- examples/ios_demo/src/lib.rs | 60 ++++++----------------- examples/ios_demo/src/lib_old.rs | 84 ++++++++++++++++++++++++++++++++ packages/desktop/Cargo.toml | 8 +-- packages/desktop/src/lib.rs | 20 ++++---- packages/hot-reload/Cargo.toml | 2 +- 6 files changed, 119 insertions(+), 61 deletions(-) create mode 100644 examples/ios_demo/src/lib_old.rs diff --git a/examples/ios_demo/Cargo.toml b/examples/ios_demo/Cargo.toml index 76b4fbc6e..1d97fbddb 100644 --- a/examples/ios_demo/Cargo.toml +++ b/examples/ios_demo/Cargo.toml @@ -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" diff --git a/examples/ios_demo/src/lib.rs b/examples/ios_demo/src/lib.rs index bf433beb1..37ce2328b 100644 --- a/examples/ios_demo/src/lib.rs +++ b/examples/ios_demo/src/lib.rs @@ -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 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(()) +} diff --git a/examples/ios_demo/src/lib_old.rs b/examples/ios_demo/src/lib_old.rs new file mode 100644 index 000000000..bf433beb1 --- /dev/null +++ b/examples/ios_demo/src/lib_old.rs @@ -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 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() +} diff --git a/packages/desktop/Cargo.toml b/packages/desktop/Cargo.toml index 59d0df937..f83864afc 100644 --- a/packages/desktop/Cargo.toml +++ b/packages/desktop/Cargo.toml @@ -15,13 +15,13 @@ keywords = ["dom", "ui", "gui", "react"] dioxus-core = { workspace = true, features = ["serialize"] } dioxus-html = { workspace = true, features = ["serialize", "native-bind"] } dioxus-interpreter-js = { workspace = true } -dioxus-hot-reload = { workspace = true, optional = true } +# dioxus-hot-reload = { workspace = true, optional = true } serde = "1.0.136" serde_json = "1.0.79" thiserror = "1.0.30" log = { workspace = true } -wry = { version = "0.27.2" } +wry = { version = "0.28.0" } futures-channel = { workspace = true } tokio = { workspace = true, features = [ "sync", @@ -51,12 +51,12 @@ objc_id = "0.1.1" core-foundation = "0.9.3" [features] -default = ["tokio_runtime", "hot-reload"] +default = ["tokio_runtime"] tokio_runtime = ["tokio"] fullscreen = ["wry/fullscreen"] transparent = ["wry/transparent"] tray = ["wry/tray"] -hot-reload = ["dioxus-hot-reload"] +# hot-reload = ["dioxus-hot-reload"] [dev-dependencies] dioxus-core-macro = { workspace = true } diff --git a/packages/desktop/src/lib.rs b/packages/desktop/src/lib.rs index a8b0fc3ba..8b3bcf181 100644 --- a/packages/desktop/src/lib.rs +++ b/packages/desktop/src/lib.rs @@ -123,16 +123,16 @@ pub fn launch_with_props(root: Component

, props: P, cfg: Config) let proxy = event_loop.create_proxy(); // Intialize hot reloading if it is enabled - #[cfg(all(feature = "hot-reload", debug_assertions))] - dioxus_hot_reload::connect({ - let proxy = proxy.clone(); - move |template| { - let _ = proxy.send_event(UserWindowEvent( - EventData::HotReloadEvent(template), - unsafe { WindowId::dummy() }, - )); - } - }); + // #[cfg(all(feature = "hot-reload", debug_assertions))] + // dioxus_hot_reload::connect({ + // let proxy = proxy.clone(); + // move |template| { + // let _ = proxy.send_event(UserWindowEvent( + // EventData::HotReloadEvent(template), + // unsafe { WindowId::dummy() }, + // )); + // } + // }); // We start the tokio runtime *on this thread* // Any future we poll later will use this runtime to spawn tasks and for IO diff --git a/packages/hot-reload/Cargo.toml b/packages/hot-reload/Cargo.toml index b53a87809..fd388c8ad 100644 --- a/packages/hot-reload/Cargo.toml +++ b/packages/hot-reload/Cargo.toml @@ -16,7 +16,7 @@ dioxus-rsx = { workspace = true } dioxus-core = { workspace = true, features = ["serialize"] } dioxus-html = { workspace = true, features = ["hot-reload-context"] } -interprocess-docfix = { version = "1.2.1" } +interprocess-docfix = { version = "1.2.2" } notify = "5.0.0" chrono = { version = "0.4.24", default-features = false, features = ["clock"] } serde_json = "1.0.91"