Fix: update wry, tao, to fix android issues

This commit is contained in:
Jonathan Kelley 2024-03-15 20:12:13 -07:00
parent ef288d02d7
commit f9f902732b
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
9 changed files with 1169 additions and 371 deletions

File diff suppressed because it is too large Load diff

View file

@ -36,10 +36,7 @@ frameworks = ["WebKit"]
anyhow = "1.0.56"
log = "0.4.11"
wry = "0.35.0"
dioxus = { path = "../../packages/dioxus" }
dioxus-desktop = { path = "../../packages/desktop", features = [
"tokio_runtime",
], default-features = false }
dioxus = { path = "../../packages/dioxus", features = ["mobile"]}
[target.'cfg(target_os = "android")'.dependencies]

View file

@ -1,8 +1,9 @@
use anyhow::Result;
use dioxus::desktop::Config;
use dioxus::mobile::Config;
use dioxus::prelude::*;
#[cfg(target_os = "android")]
use wry::android_binding;
use dioxus::mobile::wry::android_binding;
#[cfg(target_os = "android")]
fn init_logging() {
@ -49,17 +50,19 @@ pub fn main() -> Result<()> {
// 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
LaunchBuilder::new().cfg(
// 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()),
);
LaunchBuilder::mobile()
.with_cfg(
// 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()),
)
.launch(app);
Ok(())
}
fn app() -> Element {
let items = cx.use_hook(|| vec![1, 2, 3]);
let mut items = use_signal(|| vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
log::debug!("Hello from the app");
@ -74,10 +77,7 @@ fn app() -> Element {
border: "1px solid black",
button {
onclick: move |_| {
println!("Clicked!");
items.push(items.len());
cx.needs_update_any(ScopeId::ROOT);
println!("Requested update");
},
"Add item"
}

View file

@ -18,7 +18,6 @@ dioxus-html = { workspace = true, features = [
"eval",
] }
dioxus-interpreter-js = { workspace = true, features = ["binary-protocol"] }
dioxus-hot-reload = { workspace = true, optional = true }
dioxus-cli-config = { workspace = true }
generational-box = { workspace = true }
@ -55,6 +54,8 @@ tao = { version = "0.26.1", features = ["rwh_05"] }
global-hotkey = "0.5.0"
rfd = "0.12"
muda = "0.11.3"
# hotreload only works on desktop platforms.... mobile is still wip
dioxus-hot-reload = { workspace = true, optional = true }
[target.'cfg(target_os = "ios")'.dependencies]
objc = "0.2.7"
@ -65,7 +66,7 @@ core-foundation = "0.9.3"
objc = "0.2.7"
[features]
default = ["tokio_runtime", "hot-reload", "wry/objc-exception"]
default = ["tokio_runtime", "wry/objc-exception", "hot-reload"]
tokio_runtime = ["tokio"]
fullscreen = ["wry/fullscreen"]
transparent = ["wry/transparent"]

View file

@ -81,7 +81,12 @@ impl App {
app.set_global_hotkey_handler();
// Allow hotreloading to work - but only in debug mode
#[cfg(all(feature = "hot-reload", debug_assertions))]
#[cfg(all(
feature = "hot-reload",
debug_assertions,
not(target_os = "android"),
not(target_os = "ios")
))]
app.connect_hotreload();
(event_loop, app)
@ -99,7 +104,12 @@ impl App {
self.shared.shortcut_manager.call_handlers(event);
}
#[cfg(all(feature = "hot-reload", debug_assertions))]
#[cfg(all(
feature = "hot-reload",
debug_assertions,
not(target_os = "android"),
not(target_os = "ios")
))]
pub fn connect_hotreload(&self) {
dioxus_hot_reload::connect({
let proxy = self.shared.proxy.clone();
@ -265,7 +275,12 @@ impl App {
view.desktop_context.send_edits();
}
#[cfg(all(feature = "hot-reload", debug_assertions))]
#[cfg(all(
feature = "hot-reload",
debug_assertions,
not(target_os = "android"),
not(target_os = "ios")
))]
pub fn handle_hot_reload_msg(&mut self, msg: dioxus_hot_reload::HotReloadMsg) {
match msg {
dioxus_hot_reload::HotReloadMsg::UpdateTemplate(template) => {

View file

@ -14,7 +14,12 @@ pub enum UserWindowEvent {
Ipc { id: WindowId, msg: IpcMessage },
/// Handle a hotreload event, basically telling us to update our templates
#[cfg(all(feature = "hot-reload", debug_assertions))]
#[cfg(all(
feature = "hot-reload",
debug_assertions,
not(target_os = "android"),
not(target_os = "ios")
))]
HotReloadEvent(dioxus_hot_reload::HotReloadMsg),
/// Create a new window

View file

@ -36,7 +36,12 @@ pub fn launch_virtual_dom_blocking(virtual_dom: VirtualDom, desktop_config: Conf
#[cfg(any(target_os = "windows", target_os = "linux", target_os = "macos"))]
UserWindowEvent::GlobalHotKeyEvent(evnt) => app.handle_global_hotkey(evnt),
#[cfg(all(feature = "hot-reload", debug_assertions))]
#[cfg(all(
feature = "hot-reload",
debug_assertions,
not(target_os = "android"),
not(target_os = "ios")
))]
UserWindowEvent::HotReloadEvent(msg) => app.handle_hot_reload_msg(msg),
UserWindowEvent::Ipc { id, msg } => match msg.method() {

View file

@ -221,6 +221,7 @@ impl WebviewInstance {
}
}
#[allow(unused)]
pub fn kick_stylsheets(&self) {
// run eval in the webview to kick the stylesheets by appending a query string
// we should do something less clunky than this

View file

@ -226,3 +226,10 @@ pub fn launch_desktop(app: fn() -> Element) {
pub fn launch_fullstack(app: fn() -> Element) {
LaunchBuilder::fullstack().launch(app)
}
#[cfg(feature = "mobile")]
#[cfg_attr(docsrs, doc(cfg(feature = "mobile")))]
/// Launch your mobile application without any additional configuration. See [`LaunchBuilder`] for more options.
pub fn launch_mobile(app: fn() -> Element) {
LaunchBuilder::mobile().launch(app)
}