diff --git a/clients/cli/src/prover.rs b/clients/cli/src/prover.rs index a940b9a..119b258 100644 --- a/clients/cli/src/prover.rs +++ b/clients/cli/src/prover.rs @@ -106,7 +106,7 @@ async fn main() -> Result<(), Box> { let updater_config = UpdaterConfig::new(args.updater_mode, args.hostname); // b. runs the CLI's auto updater in a separate thread continuously in intervals - updater::spawn_auto_update_thread(&updater_config); + updater::spawn_auto_update_thread(&updater_config).expect("Failed to spawn auto-update thread"); let k = 4; // TODO(collinjackson): Get parameters from a file or URL. diff --git a/clients/cli/src/updater.rs b/clients/cli/src/updater.rs index 49989f2..eaa535d 100644 --- a/clients/cli/src/updater.rs +++ b/clients/cli/src/updater.rs @@ -19,18 +19,22 @@ use crate::utils::updater::{UpdaterConfig, VersionManager, VersionStatus, BLUE, // 1. The update checker can continuously monitor for new versions without interrupting the main CLI operations // 2. The main thread remains free to handle its primary responsibility (proving transactions) // 3. Users don't have to wait for update checks to complete before using the CLI -pub fn spawn_auto_update_thread(updater_config: &UpdaterConfig) { +pub fn spawn_auto_update_thread( + updater_config: &UpdaterConfig, +) -> Result<(), Box> { println!( "{}[auto-updater thread]{} Starting periodic CLI updates...", BLUE, RESET ); - // Initialize version manager - let version_manager = VersionManager::new(updater_config.clone()).unwrap(); - let version_manager = Arc::new(version_manager); + // Create a thread-safe version manager that can be shared across threads + let version_manager: Arc = Arc::new( + VersionManager::new(updater_config.clone()).expect("Failed to initialize version manager"), + ); + + // Create a reference for the new thread (original stays with main thread) + let version_manager_thread: Arc = version_manager.clone(); - // Clone Arcs for the update checker thread - let version_manager = version_manager.clone(); let update_interval = updater_config.update_interval; // Spawn the update checker thread @@ -42,12 +46,12 @@ pub fn spawn_auto_update_thread(updater_config: &UpdaterConfig) { // Infinite loop to check for updates loop { - match version_manager.as_ref().update_version_status() { + match version_manager_thread.as_ref().update_version_status() { // Got the latest version info with no error.... Ok(version_info) => match version_info { // ... there is an update available, try to apply it VersionStatus::UpdateAvailable(new_version) => { - if let Err(e) = version_manager.apply_update(&new_version) { + if let Err(e) = version_manager_thread.apply_update(&new_version) { eprintln!( "{}[auto-updater thread]{} Failed to update CLI: {}", BLUE, RESET, e @@ -75,4 +79,6 @@ pub fn spawn_auto_update_thread(updater_config: &UpdaterConfig) { thread::sleep(Duration::from_secs(update_interval)); } }); + + Ok(()) }