Refactoring
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import * as Constants from '../../constants';
|
||||
import {createAction} from 'redux-starter-kit';
|
||||
import {getIPCRenderer} from '../../utils';
|
||||
import {notifyError} from './error_actions';
|
||||
import {
|
||||
installDependency,
|
||||
installRelease,
|
||||
installUpgrade
|
||||
} from './install_actions';
|
||||
|
||||
export const setAllowDownload = createAction('download/setAllowDownload');
|
||||
|
||||
@@ -19,12 +25,36 @@ export const setDownloadBegin = (name, type, url) => {
|
||||
export const setDownloadEnd = createAction('download/setDownloadEnd');
|
||||
export const setDownloadProgress = createAction('download/setDownloadProgress');
|
||||
|
||||
export const downloadItem = (name, type, urls, completedCallback) => {
|
||||
export const downloadItem = (name, type, urls) => {
|
||||
return (dispatch, getState) => {
|
||||
if (!Array.isArray(urls)) {
|
||||
urls = [urls];
|
||||
}
|
||||
|
||||
const downloadComplete = result => {
|
||||
if (result.Success) {
|
||||
switch (type) {
|
||||
case Constants.INSTALL_TYPES.Dependency:
|
||||
dispatch(installDependency(result.Destination, result.URL));
|
||||
break;
|
||||
case Constants.INSTALL_TYPES.Release:
|
||||
dispatch(installRelease(result.Destination));
|
||||
break;
|
||||
case Constants.INSTALL_TYPES.Upgrade:
|
||||
//const info = this.props.LocationsLookup[this.props.AppPlatform][this.props.VersionLookup[this.props.AppPlatform][0]];
|
||||
const sha256 = null;//info.sha256;
|
||||
const signature = null;//info.sig;
|
||||
dispatch(installUpgrade(result.Destination, sha256, signature, !!result.SkipVerification));
|
||||
break;
|
||||
default:
|
||||
dispatch(notifyError('Unknown download type: ' + type));
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
dispatch(notifyError(result.Error));
|
||||
}
|
||||
};
|
||||
|
||||
const downloadAtIndex = index => {
|
||||
const url = urls[index];
|
||||
const state = getState();
|
||||
@@ -42,7 +72,7 @@ export const downloadItem = (name, type, urls, completedCallback) => {
|
||||
if (!arg.data.Success && (++index < urls.length)) {
|
||||
downloadAtIndex(index);
|
||||
} else {
|
||||
completedCallback(name, type, url, arg.data);
|
||||
downloadComplete(arg.data);
|
||||
dispatch(setDownloadEnd(arg.data));
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user