diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 8d154e0..8ee9d0f 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -278,19 +278,12 @@ pub fn run() { let version_updater = get_version_updater(); let mut updater_guard = version_updater.lock().await; - // Set the app handle - updater_guard.set_app_handle(app_handle).await; - - // Start the background updates + updater_guard.set_app_handle(app_handle.clone()).await; updater_guard.start_background_updates().await; }); - // Check for app updates at startup let app_handle_update = app.handle().clone(); tauri::async_runtime::spawn(async move { - // Add a small delay to ensure the app is fully loaded - tokio::time::sleep(tokio::time::Duration::from_secs(3)).await; - println!("Starting app update check at startup..."); let updater = app_auto_updater::AppAutoUpdater::new(); match updater.check_for_updates().await { diff --git a/src-tauri/src/version_updater.rs b/src-tauri/src/version_updater.rs index bb97bef..e998734 100644 --- a/src-tauri/src/version_updater.rs +++ b/src-tauri/src/version_updater.rs @@ -300,9 +300,36 @@ impl VersionUpdater { browser_new_versions: 0, status: "updating".to_string(), }; - let _ = app_handle.emit("version-update-progress", &progress); + if let Err(e) = app_handle.emit("version-update-progress", &progress) { + eprintln!("Failed to emit start progress: {e}"); + } else { + println!("Emitted start progress event"); + } for (index, browser) in browsers.iter().enumerate() { + println!( + "Processing browser {} ({}/{}): {}", + browser, + index + 1, + total_browsers, + browser + ); + + // Emit progress for current browser + let progress = VersionUpdateProgress { + current_browser: browser.to_string(), + total_browsers, + completed_browsers: index, + new_versions_found: total_new_versions, + browser_new_versions: 0, + status: "updating".to_string(), + }; + if let Err(e) = app_handle.emit("version-update-progress", &progress) { + eprintln!("Failed to emit progress for {browser}: {e}"); + } else { + println!("Emitted progress event for browser: {browser}"); + } + // Check if individual browser cache is expired before updating if !self.version_service.should_update_cache(browser) { println!("Skipping {browser} - cache is still fresh"); @@ -318,18 +345,7 @@ impl VersionUpdater { continue; } - println!("Updating versions for browser: {browser}"); - - // Emit progress for current browser - let progress = VersionUpdateProgress { - current_browser: browser.to_string(), - total_browsers, - completed_browsers: index, - new_versions_found: total_new_versions, - browser_new_versions: 0, - status: "updating".to_string(), - }; - let _ = app_handle.emit("version-update-progress", &progress); + println!("Fetching new versions for browser: {browser}"); let result = self.update_browser_versions(browser).await; @@ -373,7 +389,11 @@ impl VersionUpdater { browser_new_versions: 0, status: "completed".to_string(), }; - let _ = app_handle.emit("version-update-progress", &progress); + if let Err(e) = app_handle.emit("version-update-progress", &progress) { + eprintln!("Failed to emit completion progress: {e}"); + } else { + println!("Emitted completion progress event"); + } println!("Background version update completed. Found {total_new_versions} new versions total"); diff --git a/src/hooks/use-update-notifications.tsx b/src/hooks/use-update-notifications.tsx index 1204641..4a5ce6c 100644 --- a/src/hooks/use-update-notifications.tsx +++ b/src/hooks/use-update-notifications.tsx @@ -1,5 +1,5 @@ import { getBrowserDisplayName } from "@/lib/browser-utils"; -import { showToast } from "@/lib/toast-utils"; +import { dismissToast, showToast } from "@/lib/toast-utils"; import { invoke } from "@tauri-apps/api/core"; import { useCallback, useEffect, useRef, useState } from "react"; @@ -83,10 +83,11 @@ export function useUpdateNotifications( return; } - // Mark download as active + // Mark download as active and disable browser activeDownloads.current.add(downloadKey); try { + // Set browser as updating FIRST before any async operations setUpdatingBrowsers((prev) => new Set(prev).add(browser)); const browserDisplayName = getBrowserDisplayName(browser); @@ -95,12 +96,12 @@ export function useUpdateNotifications( notificationId, }); - // Show update available toast and start download immediately + // Show update started notification showToast({ id: `auto-update-started-${browser}-${newVersion}`, type: "loading", - title: `${browserDisplayName} update available`, - description: `Version ${newVersion} is now being downloaded. Browser launch will be disabled until update completes.`, + title: `${browserDisplayName} update started`, + description: `Version ${newVersion} download will begin shortly. Browser launch is disabled until update completes.`, duration: 4000, }); @@ -116,9 +117,26 @@ export function useUpdateNotifications( console.log( `${browserDisplayName} ${newVersion} already exists, skipping download`, ); + + showToast({ + id: `auto-update-skip-download-${browser}-${newVersion}`, + type: "success", + title: `${browserDisplayName} ${newVersion} already available`, + description: "Updating profile configurations...", + duration: 3000, + }); } else { - // Don't mark as auto-update - we want to show full download progress - // Download the browser (progress will be handled by use-browser-download hook) + // Show download starting notification + showToast({ + id: `auto-update-download-starting-${browser}-${newVersion}`, + type: "loading", + title: `Starting ${browserDisplayName} ${newVersion} download`, + description: "Download progress will be shown below...", + duration: 4000, + }); + + // Download the browser - this will trigger download progress events automatically + // The use-browser-download hook will handle showing the download progress toasts await invoke("download_browser", { browserStr: browser, version: newVersion, @@ -158,13 +176,14 @@ export function useUpdateNotifications( }); } - // Trigger profile refresh to update UI with new versions if (onProfilesUpdated) { - void onProfilesUpdated(); + await onProfilesUpdated(); } } catch (downloadError) { console.error("Failed to download browser:", downloadError); + dismissToast(`download-${browser}-${newVersion}`); + showToast({ id: `auto-update-error-${browser}-${newVersion}`, type: "error",