Skip to content

Commit bbabc8c

Browse files
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 <lucas@tauri.studio>
1 parent 4f0f318 commit bbabc8c

File tree

3 files changed

+30
-28
lines changed

3 files changed

+30
-28
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"cli.rs": patch
3+
"cli.js": patch
4+
---
5+
6+
* Remove startup delay in `tauri dev` caused by checking for a newer cli version. The check is now done upon process exit.
7+
* Add `TAURI_SKIP_UPDATE_CHECK` env variable to skip checking for a newer CLI version.

tooling/cli/src/dev.rs

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -71,28 +71,15 @@ pub fn command(options: Options) -> Result<()> {
7171
let r = command_internal(options);
7272
if r.is_err() {
7373
kill_before_dev_process();
74+
#[cfg(not(debug_assertions))]
75+
let _ = check_for_updates();
7476
}
7577
r
7678
}
7779

7880
fn command_internal(options: Options) -> Result<()> {
7981
let logger = Logger::new("tauri:dev");
8082

81-
#[cfg(not(debug_assertions))]
82-
match check_for_updates() {
83-
Ok((msg, sleep)) => {
84-
if sleep {
85-
logger.log(msg);
86-
std::thread::sleep(std::time::Duration::from_secs(3));
87-
} else {
88-
logger.log(msg);
89-
}
90-
}
91-
Err(e) => {
92-
logger.log(e.to_string());
93-
}
94-
};
95-
9683
let tauri_path = tauri_dir();
9784
set_current_dir(&tauri_path).with_context(|| "failed to change current working directory")?;
9885
let merge_config = if let Some(config) = &options.config {
@@ -160,6 +147,8 @@ fn command_internal(options: Options) -> Result<()> {
160147

161148
let _ = ctrlc::set_handler(move || {
162149
kill_before_dev_process();
150+
#[cfg(not(debug_assertions))]
151+
let _ = check_for_updates();
163152
exit(130);
164153
});
165154
}
@@ -297,20 +286,21 @@ fn command_internal(options: Options) -> Result<()> {
297286
}
298287

299288
#[cfg(not(debug_assertions))]
300-
fn check_for_updates() -> Result<(String, bool)> {
301-
let current_version = crate::info::cli_current_version()?;
302-
let current = semver::Version::parse(&current_version)?;
303-
304-
let upstream_version = crate::info::cli_upstream_version()?;
305-
let upstream = semver::Version::parse(&upstream_version)?;
306-
if upstream.gt(&current) {
307-
let message = format!(
308-
"🚀 A new version of Tauri CLI is avaliable! [{}]",
309-
upstream.to_string()
310-
);
311-
return Ok((message, true));
289+
fn check_for_updates() -> Result<()> {
290+
if std::env::var_os("TAURI_SKIP_UPDATE_CHECK") != Some("true".into()) {
291+
let current_version = crate::info::cli_current_version()?;
292+
let current = semver::Version::parse(&current_version)?;
293+
294+
let upstream_version = crate::info::cli_upstream_version()?;
295+
let upstream = semver::Version::parse(&upstream_version)?;
296+
if current < upstream {
297+
println!(
298+
"🚀 A new version of Tauri CLI is avaliable! [{}]",
299+
upstream.to_string()
300+
);
301+
};
312302
}
313-
Ok(("🎉 Tauri CLI is up-to-date!".into(), false))
303+
Ok(())
314304
}
315305

316306
fn lookup<F: FnMut(FileType, PathBuf)>(dir: &Path, mut f: F) {
@@ -534,6 +524,8 @@ fn start_app(
534524
if exit_on_panic {
535525
if !manually_killed_app.load(Ordering::Relaxed) {
536526
kill_before_dev_process();
527+
#[cfg(not(debug_assertions))]
528+
let _ = check_for_updates();
537529
exit(status.code().unwrap_or(0));
538530
}
539531
} else {
@@ -551,6 +543,8 @@ fn start_app(
551543
// - and error is not a cargo compilation error (using stderr heuristics)
552544
if status.success() || (status.code() == Some(101) && !is_cargo_compile_error) {
553545
kill_before_dev_process();
546+
#[cfg(not(debug_assertions))]
547+
let _ = check_for_updates();
554548
exit(status.code().unwrap_or(1));
555549
}
556550
}

tooling/cli/src/info.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub(crate) fn cli_upstream_version() -> Result<String> {
9999
let upstream_metadata = match ureq::get(
100100
"https://raw.githubusercontent.com/tauri-apps/tauri/dev/tooling/cli/metadata.json",
101101
)
102+
.timeout(std::time::Duration::from_secs(3))
102103
.call()
103104
{
104105
Ok(r) => r,

0 commit comments

Comments
 (0)