From 1f150d78b13c657504da88b71a60b4e47fe9837d Mon Sep 17 00:00:00 2001 From: NimBold Date: Wed, 17 Jun 2026 10:17:37 +0330 Subject: [PATCH] fix(persistence): reset interrupted downloads to queued on startup and deduplicate LazyStore instance - Reset items with 'downloading' or 'processing' status to 'queued' before re-enqueue on startup to prevent phantom active state - Include 'processing' status in recovery filter (was a zombie path) - Remove redundant LazyStore('store.bin') from settingsStore.ts; import shared instance from useDownloadStore.ts instead --- src/store/settingsStore.ts | 3 +-- src/store/useDownloadStore.ts | 11 ++++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/store/settingsStore.ts b/src/store/settingsStore.ts index 58944de..e4eea57 100644 --- a/src/store/settingsStore.ts +++ b/src/store/settingsStore.ts @@ -1,9 +1,8 @@ import { create } from 'zustand'; import { persist, createJSONStorage, StateStorage } from 'zustand/middleware'; -import { LazyStore } from '@tauri-apps/plugin-store'; import { info } from '@tauri-apps/plugin-log'; -export const tauriStore = new LazyStore('store.bin'); +import { tauriStore } from './useDownloadStore'; const tauriStorage: StateStorage = { getItem: async (name: string): Promise => { diff --git a/src/store/useDownloadStore.ts b/src/store/useDownloadStore.ts index a11fafd..e1ff984 100644 --- a/src/store/useDownloadStore.ts +++ b/src/store/useDownloadStore.ts @@ -533,8 +533,17 @@ export const useDownloadStore = create((set, get) => ({ downloads: downloads.length > 0 ? downloads : state.downloads })); + // Reset interrupted downloads (crashed while downloading/processing) to queued + set((state) => ({ + downloads: state.downloads.map(d => + d.status === 'downloading' || d.status === 'processing' + ? { ...d, status: 'queued' as const } + : d + ) + })); + // Auto resume downloads that were active or queued - const active = get().downloads.filter(d => d.status === 'downloading' || d.status === 'queued'); + const active = get().downloads.filter(d => d.status === 'queued'); if (active.length > 0) { try { const settings = useSettingsStore.getState();