Skip to content

Commit

Permalink
fix(cli.rs): remove startup delay in tauri dev (#3999)
Browse files Browse the repository at this point in the history
* fix(cli.rs): remove startup delay in `tauri dev`

* change timeout [skip ci]

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
  • Loading branch information
amrbashir and lucasfernog committed Apr 29, 2022
1 parent 4f0f318 commit bbabc8c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
7 changes: 7 additions & 0 deletions .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.
50 changes: 22 additions & 28 deletions tooling/cli/src/dev.rs
Expand Up @@ -71,28 +71,15 @@ 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
}

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 {
Expand Down Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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(&current_version)?;

let upstream_version = crate::info::cli_upstream_version()?;
let upstream = semver::Version::parse(&upstream_version)?;
if upstream.gt(&current) {
let message = format!(
"🚀 A new version of Tauri CLI is avaliable! [{}]",
upstream.to_string()
);
return Ok((message, true));
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(&current_version)?;

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<F: FnMut(FileType, PathBuf)>(dir: &Path, mut f: F) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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));
}
}
Expand Down
1 change: 1 addition & 0 deletions tooling/cli/src/info.rs
Expand Up @@ -99,6 +99,7 @@ pub(crate) fn cli_upstream_version() -> Result<String> {
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,
Expand Down

0 comments on commit bbabc8c

Please sign in to comment.