mirror of
https://github.com/neosubhamoy/neodlp.git
synced 2025-12-19 21:23:00 +05:30
fix: stop all ongoing downloads action not working on linux
This commit is contained in:
@@ -464,9 +464,11 @@ export default function App({ children }: { children: React.ReactNode }) {
|
|||||||
|
|
||||||
const pauseDownload = async (downloadState: DownloadState) => {
|
const pauseDownload = async (downloadState: DownloadState) => {
|
||||||
try {
|
try {
|
||||||
|
if ((downloadState.download_status === 'downloading' && downloadState.process_id) || (downloadState.download_status === 'starting' && downloadState.process_id)) {
|
||||||
setIsErrorExpected(true); // Set error expected to true to handle UI state
|
setIsErrorExpected(true); // Set error expected to true to handle UI state
|
||||||
console.log("Killing process with PID:", downloadState.process_id);
|
console.log("Killing process with PID:", downloadState.process_id);
|
||||||
await invoke('kill_all_process', { 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);
|
||||||
|
|||||||
@@ -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,22 +106,26 @@ 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) {
|
||||||
|
setIsPausingDownload(state.download_id, true);
|
||||||
try {
|
try {
|
||||||
await invoke('pause_ongoing_downloads').then(() => {
|
await pauseDownload(state);
|
||||||
queryClient.invalidateQueries({ queryKey: ['download-states'] });
|
|
||||||
toast({
|
|
||||||
title: 'Stopped downloads',
|
|
||||||
description: 'All ongoing downloads are being stopped.',
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
toast({
|
toast({
|
||||||
title: 'Failed to stop downloads',
|
title: 'Failed to stop download',
|
||||||
description: 'An error occurred while trying to stop the downloads.',
|
description: `An error occurred while trying to stop the download for ${state.title}.`,
|
||||||
variant: "destructive"
|
variant: "destructive"
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
setIsPausingDownload(state.download_id, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ongoingDownloads.length === 0) {
|
||||||
|
toast({
|
||||||
|
title: 'Stopped ongoing downloads',
|
||||||
|
description: 'All ongoing downloads have been stopped successfully.',
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
toast({
|
toast({
|
||||||
|
|||||||
Reference in New Issue
Block a user