Skip to content

Commit

Permalink
handling downloads properly wrt electron accross app restarts (#2490)
Browse files Browse the repository at this point in the history
  • Loading branch information
Palanikannan1437 authored Sep 1, 2022
1 parent 94391db commit 27373b5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/downloads/reducers/downloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
DOWNLOAD_REMOVED,
DOWNLOAD_UPDATED,
} from '../actions';
import { Download } from '../common';
import { Download, DownloadStatus } from '../common';

type DownloadsAction =
| ActionOf<typeof APP_SETTINGS_LOADED>
Expand All @@ -20,8 +20,16 @@ export const downloads = (
action: DownloadsAction
): Record<Download['itemId'], Download> => {
switch (action.type) {
case APP_SETTINGS_LOADED:
return action.payload.downloads ?? {};
case APP_SETTINGS_LOADED: {
const initDownloads = action.payload.downloads ?? {};
Object.values(initDownloads).forEach((value) => {
if (value.state === 'progressing' || value.state === 'paused') {
value.state = 'cancelled';
value.status = DownloadStatus.CANCELLED;
}
});
return initDownloads ?? {};
}

case DOWNLOAD_CREATED: {
const download = action.payload;
Expand Down

0 comments on commit 27373b5

Please sign in to comment.