Redux changes and refactoring
This commit is contained in:
198
src/App.js
198
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 = (
|
||||
<Modal>
|
||||
<DependencyList allowDownload={!this.state.DownloadingDependency}
|
||||
<DependencyList allowDownload={this.props.DownloadType !== DownloadTypes.Dependency}
|
||||
dependencies={this.state.MissingDependencies}
|
||||
onDownload={this.handleDependencyDownload}/>
|
||||
onDownload={this.handleDownloadDependency}/>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
let downloadDisplay = null;
|
||||
if (this.state.DownloadActive) {
|
||||
if (this.props.DownloadActive) {
|
||||
downloadDisplay = (
|
||||
<Modal>
|
||||
<DownloadProgress display={this.state.DownloadName}
|
||||
progress={this.state.DownloadProgress}/>
|
||||
<DownloadProgress/>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -476,7 +403,7 @@ class App extends IPCContainer {
|
||||
if (showUpgrade) {
|
||||
upgradeDisplay = (
|
||||
<Modal>
|
||||
<UpgradeUI upgrade={this.handleUIDownload}/>
|
||||
<UpgradeUI upgrade={this.handleDownloadUpgrade}/>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
@@ -487,11 +414,10 @@ class App extends IPCContainer {
|
||||
mainContent.push((
|
||||
<div key={'rvd_' + key++}
|
||||
style={{height: '32%'}}>
|
||||
<ReleaseVersionDisplay disabled={this.state.DownloadActive || this.state.ExtractActive || this.props.MountsBusy}
|
||||
downloadClicked={this.handleReleaseDownload}
|
||||
<ReleaseVersionDisplay disabled={this.props.DownloadActive || this.state.ExtractActive || this.props.MountsBusy}
|
||||
downloadClicked={this.handleDownloadRelease}
|
||||
downloadDisabled={!downloadEnabled}
|
||||
releaseExtracting={this.state.ExtractActive}
|
||||
saveState={this.saveState}
|
||||
text={this.state.InstalledVersion + ' [' + this.props.AppPlatform + ']'}/>
|
||||
</div>
|
||||
));
|
||||
@@ -503,7 +429,6 @@ class App extends IPCContainer {
|
||||
allowSiaPrime={allowSiaPrime}
|
||||
noConsoleSupported={noConsoleSupported}
|
||||
errorHandler={this.setErrorState}
|
||||
saveState={this.saveState}
|
||||
version={this.state.InstalledVersion}/>
|
||||
</div>
|
||||
));
|
||||
@@ -553,9 +478,12 @@ class App extends IPCContainer {
|
||||
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
AllowDownload: state.download.AllowDownload,
|
||||
AppPlatform: state.common.AppPlatform,
|
||||
AppReady: state.common.AppReady,
|
||||
DisplayConfiguration: state.mounts.DisplayConfiguration,
|
||||
DownloadActive: state.download.DownloadActive,
|
||||
DownloadType: state.download.DownloadType,
|
||||
LocationsLookup: state.relver.LocationsLookup,
|
||||
MountsBusy: state.mounts.MountsBusy,
|
||||
Platform: state.common.Platform,
|
||||
@@ -573,8 +501,10 @@ const mapStateToProps = state => {
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
detectUIUpgrade: () => dispatch(detectUIUpgrade()),
|
||||
downloadItem: (name, type, url, callback) => dispatch(downloadItem(name, type, url, callback)),
|
||||
loadReleases: ()=> dispatch(loadReleases()),
|
||||
setActiveRelease: (release, version) => dispatch(setActiveRelease(release, version)),
|
||||
setAllowDownload: allow => dispatch(setAllowDownload(allow)),
|
||||
setDismissUIUpgrade: dismiss => dispatch(setDismissUIUpgrade(dismiss)),
|
||||
setProviderState: (provider, state) => dispatch(setProviderState(provider, state)),
|
||||
setReleaseUpgradeAvailable: available => dispatch(setReleaseUpgradeAvailable(available)),
|
||||
|
||||
Reference in New Issue
Block a user