Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restart downloads upon re-opening the application #1716

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
};
}
Comment on lines +106 to +111
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I randomly fell on this edge case, so I decided to handle it.

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
Loading