mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-06-07 07:23:56 +02:00
refactor: don't mark updates as automatic and fetch versions via version_updater only
This commit is contained in:
@@ -60,53 +60,29 @@ export function useBrowserDownload() {
|
||||
|
||||
const browserName = getBrowserDisplayName(progress.browser);
|
||||
|
||||
// Check if this is an auto-update download to suppress completion toast
|
||||
const checkAutoUpdate = async () => {
|
||||
let isAutoUpdate = false;
|
||||
try {
|
||||
isAutoUpdate = await invoke<boolean>("is_auto_update_download", {
|
||||
browser: progress.browser,
|
||||
version: progress.version,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to check auto-update status:", error);
|
||||
}
|
||||
// Show toast with progress
|
||||
if (progress.stage === "downloading") {
|
||||
const speedMBps = (
|
||||
progress.speed_bytes_per_sec /
|
||||
(1024 * 1024)
|
||||
).toFixed(1);
|
||||
const etaText = progress.eta_seconds
|
||||
? formatTime(progress.eta_seconds)
|
||||
: "calculating...";
|
||||
|
||||
// Show toast with progress
|
||||
if (progress.stage === "downloading") {
|
||||
const speedMBps = (
|
||||
progress.speed_bytes_per_sec /
|
||||
(1024 * 1024)
|
||||
).toFixed(1);
|
||||
const etaText = progress.eta_seconds
|
||||
? formatTime(progress.eta_seconds)
|
||||
: "calculating...";
|
||||
|
||||
showDownloadToast(browserName, progress.version, "downloading", {
|
||||
percentage: progress.percentage,
|
||||
speed: speedMBps,
|
||||
eta: etaText,
|
||||
});
|
||||
} else if (progress.stage === "extracting") {
|
||||
showDownloadToast(browserName, progress.version, "extracting");
|
||||
} else if (progress.stage === "verifying") {
|
||||
showDownloadToast(browserName, progress.version, "verifying");
|
||||
} else if (progress.stage === "completed") {
|
||||
// Suppress completion toast for auto-updates
|
||||
showDownloadToast(
|
||||
browserName,
|
||||
progress.version,
|
||||
"completed",
|
||||
undefined,
|
||||
{
|
||||
suppressCompletionToast: isAutoUpdate,
|
||||
},
|
||||
);
|
||||
setDownloadProgress(null);
|
||||
}
|
||||
};
|
||||
|
||||
void checkAutoUpdate();
|
||||
showDownloadToast(browserName, progress.version, "downloading", {
|
||||
percentage: progress.percentage,
|
||||
speed: speedMBps,
|
||||
eta: etaText,
|
||||
});
|
||||
} else if (progress.stage === "extracting") {
|
||||
showDownloadToast(browserName, progress.version, "extracting");
|
||||
} else if (progress.stage === "verifying") {
|
||||
showDownloadToast(browserName, progress.version, "verifying");
|
||||
} else if (progress.stage === "completed") {
|
||||
showDownloadToast(browserName, progress.version, "completed");
|
||||
setDownloadProgress(null);
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getBrowserDisplayName } from "@/lib/browser-utils";
|
||||
import { showAutoUpdateToast, showToast } from "@/lib/toast-utils";
|
||||
import { showToast } from "@/lib/toast-utils";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
|
||||
@@ -95,8 +95,14 @@ export function useUpdateNotifications(
|
||||
notificationId,
|
||||
});
|
||||
|
||||
// Show auto-update started toast
|
||||
showAutoUpdateToast(browserDisplayName, newVersion);
|
||||
// Show update available toast and start download immediately
|
||||
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.`,
|
||||
duration: 4000,
|
||||
});
|
||||
|
||||
try {
|
||||
// Check if browser already exists before downloading
|
||||
@@ -111,12 +117,7 @@ export function useUpdateNotifications(
|
||||
`${browserDisplayName} ${newVersion} already exists, skipping download`,
|
||||
);
|
||||
} else {
|
||||
// Mark download as auto-update in the backend for toast suppression
|
||||
await invoke("mark_auto_update_download", {
|
||||
browser,
|
||||
version: newVersion,
|
||||
});
|
||||
|
||||
// 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)
|
||||
await invoke("download_browser", {
|
||||
browserStr: browser,
|
||||
@@ -144,17 +145,16 @@ export function useUpdateNotifications(
|
||||
id: `auto-update-success-${browser}-${newVersion}`,
|
||||
type: "success",
|
||||
title: `${browserDisplayName} update completed`,
|
||||
description: `${profileText} to version ${newVersion}. To update running profiles, restart them.`,
|
||||
duration: 5000,
|
||||
description: `${profileText} to version ${newVersion}. You can now launch your browsers with the latest version.`,
|
||||
duration: 6000,
|
||||
});
|
||||
} else {
|
||||
showToast({
|
||||
id: `auto-update-success-${browser}-${newVersion}`,
|
||||
type: "success",
|
||||
title: `${browserDisplayName} update ready`,
|
||||
description:
|
||||
"All affected profiles are currently running. To update them, restart them.",
|
||||
duration: 5000,
|
||||
title: `${browserDisplayName} update completed`,
|
||||
description: `Version ${newVersion} is now available. Running profiles will use the new version when restarted.`,
|
||||
duration: 6000,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -165,22 +165,12 @@ export function useUpdateNotifications(
|
||||
} catch (downloadError) {
|
||||
console.error("Failed to download browser:", downloadError);
|
||||
|
||||
// Clean up auto-update tracking on error
|
||||
try {
|
||||
await invoke("remove_auto_update_download", {
|
||||
browser,
|
||||
version: newVersion,
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("Failed to clean up auto-update tracking:", e);
|
||||
}
|
||||
|
||||
showToast({
|
||||
id: `auto-update-error-${browser}-${newVersion}`,
|
||||
type: "error",
|
||||
title: `Failed to download ${browserDisplayName} ${newVersion}`,
|
||||
description: String(downloadError),
|
||||
duration: 6000,
|
||||
duration: 8000,
|
||||
});
|
||||
throw downloadError;
|
||||
}
|
||||
@@ -195,7 +185,7 @@ export function useUpdateNotifications(
|
||||
type: "error",
|
||||
title: `Failed to update ${browserDisplayName}`,
|
||||
description: String(error),
|
||||
duration: 6000,
|
||||
duration: 8000,
|
||||
});
|
||||
} finally {
|
||||
// Remove from active downloads and updating browsers
|
||||
|
||||
@@ -35,6 +35,18 @@ export function useVersionUpdater() {
|
||||
const [updateProgress, setUpdateProgress] =
|
||||
useState<VersionUpdateProgress | null>(null);
|
||||
|
||||
const loadUpdateStatus = useCallback(async () => {
|
||||
try {
|
||||
const [lastUpdate, timeUntilNext] = await invoke<[number | null, number]>(
|
||||
"get_version_update_status",
|
||||
);
|
||||
setLastUpdateTime(lastUpdate);
|
||||
setTimeUntilNextUpdate(timeUntilNext);
|
||||
} catch (error) {
|
||||
console.error("Failed to load version update status:", error);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// Listen for version update progress events
|
||||
useEffect(() => {
|
||||
const unlisten = listen<VersionUpdateProgress>(
|
||||
@@ -69,9 +81,8 @@ export function useVersionUpdater() {
|
||||
|
||||
if (progress.new_versions_found > 0) {
|
||||
toast.success("Browser versions updated successfully", {
|
||||
duration: 4000,
|
||||
description:
|
||||
"Version information has been updated in the background",
|
||||
duration: 5000,
|
||||
description: `Found ${progress.new_versions_found} new browser versions. Update notifications will appear shortly.`,
|
||||
});
|
||||
} else {
|
||||
toast.success("No new browser versions found", {
|
||||
@@ -88,7 +99,7 @@ export function useVersionUpdater() {
|
||||
dismissToast("unified-version-update");
|
||||
|
||||
toast.error("Failed to update browser versions", {
|
||||
duration: 4000,
|
||||
duration: 6000,
|
||||
description: "Check your internet connection and try again",
|
||||
});
|
||||
}
|
||||
@@ -100,7 +111,7 @@ export function useVersionUpdater() {
|
||||
fn();
|
||||
});
|
||||
};
|
||||
}, []);
|
||||
}, [loadUpdateStatus]);
|
||||
|
||||
// Load update status on mount and periodically
|
||||
useEffect(() => {
|
||||
@@ -114,19 +125,7 @@ export function useVersionUpdater() {
|
||||
return () => {
|
||||
clearInterval(interval);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const loadUpdateStatus = useCallback(async () => {
|
||||
try {
|
||||
const [lastUpdate, timeUntilNext] = await invoke<[number | null, number]>(
|
||||
"get_version_update_status",
|
||||
);
|
||||
setLastUpdateTime(lastUpdate);
|
||||
setTimeUntilNextUpdate(timeUntilNext);
|
||||
} catch (error) {
|
||||
console.error("Failed to load version update status:", error);
|
||||
}
|
||||
}, []);
|
||||
}, [loadUpdateStatus]);
|
||||
|
||||
const triggerManualUpdate = useCallback(async () => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user