fix: stop all ongoing downloads action not working on linux

This commit is contained in:
2025-07-20 22:50:32 +05:30
parent 05a123c4c8
commit 161f7ad13c
2 changed files with 22 additions and 18 deletions

View File

@@ -464,9 +464,11 @@ export default function App({ children }: { children: React.ReactNode }) {
const pauseDownload = async (downloadState: DownloadState) => { const pauseDownload = async (downloadState: DownloadState) => {
try { try {
setIsErrorExpected(true); // Set error expected to true to handle UI state if ((downloadState.download_status === 'downloading' && downloadState.process_id) || (downloadState.download_status === 'starting' && downloadState.process_id)) {
console.log("Killing process with PID:", downloadState.process_id); setIsErrorExpected(true); // Set error expected to true to handle UI state
await invoke('kill_all_process', { pid: downloadState.process_id }); console.log("Killing process with PID:", downloadState.process_id);
await invoke('kill_all_process', { pid: downloadState.process_id });
}
downloadStatusUpdater.mutate({ download_id: downloadState.download_id, download_status: 'paused' }, { downloadStatusUpdater.mutate({ download_id: downloadState.download_id, download_status: 'paused' }, {
onSuccess: (data) => { onSuccess: (data) => {
console.log("Download status updated successfully:", data); console.log("Download status updated successfully:", data);

View File

@@ -6,7 +6,7 @@ import { Progress } from "@/components/ui/progress";
import { Separator } from "@/components/ui/separator"; import { Separator } from "@/components/ui/separator";
import { useToast } from "@/hooks/use-toast"; import { useToast } from "@/hooks/use-toast";
import { useAppContext } from "@/providers/appContextProvider"; import { useAppContext } from "@/providers/appContextProvider";
import { useDownloadActionStatesStore, useDownloaderPageStatesStore, useDownloadStatesStore, useLibraryPageStatesStore } from "@/services/store"; import { useDownloadActionStatesStore, useDownloadStatesStore, useLibraryPageStatesStore } from "@/services/store";
import { formatBitrate, formatCodec, formatDurationString, formatFileSize, formatSecToTimeString, formatSpeed } from "@/utils"; import { formatBitrate, formatCodec, formatDurationString, formatFileSize, formatSecToTimeString, formatSpeed } from "@/utils";
import { AudioLines, Clock, File, FileAudio2, FileQuestion, FileVideo2, FolderInput, ListVideo, Loader2, Music, Pause, Play, Square, Trash2, Video, X } from "lucide-react"; import { AudioLines, Clock, File, FileAudio2, FileQuestion, FileVideo2, FolderInput, ListVideo, Loader2, Music, Pause, Play, Square, Trash2, Video, X } from "lucide-react";
import { invoke } from "@tauri-apps/api/core"; import { invoke } from "@tauri-apps/api/core";
@@ -33,8 +33,6 @@ export default function LibraryPage() {
const setIsCancelingDownload = useDownloadActionStatesStore(state => state.setIsCancelingDownload); const setIsCancelingDownload = useDownloadActionStatesStore(state => state.setIsCancelingDownload);
const setIsDeleteFileChecked = useDownloadActionStatesStore(state => state.setIsDeleteFileChecked); const setIsDeleteFileChecked = useDownloadActionStatesStore(state => state.setIsDeleteFileChecked);
const setIsErrorExpected = useDownloaderPageStatesStore((state) => state.setIsErrorExpected);
const { pauseDownload, resumeDownload, cancelDownload } = useAppContext() const { pauseDownload, resumeDownload, cancelDownload } = useAppContext()
const { toast } = useToast(); const { toast } = useToast();
@@ -108,21 +106,25 @@ export default function LibraryPage() {
const stopOngoingDownloads = async () => { const stopOngoingDownloads = async () => {
if (ongoingDownloads.length > 0) { if (ongoingDownloads.length > 0) {
setIsErrorExpected(true); // Set error expected to true to handle UI state for (const state of ongoingDownloads) {
try { setIsPausingDownload(state.download_id, true);
await invoke('pause_ongoing_downloads').then(() => { try {
queryClient.invalidateQueries({ queryKey: ['download-states'] }); await pauseDownload(state);
} catch (e) {
console.error(e);
toast({ toast({
title: 'Stopped downloads', title: 'Failed to stop download',
description: 'All ongoing downloads are being stopped.', description: `An error occurred while trying to stop the download for ${state.title}.`,
variant: "destructive"
}); });
}); } finally {
} catch (e) { setIsPausingDownload(state.download_id, false);
console.error(e); }
}
if (ongoingDownloads.length === 0) {
toast({ toast({
title: 'Failed to stop downloads', title: 'Stopped ongoing downloads',
description: 'An error occurred while trying to stop the downloads.', description: 'All ongoing downloads have been stopped successfully.',
variant: "destructive"
}); });
} }
} else { } else {