mirror of
https://github.com/markuryy/shark.git
synced 2025-12-12 11:41:02 +00:00
fix(queue): reset interrupted downloads and clear current job on load
This commit is contained in:
@@ -122,9 +122,6 @@ export class DeezerQueueManager {
|
||||
this.abortController = new AbortController();
|
||||
console.log('[DeezerQueueManager] Starting queue processor');
|
||||
|
||||
// Clear any stale currentJob from previous session
|
||||
await setCurrentJob(null);
|
||||
|
||||
try {
|
||||
await this.processQueue();
|
||||
} catch (error) {
|
||||
|
||||
@@ -50,11 +50,34 @@ export async function loadDownloadQueue(): Promise<void> {
|
||||
const queue = await store.get<Record<string, QueueItem>>('queue');
|
||||
const currentJob = await store.get<string>('currentJob');
|
||||
|
||||
downloadQueue.set({
|
||||
// Reset any items stuck in 'downloading' state from previous session
|
||||
const cleanedQueue = { ...(queue ?? {}) };
|
||||
let resetCount = 0;
|
||||
for (const id in cleanedQueue) {
|
||||
const item = cleanedQueue[id];
|
||||
if (item && item.status === 'downloading') {
|
||||
cleanedQueue[id] = {
|
||||
...item,
|
||||
status: 'queued',
|
||||
progress: 0,
|
||||
currentTrack: undefined
|
||||
};
|
||||
resetCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (resetCount > 0) {
|
||||
console.log(`[DownloadQueue] Reset ${resetCount} interrupted download(s)`);
|
||||
}
|
||||
|
||||
const newState = {
|
||||
queueOrder: queueOrder ?? [],
|
||||
queue: queue ?? {},
|
||||
currentJob: currentJob ?? null
|
||||
});
|
||||
queue: cleanedQueue,
|
||||
currentJob: null // Always clear currentJob on load
|
||||
};
|
||||
|
||||
downloadQueue.set(newState);
|
||||
await saveQueue(newState);
|
||||
}
|
||||
|
||||
// Save queue to disk
|
||||
|
||||
Reference in New Issue
Block a user