fix(queue): preserve media terminal states

This commit is contained in:
NimBold
2026-06-18 07:26:40 +03:30
parent 18de275d42
commit 605992439d
6 changed files with 133 additions and 50 deletions
+11 -18
View File
@@ -1,4 +1,4 @@
import { initMediaDomains } from './utils/downloads';
import { initMediaDomains, isActiveDownloadStatus } from './utils/downloads';
import { useEffect, useRef, useState } from "react";
import { Sidebar, SidebarFilter } from "./components/Sidebar";
import { DownloadTable } from "./components/DownloadTable";
@@ -134,7 +134,7 @@ function App() {
useEffect(() => {
if (!schedulerRunning) return;
const hasPendingScheduledWork = downloads.some(download =>
download.status === 'queued' || download.status === 'downloading'
isActiveDownloadStatus(download.status)
);
if (hasPendingScheduledWork) return;
@@ -209,26 +209,20 @@ function App() {
useEffect(() => {
initDownloadListener();
const unlistenComplete = listen('download-complete', (event) => {
const unlistenTerminalState = listen('download-state', (event) => {
if (event.payload.status !== 'completed' && event.payload.status !== 'failed') return;
const settings = useSettingsStore.getState();
if (settings.showNotifications) {
const item = useDownloadStore.getState().downloads.find(d => d.id === event.payload);
const fileName = item?.fileName || 'A file';
if (!settings.showNotifications) return;
const item = useDownloadStore.getState().downloads.find(d => d.id === event.payload.id);
const fileName = item?.fileName || 'A file';
if (event.payload.status === 'completed') {
sendNotification({
title: 'Download Complete',
body: `${fileName} has finished downloading.`,
sound: settings.playCompletionSound ? 'default' : undefined
});
}
});
const unlistenFailed = listen('download-failed', (event) => {
const settings = useSettingsStore.getState();
if (settings.showNotifications) {
const item = useDownloadStore.getState().downloads.find(d => d.id === event.payload);
const fileName = item?.fileName || 'A file';
} else {
sendNotification({
title: 'Download Failed',
body: `${fileName} failed to download.`,
@@ -265,8 +259,7 @@ function App() {
return () => {
invoke('set_extension_frontend_ready', { ready: false }).catch(() => {});
unlistenComplete.then(f => f());
unlistenFailed.then(f => f());
unlistenTerminalState.then(f => f());
unlistenExtension.then(f => f());
unlistenExtensionQueued.then(f => f());
unlistenDeepLink.then(f => f());
+2
View File
@@ -4,6 +4,7 @@ import { listen as tauriListen, type Event, type EventCallback, type UnlistenFn
import type { DownloadCategory } from './bindings/DownloadCategory';
import type { DownloadItem } from './bindings/DownloadItem';
import type { DownloadProgressEvent } from './bindings/DownloadProgressEvent';
import type { DownloadStateEvent } from './bindings/DownloadStateEvent';
import type { DownloadStatus } from './bindings/DownloadStatus';
import type { ExtensionDownload } from './bindings/ExtensionDownload';
import type { MediaCookieSource } from './bindings/MediaCookieSource';
@@ -123,6 +124,7 @@ export function invokeCommand<K extends CommandName>(
type EventMap = {
'schedule-trigger': 'start' | 'stop';
'download-progress': DownloadProgressEvent;
'download-state': DownloadStateEvent;
'download-complete': string;
'download-failed': string;
'extension-add-download': ExtensionDownload;
+3 -2
View File
@@ -10,6 +10,7 @@ import type { ExtensionDownload } from '../bindings/ExtensionDownload';
import type { Queue } from '../bindings/Queue';
import type { MediaMetadata } from '../bindings/MediaMetadata';
import { useSettingsStore } from './useSettingsStore';
import { isActiveDownloadStatus } from '../utils/downloads';
export type { DownloadCategory } from '../utils/downloads';
@@ -533,10 +534,10 @@ export const useDownloadStore = create<DownloadState>((set, get) => ({
downloads: downloads.length > 0 ? downloads : state.downloads
}));
// Reset interrupted downloads (crashed while downloading/processing) to queued
// Reset interrupted active downloads to queued.
set((state) => ({
downloads: state.downloads.map(d =>
d.status === 'downloading' || d.status === 'processing'
isActiveDownloadStatus(d.status) && d.status !== 'queued'
? { ...d, status: 'queued' as const }
: d
)
+11
View File
@@ -1,4 +1,5 @@
import type { DownloadCategory } from '../bindings/DownloadCategory';
import type { DownloadStatus } from '../bindings/DownloadStatus';
export type { DownloadCategory } from '../bindings/DownloadCategory';
import { invoke } from '@tauri-apps/api/core';
@@ -19,6 +20,16 @@ let MEDIA_DOMAINS = [
'fb.watch'
];
const ACTIVE_DOWNLOAD_STATUSES: ReadonlySet<DownloadStatus> = new Set([
'queued',
'downloading',
'processing',
'retrying',
]);
export const isActiveDownloadStatus = (status: DownloadStatus): boolean =>
ACTIVE_DOWNLOAD_STATUSES.has(status);
export const initMediaDomains = async () => {
try {
const domains = await invoke<string[]>('get_supported_media_domains');