diff --git a/src/App.js b/src/App.js
index 5a99932..baf8e30 100644
--- a/src/App.js
+++ b/src/App.js
@@ -17,17 +17,22 @@ import UpgradeIcon from './components/UpgradeIcon/UpgradeIcon';
import UpgradeUI from './components/UpgradeUI/UpgradeUI';
import {setProviderState} from './redux/actions/mount_actions';
import {detectUIUpgrade, loadReleases, setActiveRelease, setDismissUIUpgrade, setReleaseUpgradeAvailable} from './redux/actions/release_version_actions';
+import {downloadItem, setAllowDownload} from './redux/actions/download_actions';
const Constants = require('./constants');
const Scheduler = require('node-schedule');
+const DownloadTypes = {
+ Dependency: 'dependency',
+ Release: 'release',
+ Upgrade: 'upgrade',
+};
+
class App extends IPCContainer {
constructor(props) {
super(props);
this.setRequestHandler(Constants.IPC_Check_Installed_Reply, this.onCheckInstalledReply);
- this.setRequestHandler(Constants.IPC_Download_File_Complete, this.onDownloadFileComplete);
- this.setRequestHandler(Constants.IPC_Download_File_Progress, this.onDownloadFileProgress);
this.setRequestHandler(Constants.IPC_Extract_Release_Complete, this.onExtractReleaseComplete);
this.setRequestHandler(Constants.IPC_Get_State_Reply, this.onGetStateReply);
this.setRequestHandler(Constants.IPC_Install_Dependency_Reply, this.onInstallDependencyReply);
@@ -35,39 +40,29 @@ class App extends IPCContainer {
}
state = {
- AllowDownload: false,
DisplayError: false,
Error: null,
ErrorAction: null,
ErrorCritical: false,
- DownloadActive: false,
- DownloadProgress: 0.0,
- DownloadingDependency: false,
- DownloadName: '',
- DownloadingRelease: false,
- DownloadingUpgrade: false,
ExtractActive: false,
MissingDependencies: [],
InstalledVersion: 'none',
};
checkVersionInstalled = () => {
- this.setState({
- AllowDownload: false,
- }, ()=> {
- const selectedVersion = this.getSelectedVersion();
- if (selectedVersion !== 'unavailable') {
- let dependencies = [];
- if (this.props.LocationsLookup[selectedVersion] && this.props.LocationsLookup[selectedVersion].dependencies) {
- dependencies = this.props.LocationsLookup[selectedVersion].dependencies;
- }
-
- this.sendRequest(Constants.IPC_Check_Installed, {
- Dependencies: dependencies,
- Version: selectedVersion,
- });
+ this.props.setAllowDownload(false);
+ const selectedVersion = this.getSelectedVersion();
+ if (selectedVersion !== 'unavailable') {
+ let dependencies = [];
+ if (this.props.LocationsLookup[selectedVersion] && this.props.LocationsLookup[selectedVersion].dependencies) {
+ dependencies = this.props.LocationsLookup[selectedVersion].dependencies;
}
- });
+
+ this.sendRequest(Constants.IPC_Check_Installed, {
+ Dependencies: dependencies,
+ Version: selectedVersion,
+ });
+ }
};
closeErrorDisplay = () => {
@@ -121,14 +116,6 @@ class App extends IPCContainer {
Version: selectedVersion,
});
}
-
- this.setState({
- DownloadActive: false,
- DownloadProgress: 0.0,
- DownloadingRelease: false,
- ExtractActive: data.Success,
- DownloadName: '',
- });
};
detectUpgrades = () => {
@@ -144,46 +131,20 @@ class App extends IPCContainer {
this.props.VersionLookup[Constants.RELEASE_TYPES[this.props.Release]][this.props.ReleaseVersion];
};
- handleDependencyDownload = (url) => {
- this.setState({
- DownloadActive: true,
- DownloadingDependency: true,
- DownloadName: this.extractFileNameFromURL(url),
- }, ()=> {
- this.sendRequest(Constants.IPC_Download_File, {
- Filename: this.state.DownloadName,
- URL: url,
- });
- });
+ handleDownloadDependency = url => {
+ this.props.downloadItem(this.extractFileNameFromURL(url), DownloadTypes.Dependency, url, this.onDownloadFileComplete);
};
- handleReleaseDownload = () => {
+ handleDownloadRelease = () => {
const selectedVersion = this.getSelectedVersion();
const fileName = selectedVersion + '.zip';
- this.setState({
- DownloadActive: true,
- DownloadingRelease: true,
- DownloadName: fileName,
- }, () => {
- this.sendRequest(Constants.IPC_Download_File, {
- Filename: this.state.DownloadName,
- URL: this.props.LocationsLookup[selectedVersion].urls[0],
- });
- });
+ this.props.downloadItem(fileName, DownloadTypes.Release, this.props.LocationsLookup[selectedVersion].urls[0], this.onDownloadFileComplete);
};
- handleUIDownload = () => {
- this.setState({
- DownloadActive: true,
- DownloadingUpgrade: true,
- DownloadName: 'UI Upgrade',
- }, ()=> {
- const url = this.props.UpgradeData.urls[0];
- this.sendRequest(Constants.IPC_Download_File, {
- Filename: this.props.Platform === 'win32' ? 'upgrade.exe' : this.extractFileNameFromURL(url),
- URL: url,
- });
- });
+ handleDownloadUpgrade = () => {
+ const url = this.props.UpgradeData.urls[0];
+ const name = this.props.Platform === 'win32' ? 'upgrade.exe' : this.extractFileNameFromURL(url);
+ this.props.downloadItem(name, DownloadTypes.Upgrade, url, this.onDownloadFileComplete);
};
installDependency = data => {
@@ -193,13 +154,6 @@ class App extends IPCContainer {
URL: data.URL,
});
}
-
- this.setState({
- DownloadActive: false,
- DownloadProgress: 0.0,
- DownloadingDependency: data.Success,
- DownloadName: '',
- });
};
installUpgrade = data => {
@@ -212,13 +166,6 @@ class App extends IPCContainer {
SkipVerification: !!data.SkipVerification,
Source: data.Destination,
});
- } else {
- this.setState({
- DownloadActive: false,
- DownloadProgress: 0.0,
- DownloadingUpgrade: false,
- DownloadName: '',
- });
}
};
@@ -238,10 +185,8 @@ class App extends IPCContainer {
}
}
this.props.setReleaseUpgradeAvailable(upgradeAvailable);
-
+ this.props.setAllowDownload(true);
this.setState({
- AllowDownload: true,
- DownloadingDependency: false,
MissingDependencies: arg.data.Dependencies,
InstalledVersion: installedVersion,
});
@@ -254,28 +199,17 @@ class App extends IPCContainer {
}
};
- onDownloadFileComplete = (event, arg) => {
- if (this.state.DownloadingRelease) {
- this.extractRelease(arg.data);
- } else if (this.state.DownloadingDependency) {
- this.installDependency(arg.data);
- } else if (this.state.DownloadingUpgrade) {
- this.installUpgrade(arg.data);
- } else {
- this.setState({
- DownloadActive: false,
- DownloadProgress: 0.0,
- DownloadName: '',
- });
+ onDownloadFileComplete = (name, type, url, result) => {
+ switch (type) {
+ case DownloadTypes.Dependency: this.installDependency(result); break;
+ case DownloadTypes.Release: this.extractRelease(result); break;
+ case DownloadTypes.Upgrade: this.installUpgrade(result); break;
+ default:
+ this.setErrorState('Unknown download type: ' + type, null, false);
+ break;
}
};
- onDownloadFileProgress = (event, arg) => {
- this.setState({
- DownloadProgress: arg.data.Progress,
- });
- };
-
onExtractReleaseComplete = (event, arg) => {
this.sendRequest(Constants.IPC_Delete_File, {
FilePath: arg.data.Source,
@@ -323,24 +257,18 @@ class App extends IPCContainer {
FilePath: arg.data.Source,
});
- this.setState({
- DownloadActive: false,
- DownloadProgress: 0.0,
- DownloadName: '',
- }, () => {
- if (!arg.data.Success) {
- this.setErrorState(arg.data.Error, () => {
- // TODO Prompt to verify
- if (arg.data.AllowSkipVerification) {
- this.installUpgrade( {
- SkipVerification: true,
- Source: arg.data.Source,
- Success: true,
- });
- }
- }, false);
- }
- });
+ if (!arg.data.Success) {
+ this.setErrorState(arg.data.Error, () => {
+ // TODO Prompt to verify
+ if (arg.data.AllowSkipVerification) {
+ this.installUpgrade( {
+ SkipVerification: true,
+ Source: arg.data.Source,
+ Success: true,
+ });
+ }
+ }, false);
+ }
};
saveState = () => {
@@ -398,9 +326,9 @@ class App extends IPCContainer {
render() {
const selectedVersion = this.getSelectedVersion();
- const downloadEnabled = this.state.AllowDownload &&
+ const downloadEnabled = this.props.AllowDownload &&
!this.props.MountsBusy &&
- !this.state.DownloadActive &&
+ !this.props.DownloadActive &&
(selectedVersion !== 'unavailable') &&
(selectedVersion !== this.state.InstalledVersion);
@@ -423,12 +351,12 @@ class App extends IPCContainer {
const showUpgrade = this.props.UpgradeAvailable &&
!this.state.DisplayError &&
!showConfig &&
- !this.state.DownloadActive &&
+ !this.props.DownloadActive &&
!this.props.UpgradeDismissed;
const showDependencies = !showUpgrade &&
missingDependencies &&
- !this.state.DownloadActive;
+ !this.props.DownloadActive;
let errorDisplay = null;
if (this.state.DisplayError) {
@@ -455,19 +383,18 @@ class App extends IPCContainer {
if (showDependencies) {
dependencyDisplay = (