cli json output, dx bundle fix, dx serve --platform android, race condition, drop ssg platform (#3186)

* clean up logging to avoid random extra trace

* fix race condition with updates

* properly wire up verbose

* fix bundling (macos) and logging

* Add structured output

* clean up clap names

* extract out wire format

* switch structured key to json

* fix random println, fallback to `dioxus/platform`

* clean up logging for run/build

* clean up logging around project

* remove manual exits

* fix tokio runtime for mobile

* rework dog app

* rip out ssg

* Switch dioxus/axum to dioxus/server

* add android template inline

* pre restructure for bundle prep

* add the whole res directory

* Better theme for the app

* remove mobile demo now that most apps work natively

* self-referential android

* only use deep linking for assets

* fix imports for android

* clippy, fixup ios and android

* I'm not boxing compiler message you can't make me

* fix clippy on unix
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2024-11-12 09:01:01 -05:00
1 parent 8a998e7d49
commit ac3e33af46
116 files changed
+2367 -6091

No files matched your search

+1 -3
View File
@@ -5,8 +5,6 @@ use async_std::task::sleep;
use dioxus::prelude::*;
use web_time::Instant;
const STYLE: Asset = asset!("/examples/assets/clock.css");
fn main() {
dioxus::launch(app);
}
@@ -36,7 +34,7 @@ fn app() -> Element {
);
rsx! {
document::Link { rel: "stylesheet", href: STYLE }
document::Stylesheet { href: asset!("/examples/assets/clock.css") }
div { id: "app",
div { id: "title", "Carpe diem 🎉" }
div { id: "clock-display", "{time}" }
+9 -11
View File
@@ -39,10 +39,8 @@ fn app() -> Element {
rsx! {
for cur_breed in breeds.message.keys().take(20).cloned() {
li { key: "{cur_breed}",
button { onclick: move |_| breed.set(cur_breed.clone()),
"{cur_breed}"
}
button { onclick: move |_| breed.set(cur_breed.clone()),
"{cur_breed}"
}
}
}
@@ -55,11 +53,9 @@ fn app() -> Element {
};
rsx! {
h1 { "Select a dog breed!" }
div { height: "500px", display: "flex",
ul { width: "100px", {breed_list} }
div { flex: 1, BreedPic { breed } }
}
h1 { "Select a dog breed: {breed}" }
BreedPic { breed }
div { width: "400px", {breed_list} }
}
}
@@ -81,8 +77,10 @@ fn BreedPic(breed: Signal<String>) -> Element {
match fut.read_unchecked().as_ref() {
Some(Ok(resp)) => rsx! {
button { onclick: move |_| fut.restart(), "Click to fetch another doggo" }
img { max_width: "500px", max_height: "500px", src: "{resp.message}" }
div {
button { onclick: move |_| fut.restart(), padding: "5px", background_color: "gray", color: "white", border_radius: "5px", "Click to fetch another doggo" }
img { max_width: "500px", max_height: "500px", src: "{resp.message}" }
}
},
Some(Err(_)) => rsx! { "loading image failed" },
None => rsx! { "loading image..." },
+1 -1
View File
@@ -14,6 +14,6 @@ serde = { version = "1.0.159", features = ["derive"] }
[features]
default = []
server = ["axum", "dioxus/axum"]
server = ["axum", "dioxus/server"]
web = ["dioxus/web"]
+1 -1
View File
@@ -20,5 +20,5 @@ once_cell = "1.19.0"
[features]
default = []
server = ["dioxus/axum", "dep:tokio"]
server = ["dioxus/server", "dep:tokio"]
web = ["dioxus/web"]
-10
View File
@@ -1,10 +0,0 @@
# Rust
target/
**/*.rs.bk
# cargo-mobile2
.cargo/
/gen
# macOS
.DS_Store
-4007
View File
File diff suppressed because it is too large. Load diff
-51
View File
@@ -1,51 +0,0 @@
[package]
name = "mobile-demo"
version = "0.1.0"
authors = ["Jonathan Kelley <jkelleyrtp@gmail.com>"]
edition = "2021"
[lib]
crate-type = ["staticlib", "cdylib", "rlib"]
[[bin]]
name = "mobile-demo-desktop"
path = "gen/bin/desktop.rs"
[package.metadata.cargo-android]
app-activity-name = "com.example.mobile_demo.MainActivity"
app-dependencies = [
"androidx.webkit:webkit:1.6.1",
"androidx.appcompat:appcompat:1.6.1",
"com.google.android.material:material:1.8.0",
]
project-dependencies = ["org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21"]
app-plugins = ["org.jetbrains.kotlin.android"]
app-permissions = ["android.permission.INTERNET"]
app-theme-parent = "Theme.MaterialComponents.DayNight.DarkActionBar"
vulkan-validation = false
[package.metadata.cargo-android.env-vars]
WRY_ANDROID_PACKAGE = "com.example.mobile_demo"
WRY_ANDROID_LIBRARY = "mobile_demo"
WRY_ANDROID_KOTLIN_FILES_OUT_DIR = "<android-project-dir>/app/src/main/kotlin/com/example/mobile_demo"
[package.metadata.cargo-apple.ios]
frameworks = ["WebKit"]
[dependencies]
anyhow = "1.0.56"
log = "0.4.11"
wry = "0.35.0"
dioxus = { path = "../../packages/dioxus", features = ["mobile"]}
[target.'cfg(target_os = "android")'.dependencies]
android_logger = "0.9.0"
jni = "0.19.0"
paste = "1.0"
[target.'cfg(not(target_os = "android"))'.dependencies]
env_logger = "0.9.0"
[target.'cfg(target_os = "ios")'.dependencies]
core-foundation = "0.9.3"
-11
View File
@@ -1,11 +0,0 @@
# Dioxus Mobile demo
## How this project was generated
Right now, Dioxus supports mobile targets including iOS and Android. However, our tooling is not mature enough to include the build commands directly.
This project was generated using [cargo-mobile2](https://github.com/tauri-apps/cargo-mobile2). We have yet to integrate this generation into the Dioxus-CLI. The open issue for this is [#1157](https://github.com/DioxusLabs/dioxus/issues/1157).
## Running this project
Because the tooling and ecosystem is still young, Dioxus mobile can be difficult to setup and run. We have [detailed guides](https://dioxuslabs.com/learn/0.5/getting_started) for creating, building, and running on both iOS and Android.
-8
View File
@@ -1,8 +0,0 @@
[app]
name = "mobile-demo"
stylized-name = "Mobile Demo"
domain = "example.com"
template-pack = "wry"
[apple]
development-team = "34U4FG9TJ8"
-12
View File
@@ -1,12 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Dioxus app</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<!-- CUSTOM HEAD -->
</head>
<body>
<div id="main"></div>
<!-- MODULE LOADER -->
</body>
</html>
-90
View File
@@ -1,90 +0,0 @@
use anyhow::Result;
use dioxus::mobile::Config;
use dioxus::prelude::*;
#[cfg(target_os = "android")]
use dioxus::mobile::wry::android_binding;
#[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();
// 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::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 mut items = use_signal(|| vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9]);
log::debug!("Hello from the app");
rsx! {
div {
h1 { "Hello, Mobile" }
div {
margin_left: "auto",
margin_right: "auto",
width: "200px",
padding: "10px",
border: "1px solid black",
button {
onclick: move |_| {
items.push(items.len());
},
"Add item"
}
for item in items.iter() {
div { "- {item}" }
}
}
}
}
}
-4
View File
@@ -1,4 +0,0 @@
dist
target
docs
.dioxus
-17
View File
@@ -1,17 +0,0 @@
[package]
name = "github-pages-static-generation"
version = "0.1.0"
edition = "2021"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dioxus = { workspace = true, features = ["static-generation", "router"] }
tower = { workspace = true, features = ["util"] }
tracing-subscriber = "0.3.18"
[features]
default = []
server = ["dioxus/axum"]
web = ["dioxus/web"]
-70
View File
@@ -1,70 +0,0 @@
//! You can use the `github_pages` method to set up a preset for github pages.
//! This will output your files in the `/docs` directory and set up a `404.html` file.
#![allow(unused)]
use dioxus::prelude::*;
// Generate all routes and output them to the static path
fn main() {
dioxus::LaunchBuilder::new()
.with_cfg(dioxus::static_site_generation::Config::new().github_pages())
.launch(|| {
rsx! {
Router::<Route> {}
}
});
}
#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
#[route("/")]
Home {},
#[route("/blog")]
Blog,
// You must include a catch all route to handle 404s
#[route("/:..route")]
PageNotFound { route: Vec<String> },
}
#[component]
fn Blog() -> Element {
rsx! {
Link { to: Route::Home {}, "Go to counter" }
table {
tbody {
for _ in 0..100 {
tr {
for _ in 0..100 {
td { "hello world!" }
}
}
}
}
}
}
}
#[component]
fn Home() -> Element {
let mut count = use_signal(|| 0);
rsx! {
Link { to: Route::Blog {}, "Go to blog" }
div {
h1 { "High-Five counter: {count}" }
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
}
}
}
#[component]
fn PageNotFound(route: Vec<String>) -> Element {
rsx! {
h1 { "Page not found" }
p { "We are terribly sorry, but the page you requested doesn't exist." }
pre { color: "red", "log:\nattempted to navigate to: {route:?}" }
}
}
-4
View File
@@ -1,4 +0,0 @@
dist
target
static
.dioxus
-16
View File
@@ -1,16 +0,0 @@
[package]
name = "router-static-generation"
version = "0.1.0"
edition = "2021"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dioxus = { workspace = true, features = ["static-generation", "router"] }
tracing-subscriber = "0.3.18"
[features]
default = []
server = ["dioxus/axum"]
web = ["dioxus/web"]
-54
View File
@@ -1,54 +0,0 @@
//! Static generation works out of the box with the router. Just add a router anywhere in your app and it will generate any static routes for you!
#![allow(unused)]
use dioxus::prelude::*;
// Generate all routes and output them to the static path
fn main() {
dioxus::launch(|| {
rsx! {
Router::<Route> {}
}
});
}
#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
#[route("/")]
Home {},
#[route("/blog")]
Blog,
}
#[component]
fn Blog() -> Element {
rsx! {
Link { to: Route::Home {}, "Go to counter" }
table {
tbody {
for _ in 0..100 {
tr {
for _ in 0..100 {
td { "hello!" }
}
}
}
}
}
}
}
#[component]
fn Home() -> Element {
let mut count = use_signal(|| 0);
rsx! {
Link { to: Route::Blog {}, "Go to blog" }
div {
h1 { "High-Five counter: {count}" }
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
}
}
}
-4
View File
@@ -1,4 +0,0 @@
dist
target
static
.dioxus
-16
View File
@@ -1,16 +0,0 @@
[package]
name = "simple-static-generation"
version = "0.1.0"
edition = "2021"
publish = false
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
dioxus = { workspace = true, features = ["static-generation"] }
tracing-subscriber = "0.3.18"
[features]
default = []
server = ["dioxus/axum"]
web = ["dioxus/web"]
-17
View File
@@ -1,17 +0,0 @@
//! Static generation lets you pre-render your entire app to static files and then hydrate it on the client.
use dioxus::prelude::*;
// Generate all routes and output them to the static path
fn main() {
dioxus::launch(app);
}
fn app() -> Element {
let mut count = use_signal(|| 0);
rsx! {
h1 { "High-Five counter: {count}" }
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
}
}