mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-04-22 20:06:18 +02:00
refactor: change event emitting and remove sleep
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user