From bbabc8cd1ea2c1f6806610fd2d533c99305d320c Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Fri, 29 Apr 2022 18:44:31 +0200 Subject: [PATCH] fix(cli.rs): remove startup delay in `tauri dev` (#3999) * fix(cli.rs): remove startup delay in `tauri dev` * change timeout [skip ci] Co-authored-by: Lucas Nogueira --- .changes/cli.rs-dev-update-check-delay.md | 7 ++++ tooling/cli/src/dev.rs | 48 ++++++++++------------- tooling/cli/src/info.rs | 1 + 3 files changed, 29 insertions(+), 27 deletions(-) create mode 100644 .changes/cli.rs-dev-update-check-delay.md diff --git a/.changes/cli.rs-dev-update-check-delay.md b/.changes/cli.rs-dev-update-check-delay.md new file mode 100644 index 000000000..13da1a48b --- /dev/null +++ b/.changes/cli.rs-dev-update-check-delay.md @@ -0,0 +1,7 @@ +--- +"cli.rs": patch +"cli.js": patch +--- + +* Remove startup delay in `tauri dev` caused by checking for a newer cli version. The check is now done upon process exit. +* Add `TAURI_SKIP_UPDATE_CHECK` env variable to skip checking for a newer CLI version. diff --git a/tooling/cli/src/dev.rs b/tooling/cli/src/dev.rs index 3182360dc..82d409b32 100644 --- a/tooling/cli/src/dev.rs +++ b/tooling/cli/src/dev.rs @@ -71,6 +71,8 @@ pub fn command(options: Options) -> Result<()> { let r = command_internal(options); if r.is_err() { kill_before_dev_process(); + #[cfg(not(debug_assertions))] + let _ = check_for_updates(); } r } @@ -78,21 +80,6 @@ pub fn command(options: Options) -> Result<()> { fn command_internal(options: Options) -> Result<()> { let logger = Logger::new("tauri:dev"); - #[cfg(not(debug_assertions))] - match check_for_updates() { - Ok((msg, sleep)) => { - if sleep { - logger.log(msg); - std::thread::sleep(std::time::Duration::from_secs(3)); - } else { - logger.log(msg); - } - } - Err(e) => { - logger.log(e.to_string()); - } - }; - let tauri_path = tauri_dir(); set_current_dir(&tauri_path).with_context(|| "failed to change current working directory")?; let merge_config = if let Some(config) = &options.config { @@ -160,6 +147,8 @@ fn command_internal(options: Options) -> Result<()> { let _ = ctrlc::set_handler(move || { kill_before_dev_process(); + #[cfg(not(debug_assertions))] + let _ = check_for_updates(); exit(130); }); } @@ -297,20 +286,21 @@ fn command_internal(options: Options) -> Result<()> { } #[cfg(not(debug_assertions))] -fn check_for_updates() -> Result<(String, bool)> { - let current_version = crate::info::cli_current_version()?; - let current = semver::Version::parse(¤t_version)?; +fn check_for_updates() -> Result<()> { + if std::env::var_os("TAURI_SKIP_UPDATE_CHECK") != Some("true".into()) { + let current_version = crate::info::cli_current_version()?; + let current = semver::Version::parse(¤t_version)?; - let upstream_version = crate::info::cli_upstream_version()?; - let upstream = semver::Version::parse(&upstream_version)?; - if upstream.gt(¤t) { - let message = format!( - "🚀 A new version of Tauri CLI is avaliable! [{}]", - upstream.to_string() - ); - return Ok((message, true)); + let upstream_version = crate::info::cli_upstream_version()?; + let upstream = semver::Version::parse(&upstream_version)?; + if current < upstream { + println!( + "🚀 A new version of Tauri CLI is avaliable! [{}]", + upstream.to_string() + ); + }; } - Ok(("🎉 Tauri CLI is up-to-date!".into(), false)) + Ok(()) } fn lookup(dir: &Path, mut f: F) { @@ -534,6 +524,8 @@ fn start_app( if exit_on_panic { if !manually_killed_app.load(Ordering::Relaxed) { kill_before_dev_process(); + #[cfg(not(debug_assertions))] + let _ = check_for_updates(); exit(status.code().unwrap_or(0)); } } else { @@ -551,6 +543,8 @@ fn start_app( // - and error is not a cargo compilation error (using stderr heuristics) if status.success() || (status.code() == Some(101) && !is_cargo_compile_error) { kill_before_dev_process(); + #[cfg(not(debug_assertions))] + let _ = check_for_updates(); exit(status.code().unwrap_or(1)); } } diff --git a/tooling/cli/src/info.rs b/tooling/cli/src/info.rs index 5672f8041..73ef1f4bd 100644 --- a/tooling/cli/src/info.rs +++ b/tooling/cli/src/info.rs @@ -99,6 +99,7 @@ pub(crate) fn cli_upstream_version() -> Result { let upstream_metadata = match ureq::get( "https://raw.githubusercontent.com/tauri-apps/tauri/dev/tooling/cli/metadata.json", ) + .timeout(std::time::Duration::from_secs(3)) .call() { Ok(r) => r,