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
This commit is contained in:
NimBold
2026-06-17 10:17:37 +03:30
parent 6521457cfe
commit 1f150d78b1
2 changed files with 11 additions and 3 deletions
+1 -2
View File
@@ -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<string | null> => {
+10 -1
View File
@@ -533,8 +533,17 @@ export const useDownloadStore = create<DownloadState>((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();