mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-04-29 07:16:11 +02:00
refactor: don't mark updates as automatic and fetch versions via version_updater only
This commit is contained in:
@@ -197,43 +197,6 @@ impl AutoUpdater {
|
||||
result
|
||||
}
|
||||
|
||||
/// Mark download as auto-update
|
||||
pub fn mark_auto_update_download(
|
||||
&self,
|
||||
browser: &str,
|
||||
version: &str,
|
||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let mut state = self.load_auto_update_state()?;
|
||||
let download_key = format!("{browser}-{version}");
|
||||
state.auto_update_downloads.insert(download_key);
|
||||
self.save_auto_update_state(&state)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove auto-update download tracking
|
||||
pub fn remove_auto_update_download(
|
||||
&self,
|
||||
browser: &str,
|
||||
version: &str,
|
||||
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let mut state = self.load_auto_update_state()?;
|
||||
let download_key = format!("{browser}-{version}");
|
||||
state.auto_update_downloads.remove(&download_key);
|
||||
self.save_auto_update_state(&state)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Check if download is marked as auto-update
|
||||
pub fn is_auto_update_download(
|
||||
&self,
|
||||
browser: &str,
|
||||
version: &str,
|
||||
) -> Result<bool, Box<dyn std::error::Error + Send + Sync>> {
|
||||
let state = self.load_auto_update_state()?;
|
||||
let download_key = format!("{browser}-{version}");
|
||||
Ok(state.auto_update_downloads.contains(&download_key))
|
||||
}
|
||||
|
||||
/// Automatically update all affected profile versions after browser download
|
||||
pub async fn auto_update_profile_versions(
|
||||
&self,
|
||||
@@ -463,30 +426,6 @@ pub async fn complete_browser_update_with_auto_update(
|
||||
.map_err(|e| format!("Failed to complete browser update: {e}"))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn mark_auto_update_download(browser: String, version: String) -> Result<(), String> {
|
||||
let updater = AutoUpdater::new();
|
||||
updater
|
||||
.mark_auto_update_download(&browser, &version)
|
||||
.map_err(|e| format!("Failed to mark auto-update download: {e}"))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn remove_auto_update_download(browser: String, version: String) -> Result<(), String> {
|
||||
let updater = AutoUpdater::new();
|
||||
updater
|
||||
.remove_auto_update_download(&browser, &version)
|
||||
.map_err(|e| format!("Failed to remove auto-update download: {e}"))
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn is_auto_update_download(browser: String, version: String) -> Result<bool, String> {
|
||||
let updater = AutoUpdater::new();
|
||||
updater
|
||||
.is_auto_update_download(&browser, &version)
|
||||
.map_err(|e| format!("Failed to check auto-update download: {e}"))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
@@ -49,8 +49,7 @@ use version_updater::{
|
||||
|
||||
use auto_updater::{
|
||||
check_for_browser_updates, complete_browser_update_with_auto_update, dismiss_update_notification,
|
||||
is_auto_update_download, is_browser_disabled_for_update, mark_auto_update_download,
|
||||
remove_auto_update_download,
|
||||
is_browser_disabled_for_update,
|
||||
};
|
||||
|
||||
use app_auto_updater::{
|
||||
@@ -354,9 +353,6 @@ pub fn run() {
|
||||
is_browser_disabled_for_update,
|
||||
dismiss_update_notification,
|
||||
complete_browser_update_with_auto_update,
|
||||
mark_auto_update_download,
|
||||
remove_auto_update_download,
|
||||
is_auto_update_download,
|
||||
check_for_app_updates,
|
||||
check_for_app_updates_manual,
|
||||
download_and_install_app_update,
|
||||
|
||||
@@ -4,7 +4,6 @@ use std::fs::{self, create_dir_all};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::api_client::ApiClient;
|
||||
use crate::browser_version_service::BrowserVersionService;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct TableSortingSettings {
|
||||
@@ -201,7 +200,9 @@ pub async fn save_table_sorting_settings(sorting: TableSortingSettings) -> Resul
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn clear_all_version_cache_and_refetch() -> Result<(), String> {
|
||||
pub async fn clear_all_version_cache_and_refetch(
|
||||
app_handle: tauri::AppHandle,
|
||||
) -> Result<(), String> {
|
||||
let api_client = ApiClient::new();
|
||||
|
||||
// Clear all cache first
|
||||
@@ -209,23 +210,15 @@ pub async fn clear_all_version_cache_and_refetch() -> Result<(), String> {
|
||||
.clear_all_cache()
|
||||
.map_err(|e| format!("Failed to clear version cache: {e}"))?;
|
||||
|
||||
// Trigger auto-fetch for only supported browsers
|
||||
let service = BrowserVersionService::new();
|
||||
let supported_browsers = service.get_supported_browsers();
|
||||
// Use the version updater to trigger a proper update with progress events
|
||||
use crate::version_updater::get_version_updater;
|
||||
let updater = get_version_updater();
|
||||
let updater_guard = updater.lock().await;
|
||||
|
||||
for browser in supported_browsers {
|
||||
// Start background fetch for each supported browser (don't wait for completion)
|
||||
let service_clone = BrowserVersionService::new();
|
||||
let browser_clone = browser.clone();
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = service_clone
|
||||
.fetch_browser_versions_detailed(&browser_clone, false)
|
||||
.await
|
||||
{
|
||||
eprintln!("Background version fetch failed for {browser_clone}: {e}");
|
||||
}
|
||||
});
|
||||
}
|
||||
updater_guard
|
||||
.trigger_manual_update(&app_handle)
|
||||
.await
|
||||
.map_err(|e| format!("Failed to trigger version update: {e}"))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -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