From 995a529b2f4ddab1c723120f45629f870ff08bef Mon Sep 17 00:00:00 2001 From: Jonathan Kelley Date: Fri, 6 Dec 2024 15:15:42 -0800 Subject: [PATCH] feat: some simple UI tweaks to CLI (#3301) --- packages/cli/src/build/bundle.rs | 2 ++ packages/cli/src/build/progress.rs | 6 ++++++ packages/cli/src/cli/create.rs | 1 + packages/cli/src/dioxus_crate.rs | 27 +++++++++++---------------- packages/cli/src/logging.rs | 4 ++++ packages/cli/src/serve/output.rs | 1 + packages/desktop/src/app.rs | 2 +- packages/dx-wire-format/src/lib.rs | 1 + 8 files changed, 27 insertions(+), 17 deletions(-) diff --git a/packages/cli/src/build/bundle.rs b/packages/cli/src/build/bundle.rs index 76881ddac..ef65a4e7b 100644 --- a/packages/cli/src/build/bundle.rs +++ b/packages/cli/src/build/bundle.rs @@ -777,6 +777,8 @@ impl AppBundle { /// Run any final tools to produce apks or other artifacts we might need. async fn assemble(&self) -> Result<()> { if let Platform::Android = self.build.build.platform() { + self.build.status_running_gradle(); + // make sure we can execute the gradlew script #[cfg(unix)] { diff --git a/packages/cli/src/build/progress.rs b/packages/cli/src/build/progress.rs index f07b22c5b..ed2286709 100644 --- a/packages/cli/src/build/progress.rs +++ b/packages/cli/src/build/progress.rs @@ -29,6 +29,12 @@ impl BuildRequest { }); } + pub(crate) fn status_running_gradle(&self) { + _ = self.progress.unbounded_send(BuildUpdate::Progress { + stage: BuildStage::RunningGradle, + }) + } + pub(crate) fn status_build_diagnostic(&self, message: CompilerMessage) { _ = self .progress diff --git a/packages/cli/src/cli/create.rs b/packages/cli/src/cli/create.rs index eae08d427..d23a4c6ac 100644 --- a/packages/cli/src/cli/create.rs +++ b/packages/cli/src/cli/create.rs @@ -211,6 +211,7 @@ pub(crate) fn post_create(path: &Path) -> Result<()> { file.write_all(new_readme.as_bytes())?; tracing::info!(dx_src = ?TraceSrc::Dev, "Generated project at {}", path.display()); + tracing::info!(dx_src = ?TraceSrc::Dev, "`cd` to your project and run `dx serve` to start developing. Build cool things! ✌️"); Ok(()) } diff --git a/packages/cli/src/dioxus_crate.rs b/packages/cli/src/dioxus_crate.rs index ee2802fe7..ba41a16ac 100644 --- a/packages/cli/src/dioxus_crate.rs +++ b/packages/cli/src/dioxus_crate.rs @@ -5,9 +5,9 @@ use anyhow::Context; use itertools::Itertools; use krates::{cm::Target, KrateDetails}; use krates::{cm::TargetKind, Cmd, Krates, NodeId}; +use std::path::Path; use std::path::PathBuf; use std::sync::Arc; -use std::{io::Write, path::Path}; use toml_edit::Item; // Contains information about the crate we are currently in and the dioxus config for that crate @@ -20,9 +20,9 @@ pub(crate) struct DioxusCrate { pub(crate) settings: CliSettings, } -pub(crate) static PROFILE_WASM: &str = "dioxus-wasm"; -pub(crate) static PROFILE_ANDROID: &str = "dioxus-android"; -pub(crate) static PROFILE_SERVER: &str = "dioxus-server"; +pub(crate) static PROFILE_WASM: &str = "wasm-dev"; +pub(crate) static PROFILE_ANDROID: &str = "android-dev"; +pub(crate) static PROFILE_SERVER: &str = "server-dev"; impl DioxusCrate { pub(crate) fn new(target: &TargetArgs) -> Result { @@ -291,18 +291,19 @@ impl DioxusCrate { self.config.web.pre_compress && release } - // The `opt-level=2` increases build times, but can noticeably decrease time + // The `opt-level=1` increases build times, but can noticeably decrease time // between saving changes and being able to interact with an app (for wasm/web). The "overall" // time difference (between having and not having the optimization) can be // almost imperceptible (~1 s) but also can be very noticeable (~6 s) — depends // on setup (hardware, OS, browser, idle load). // - // Find or create the client and server profiles in the .cargo/config.toml file + // Find or create the client and server profiles in the top-level Cargo.toml file + // todo(jon): we should/could make these optional by placing some defaults somewhere pub(crate) fn initialize_profiles(&self) -> crate::Result<()> { - let config_path = self.workspace_dir().join(".cargo/config.toml"); + let config_path = self.workspace_dir().join("Cargo.toml"); let mut config = match std::fs::read_to_string(&config_path) { Ok(config) => config.parse::().map_err(|e| { - crate::Error::Other(anyhow::anyhow!("Failed to parse .cargo/config.toml: {}", e)) + crate::Error::Other(anyhow::anyhow!("Failed to parse Cargo.toml: {}", e)) })?, Err(_) => Default::default(), }; @@ -322,7 +323,6 @@ impl DioxusCrate { if let toml_edit::Entry::Vacant(entry) = table.entry(PROFILE_SERVER) { let mut server = toml_edit::Table::new(); server.insert("inherits", Item::Value("dev".into())); - // server.insert("opt-level", Item::Value(2.into())); entry.insert(Item::Table(server)); } @@ -333,13 +333,8 @@ impl DioxusCrate { } } - // Write the config back to the file - if let Some(parent) = config_path.parent() { - std::fs::create_dir_all(parent)?; - } - let file = std::fs::File::create(config_path)?; - let mut buf_writer = std::io::BufWriter::new(file); - write!(buf_writer, "{}", config)?; + std::fs::write(config_path, config.to_string()) + .context("Failed to write profiles to Cargo.toml")?; Ok(()) } diff --git a/packages/cli/src/logging.rs b/packages/cli/src/logging.rs index fca7bcdb8..45d6a4cbc 100644 --- a/packages/cli/src/logging.rs +++ b/packages/cli/src/logging.rs @@ -95,6 +95,10 @@ impl TraceController { return Ok(()); } + if field.name() == "dx_src" && !args.verbosity.verbose { + return Ok(()); + } + write!(writer, "{}", format_field(field.name(), value)) }) .delimited(" "), diff --git a/packages/cli/src/serve/output.rs b/packages/cli/src/serve/output.rs index 7f7c96cd7..95bb879a9 100644 --- a/packages/cli/src/serve/output.rs +++ b/packages/cli/src/serve/output.rs @@ -488,6 +488,7 @@ impl Output { } BuildStage::OptimizingWasm {} => lines.push("Optimizing wasm".yellow()), BuildStage::RunningBindgen {} => lines.push("Running wasm-bindgen".yellow()), + BuildStage::RunningGradle {} => lines.push("Running gradle assemble".yellow()), BuildStage::Bundling {} => lines.push("Bundling app".yellow()), BuildStage::CopyingAssets { current, diff --git a/packages/desktop/src/app.rs b/packages/desktop/src/app.rs index c366dab1d..d41f55250 100644 --- a/packages/desktop/src/app.rs +++ b/packages/desktop/src/app.rs @@ -66,7 +66,7 @@ impl App { webviews: HashMap::new(), control_flow: ControlFlow::Wait, unmounted_dom: Cell::new(Some(virtual_dom)), - float_all: !cfg!(debug_assertions), + float_all: false, show_devtools: false, cfg: Cell::new(Some(cfg)), shared: Rc::new(SharedContext { diff --git a/packages/dx-wire-format/src/lib.rs b/packages/dx-wire-format/src/lib.rs index bf62a8d0e..b8777e868 100644 --- a/packages/dx-wire-format/src/lib.rs +++ b/packages/dx-wire-format/src/lib.rs @@ -63,6 +63,7 @@ pub enum BuildStage { path: PathBuf, }, Bundling, + RunningGradle, Success, Failed, Aborted,