diff --git a/packages/app/app/App.js b/packages/app/app/App.js index 0c904eb91d..a46f75d732 100644 --- a/packages/app/app/App.js +++ b/packages/app/app/App.js @@ -19,6 +19,7 @@ import * as ConnectivityActions from './actions/connectivity'; import * as GithubContribActions from './actions/githubContrib'; import * as WindowActions from './actions/window'; import * as NuclearConfigActions from './actions/nuclear/configuration'; +import * as DownloadActions from './actions/downloads'; import './app.global.scss'; import styles from './styles.scss'; @@ -64,6 +65,7 @@ class App extends React.PureComponent { this.props.actions.githubContribInfo(); this.props.actions.fetchNuclearConfiguration(); this.props.actions.fetchNuclearParams(); + this.props.actions.resumeDownloads(); this.updateConnectivityStatus(navigator.onLine); window.addEventListener('online', () => this.updateConnectivityStatus(true)); @@ -198,7 +200,8 @@ function mapDispatchToProps(dispatch) { SearchActions, GithubContribActions, WindowActions, - NuclearConfigActions + NuclearConfigActions, + DownloadActions ), dispatch ) diff --git a/packages/app/app/actions/actionTypes.ts b/packages/app/app/actions/actionTypes.ts index 22a46bce1e..7a8d1c1ffd 100644 --- a/packages/app/app/actions/actionTypes.ts +++ b/packages/app/app/actions/actionTypes.ts @@ -152,6 +152,7 @@ export enum Equalizer { export enum Download { READ_DOWNLOADS = 'READ_DOWNLOADS', ADD_TO_DOWNLOADS = 'ADD_TO_DOWNLOADS', + RESUME_DOWNLOADS = 'RESUME_DOWNLOADS', DOWNLOAD_STARTED = 'DOWNLOAD_STARTED', DOWNLOAD_PAUSED = 'DOWNLOAD_PAUSED', DOWNLOAD_RESUMED = 'DOWNLOAD_RESUMED', diff --git a/packages/app/app/actions/downloads.ts b/packages/app/app/actions/downloads.ts index 91c54c85ea..462aa1afa1 100644 --- a/packages/app/app/actions/downloads.ts +++ b/packages/app/app/actions/downloads.ts @@ -101,8 +101,15 @@ export const onDownloadResume = createStandardAction(DownloadActionTypes.DOWNLOA export const onDownloadProgress = createStandardAction(DownloadActionTypes.DOWNLOAD_PROGRESS).map( (uuid: string, progress: number) => { - const downloads = store.get('downloads'); - let payload = changePropertyForItem({ + const downloads: Download[] = store.get('downloads'); + const track = downloads.find((item) => item.track.uuid === uuid); + if (track === undefined) { + // track is no longer in downloads, so nothing can be updated + return { + payload: downloads + }; + } + let payload: Download[] = changePropertyForItem({ downloads, uuid, propertyName: 'completion', @@ -172,3 +179,19 @@ export const clearFinishedDownloads = createStandardAction(DownloadActionTypes.C payload: filteredTracks }; }); + +export const resumeDownloads = createStandardAction(DownloadActionTypes.RESUME_DOWNLOADS).map( + () => { + const downloads: Download[] = store.get('downloads'); + const startedItem = downloads.find((item) => item.status === DownloadStatus.STARTED); + let payload = downloads; + if (startedItem !== undefined) { + payload = changePropertyForItem({ + downloads, + uuid: startedItem.track.uuid, + value: DownloadStatus.WAITING + }); + } + return { payload, type: DownloadActionTypes.RESUME_DOWNLOADS }; + } +); diff --git a/packages/app/app/reducers/downloads.ts b/packages/app/app/reducers/downloads.ts index d0d06d628a..12a9730776 100644 --- a/packages/app/app/reducers/downloads.ts +++ b/packages/app/app/reducers/downloads.ts @@ -15,6 +15,7 @@ export default function DownloadsReducer(state=initialState, action: DownloadRed case getType(DownloadActions.onDownloadResume): case getType(DownloadActions.onDownloadPause): return [...action.payload.downloads]; + case getType(DownloadActions.resumeDownloads): case getType(DownloadActions.readDownloads): case getType(DownloadActions.onDownloadStarted): case getType(DownloadActions.onDownloadProgress): diff --git a/packages/app/app/store/middlewares/ipc.ts b/packages/app/app/store/middlewares/ipc.ts index d95ef3fd7f..ccca4556c0 100644 --- a/packages/app/app/store/middlewares/ipc.ts +++ b/packages/app/app/store/middlewares/ipc.ts @@ -120,6 +120,7 @@ const ipcConnect: Middleware = () => next => { ipcRenderer.send(IpcEvents.DOWNLOAD_PAUSE, track); break; } + case getType(DownloadActions.resumeDownloads): case getType(DownloadActions.onDownloadFinished): case getType(DownloadActions.onDownloadError): { const nextDownload = payload.find((download) =>