From a9f64c78a3862c2e87d01de60e3779a9e00608e3 Mon Sep 17 00:00:00 2001 From: Marko Vejnovic Date: Wed, 11 Feb 2026 10:00:50 -0800 Subject: [PATCH] feat: run update check in the background to avoid blocking startup --- src/daemon.rs | 3 +++ src/main.rs | 2 -- src/updates.rs | 28 +++++++++++++++------------- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/daemon.rs b/src/daemon.rs index 288d031..0e70229 100644 --- a/src/daemon.rs +++ b/src/daemon.rs @@ -184,6 +184,9 @@ pub async fn run( config: app_config::Config, handle: tokio::runtime::Handle, ) -> Result<(), std::io::Error> { + // Fire-and-forget: errors are logged inside check_for_updates(). + tokio::spawn(crate::updates::check_for_updates()); + // Spawn the cache if it doesn't exist. tokio::fs::create_dir_all(&config.cache.path).await?; diff --git a/src/main.rs b/src/main.rs index 1fc8e29..5d16f85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,8 +58,6 @@ fn main() { std::process::exit(1); }); - updates::check_for_updates(); - let args = Args::parse(); let config = Config::load_or_create(args.config_path.as_deref()).unwrap_or_else(|e| { error!("Failed to load configuration: {e}"); diff --git a/src/updates.rs b/src/updates.rs index 752678a..b331d8a 100644 --- a/src/updates.rs +++ b/src/updates.rs @@ -11,24 +11,26 @@ const PKG_VERSION: &str = env!("CARGO_PKG_VERSION"); /// Check GitHub for the latest stable release and warn if this binary is outdated. /// /// This function never fails the application — it logs errors and returns. -pub fn check_for_updates() { +pub async fn check_for_updates() { let short_sha = &BUILD_SHA[..7.min(BUILD_SHA.len())]; let running_version = format!("{PKG_VERSION}+{short_sha}"); - let releases = match self_update::backends::github::ReleaseList::configure() - .repo_owner("mesa-dot-dev") - .repo_name("git-fs") - .build() + let releases = match tokio::task::spawn_blocking(|| { + self_update::backends::github::ReleaseList::configure() + .repo_owner("mesa-dot-dev") + .repo_name("git-fs") + .build() + .and_then(self_update::backends::github::ReleaseList::fetch) + }) + .await { - Ok(list) => match list.fetch() { - Ok(releases) => releases, - Err(e) => { - error!("Could not check for updates: {e}"); - return; - } - }, + Ok(Ok(releases)) => releases, + Ok(Err(e)) => { + error!("Could not check for updates: {e}"); + return; + } Err(e) => { - error!("Could not configure update check: {e}"); + error!("Update check task failed: {e}"); return; } };