refactor: better camoufox instance tracking

This commit is contained in:
zhom
2025-07-31 03:56:41 +04:00
parent 2fd344b9bb
commit 63000c72bd
20 changed files with 1623 additions and 457 deletions
+19 -1
View File
@@ -1,6 +1,6 @@
import { invoke } from "@tauri-apps/api/core";
import { listen } from "@tauri-apps/api/event";
import { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import { getBrowserDisplayName } from "@/lib/browser-utils";
import {
dismissToast,
@@ -47,6 +47,9 @@ export function useVersionUpdater() {
const [updateProgress, setUpdateProgress] =
useState<VersionUpdateProgress | null>(null);
// Track active downloads to prevent duplicates
const activeDownloads = useRef(new Set<string>());
const loadUpdateStatus = useCallback(async () => {
try {
const [lastUpdate, timeUntilNext] = await invoke<[number | null, number]>(
@@ -160,6 +163,18 @@ export function useVersionUpdater() {
console.log("Browser auto-update event received:", event.payload);
const browserDisplayName = getBrowserDisplayName(browser);
const downloadKey = `${browser}-${new_version}`;
// Check if this download is already in progress
if (activeDownloads.current.has(downloadKey)) {
console.log(
`Download already in progress for ${browserDisplayName} ${new_version}, skipping`,
);
return;
}
// Mark download as active
activeDownloads.current.add(downloadKey);
try {
// Show auto-update start notification
@@ -237,6 +252,9 @@ export function useVersionUpdater() {
: "Unknown error occurred",
duration: 8000,
});
} finally {
// Remove from active downloads
activeDownloads.current.delete(downloadKey);
}
};