diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 68a8046..9d0de54 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -165,12 +165,19 @@ pub fn run() { .build(), ) .setup(|app| { - // Clean up orphaned tmp files from previous crashes - { - use data::beads::RealBeadsCli; - use data::bridge::Bridge; - use data::lore::RealLoreCli; + use data::beads::RealBeadsCli; + use data::bridge::Bridge; + use data::lore::RealLoreCli; + // 1. Ensure data directories exist + let config = app::AppConfig::default(); + if let Err(e) = app::ensure_data_dir(&config) { + tracing::error!("Failed to create data directory: {}", e); + // Continue anyway - commands will fail gracefully + } + + // 2. Clean up orphaned tmp files from previous crashes + { let bridge: Bridge = Bridge::new(RealLoreCli, RealBeadsCli); if let Err(e) = bridge.cleanup_tmp_files() { @@ -178,6 +185,49 @@ pub fn run() { } } + // 3. Verify CLI dependencies (async, spawned to not block startup) + let app_handle = app.handle().clone(); + tauri::async_runtime::spawn(async move { + let (cli_available, warnings) = app::verify_cli_dependencies().await; + + // Log warnings + for warning in &warnings { + match warning { + app::StartupWarning::LoreMissing => { + tracing::warn!("lore CLI not found - GitLab sync will be unavailable"); + } + app::StartupWarning::BrMissing => { + tracing::warn!("br CLI not found - beads integration will be unavailable"); + } + app::StartupWarning::BvMissing => { + tracing::warn!("bv CLI not found - triage features will be unavailable"); + } + _ => {} + } + } + + // Emit startup warnings to frontend + if !warnings.is_empty() { + if let Err(e) = app_handle.emit("startup-warnings", &warnings) { + tracing::error!("Failed to emit startup warnings: {}", e); + } + } + + // Emit CLI availability to frontend + if let Err(e) = app_handle.emit("cli-availability", &cli_available) { + tracing::error!("Failed to emit CLI availability: {}", e); + } + + // 4. Trigger startup reconciliation if CLIs are available + if cli_available.lore && cli_available.br { + tracing::info!("Triggering startup reconciliation"); + // The frontend will call reconcile() command when ready + if let Err(e) = app_handle.emit("startup-sync-ready", ()) { + tracing::error!("Failed to emit startup-sync-ready: {}", e); + } + } + }); + // Set up system tray if let Err(e) = setup_tray(app) { tracing::error!("Failed to setup system tray: {}", e);