Redux changes and refactoring
This commit is contained in:
150
src/App.js
150
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,26 +40,17 @@ 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,
|
||||
}, ()=> {
|
||||
this.props.setAllowDownload(false);
|
||||
const selectedVersion = this.getSelectedVersion();
|
||||
if (selectedVersion !== 'unavailable') {
|
||||
let dependencies = [];
|
||||
@@ -67,7 +63,6 @@ class App extends IPCContainer {
|
||||
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',
|
||||
}, ()=> {
|
||||
handleDownloadUpgrade = () => {
|
||||
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,
|
||||
});
|
||||
});
|
||||
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,11 +257,6 @@ 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
|
||||
@@ -340,7 +269,6 @@ class App extends IPCContainer {
|
||||
}
|
||||
}, 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)),
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
import Box from '../UI/Box/Box';
|
||||
import {connect} from 'react-redux';
|
||||
import React from 'react';
|
||||
import './DownloadProgress.css';
|
||||
|
||||
export default props => {
|
||||
const mapStateToProps = state => {
|
||||
return {
|
||||
DownloadName: state.download.DownloadName,
|
||||
DownloadProgress: state.download.DownloadProgress,
|
||||
};
|
||||
};
|
||||
|
||||
export default connect(mapStateToProps)(props => {
|
||||
return (
|
||||
<Box dxStyle={{width: '380px', height: 'auto', padding: '5px'}}>
|
||||
<div style={{width: '100%', height: 'auto'}}>
|
||||
<h1 style={{width: '100%', textAlign: 'center'}}>{'Downloading ' + props.display}</h1>
|
||||
<h1 style={{width: '100%', textAlign: 'center'}}>{'Downloading ' + props.DownloadName}</h1>
|
||||
</div>
|
||||
<progress max={100.0} id={'download_progress'}
|
||||
style={{width: '100%'}}
|
||||
value={props.progress}/>
|
||||
value={props.DownloadProgress}/>
|
||||
</Box>);
|
||||
};
|
||||
});
|
||||
@@ -10,8 +10,8 @@ import {
|
||||
setAllowMount,
|
||||
setAutoMountProcessed,
|
||||
setBusy,
|
||||
setMountState,
|
||||
setMounted,
|
||||
setMountState,
|
||||
setProviderState
|
||||
} from '../../redux/actions/mount_actions';
|
||||
|
||||
@@ -221,7 +221,6 @@ class MountItems extends IPCContainer {
|
||||
RetrySeconds: 10,
|
||||
};
|
||||
const mountState = {
|
||||
...this.props.MountState[provider],
|
||||
AllowMount: false,
|
||||
Mounted: false,
|
||||
};
|
||||
|
||||
52
src/redux/actions/download_actions.js
Normal file
52
src/redux/actions/download_actions.js
Normal 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,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
49
src/redux/reducers/download_reducer.js
Normal file
49
src/redux/reducers/download_reducer.js
Normal file
@@ -0,0 +1,49 @@
|
||||
import {createReducer} from 'redux-starter-kit';
|
||||
import {setAllowDownload, SET_DOWNLOAD_BEGIN, setDownloadEnd, setDownloadProgress} from '../actions/download_actions';
|
||||
|
||||
const defaultDownloadState = {
|
||||
DownloadActive: false,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadingDependency: false,
|
||||
DownloadName: '',
|
||||
DownloadType: null,
|
||||
DownloadingRelease: false,
|
||||
DownloadResult: null,
|
||||
DownloadingUpgrade: false
|
||||
};
|
||||
|
||||
export const downloadReducer = createReducer({
|
||||
...defaultDownloadState,
|
||||
AllowDownload: false,
|
||||
}, {
|
||||
[setAllowDownload]: (state, action) => {
|
||||
return {
|
||||
...state,
|
||||
AllowDownload: action.payload,
|
||||
};
|
||||
},
|
||||
[SET_DOWNLOAD_BEGIN]: (state, action) => {
|
||||
return {
|
||||
...state,
|
||||
DownloadActive: true,
|
||||
DownloadName: action.payload.name,
|
||||
DownloadProgress: 0.0,
|
||||
DownloadResult: null,
|
||||
DownloadType: action.payload.type,
|
||||
DownloadURL: action.payload.url,
|
||||
}
|
||||
},
|
||||
[setDownloadEnd]: (state, action) => {
|
||||
return {
|
||||
...state,
|
||||
...defaultDownloadState,
|
||||
DownloadResult: action.payload,
|
||||
};
|
||||
},
|
||||
[setDownloadProgress]: (state, action) => {
|
||||
return {
|
||||
...state,
|
||||
DownloadProgress: action.payload,
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -2,10 +2,12 @@ import {configureStore, getDefaultMiddleware} from 'redux-starter-kit';
|
||||
import {createCommonReducer} from '../reducers/common_reducer';
|
||||
import {mountReducer} from '../reducers/mount_reducer';
|
||||
import {releaseVersionReducer} from '../reducers/release_version_reducer';
|
||||
import {downloadReducer} from '../reducers/download_reducer';
|
||||
|
||||
export default function createAppStore(platform, appPlatform, version) {
|
||||
const reducer = {
|
||||
common: createCommonReducer(platform, appPlatform, version),
|
||||
download: downloadReducer,
|
||||
mounts: mountReducer,
|
||||
relver: releaseVersionReducer,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user