Redux changes and refactoring

This commit is contained in:
Scott E. Graves
2019-06-07 00:30:59 -05:00
parent 1dc99567f3
commit 31585fc912
6 changed files with 179 additions and 140 deletions

View File

@@ -0,0 +1,52 @@
import * as Constants from '../../constants';
import {createAction} from 'redux-starter-kit';
export const setAllowDownload = createAction('download/setAllowDownload');
export const SET_DOWNLOAD_BEGIN = 'download/setDownloadBegin';
export const setDownloadBegin = (name, type, url) => {
return {
type: SET_DOWNLOAD_BEGIN,
payload: {
name,
type,
url
}
};
};
export const setDownloadEnd = createAction('download/setDownloadEnd');
export const setDownloadProgress = createAction('download/setDownloadProgress');
export const downloadItem = (name, type, url, completedCallback) => {
return (dispatch, getState) => {
const state = getState();
if (!state.download.DownloadActive && state.download.AllowDownload) {
if (!process.versions.hasOwnProperty('electron')) {
const ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
if (ipcRenderer) {
dispatch(setDownloadBegin(name, type, url));
const downloadFileProgress = (_, arg) => {
dispatch(setDownloadProgress(arg.data.Progress));
};
const downloadFileComplete = (_, arg) => {
this.ipcRenderer.removeListener(Constants.IPC_Download_File_Progress, downloadFileProgress);
this.ipcRenderer.removeListener(Constants.IPC_Download_File_Complete, downloadFileComplete);
completedCallback(name, type, url, arg.data);
dispatch(setDownloadEnd(arg.data));
};
ipcRenderer.on(Constants.IPC_Download_File_Progress, downloadFileProgress);
ipcRenderer.on(Constants.IPC_Download_File_Complete, downloadFileComplete);
ipcRenderer.send(Constants.IPC_Download_File, {
Filename: name,
URL: url,
});
}
}
}
};
};