Skip to content

Commit

Permalink
Merge pull request #1716 from waldo121/bug/1709-resume-download-on-re…
Browse files Browse the repository at this point in the history
…start

Restart downloads upon re-opening the application
  • Loading branch information
nukeop authored Oct 10, 2024
2 parents 9ba0eb5 + d028afd commit 94d809a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/app/app/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -198,7 +200,8 @@ function mapDispatchToProps(dispatch) {
SearchActions,
GithubContribActions,
WindowActions,
NuclearConfigActions
NuclearConfigActions,
DownloadActions
),
dispatch
)
Expand Down
1 change: 1 addition & 0 deletions packages/app/app/actions/actionTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
27 changes: 25 additions & 2 deletions packages/app/app/actions/downloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 };
}
);
1 change: 1 addition & 0 deletions packages/app/app/reducers/downloads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions packages/app/app/store/middlewares/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down

0 comments on commit 94d809a

Please sign in to comment.