Refactoring
This commit is contained in:
200
src/App.js
200
src/App.js
@@ -5,81 +5,51 @@ import Configuration from './containers/Configuration/Configuration';
|
||||
import {connect} from 'react-redux';
|
||||
import DependencyList from './components/DependencyList/DependencyList';
|
||||
import DownloadProgress from './components/DownloadProgress/DownloadProgress';
|
||||
import {extractFileNameFromURL} from './utils';
|
||||
import ErrorDetails from './components/ErrorDetails/ErrorDetails';
|
||||
import Grid from './components/UI/Grid/Grid';
|
||||
import IPCContainer from './containers/IPCContainer/IPCContainer';
|
||||
import Loading from './components/UI/Loading/Loading';
|
||||
import Modal from './components/UI/Modal/Modal';
|
||||
import MountItems from './containers/MountItems/MountItems';
|
||||
import {notifyError} from './redux/actions/error_actions';
|
||||
import ReleaseVersionDisplay from './components/ReleaseVersionDisplay/ReleaseVersionDisplay';
|
||||
import {setProviderState} from './redux/actions/mount_actions';
|
||||
import Text from './components/UI/Text/Text';
|
||||
import UpgradeIcon from './components/UpgradeIcon/UpgradeIcon';
|
||||
import UpgradeUI from './components/UpgradeUI/UpgradeUI';
|
||||
import {checkVersionInstalled} from './redux/actions/install_actions';
|
||||
import {
|
||||
downloadItem,
|
||||
setAllowDownload
|
||||
} from './redux/actions/download_actions';
|
||||
import {
|
||||
checkInstalled,
|
||||
installDependency,
|
||||
installRelease,
|
||||
installUpgrade
|
||||
} from './redux/actions/install_actions';
|
||||
import {
|
||||
detectUIUpgrade,
|
||||
loadReleases,
|
||||
setActiveRelease,
|
||||
setDismissUIUpgrade,
|
||||
setInstalledVersion,
|
||||
setReleaseUpgradeAvailable
|
||||
setDismissUIUpgrade
|
||||
} from './redux/actions/release_version_actions';
|
||||
import {saveState} from './redux/actions/common_actions';
|
||||
|
||||
const Constants = require('./constants');
|
||||
const Scheduler = require('node-schedule');
|
||||
|
||||
class App extends IPCContainer {
|
||||
checkVersionInstalled = () => {
|
||||
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.props.checkInstalled(dependencies, selectedVersion);
|
||||
} else {
|
||||
this.props.setInstalledVersion('none');
|
||||
this.props.setAllowDownload(true);
|
||||
}
|
||||
};
|
||||
|
||||
_isMounted = false;
|
||||
|
||||
componentDidMount() {
|
||||
this._isMounted = true;
|
||||
this.scheduledUpdateJob = Scheduler.scheduleJob('23 11 * * *', this.updateCheckScheduledJob);
|
||||
this.detectUpgrades();
|
||||
const detectUpgrades = () => {
|
||||
if (this.props.AppPlatform !== 'unknown') {
|
||||
this.props.loadReleases();
|
||||
}
|
||||
};
|
||||
this.scheduledUpdateJob = Scheduler.scheduleJob('23 11 * * *', detectUpgrades);
|
||||
detectUpgrades();
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if ((prevProps.Release !== this.props.Release) ||
|
||||
(prevProps.ReleaseVersion !== this.props.ReleaseVersion) ||
|
||||
(prevProps.VersionLookup !== this.props.VersionLookup)) {
|
||||
this.saveState();
|
||||
this.checkVersionInstalled();
|
||||
this.props.saveState();
|
||||
this.props.checkVersionInstalled();
|
||||
} else if (Object.keys(this.props.ProviderState).filter(k=> {
|
||||
return this.props.ProviderState[k] !== prevProps.ProviderState[k];
|
||||
}).length > 0) {
|
||||
this.saveState();
|
||||
this.props.saveState();
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this._isMounted = false;
|
||||
Scheduler.cancelJob(this.scheduledUpdateJob);
|
||||
super.componentWillUnmount();
|
||||
}
|
||||
@@ -89,129 +59,12 @@ class App extends IPCContainer {
|
||||
return condition ? (<Modal {...modalProps}>{jsx}</Modal>) : null;
|
||||
};
|
||||
|
||||
detectUpgrades = () => {
|
||||
if (this.props.AppPlatform !== 'unknown') {
|
||||
this.props.loadReleases();
|
||||
this.props.detectUIUpgrade();
|
||||
}
|
||||
};
|
||||
|
||||
getSelectedVersion = () => {
|
||||
return (this.props.ReleaseVersion === -1) ?
|
||||
'unavailable' :
|
||||
this.props.VersionLookup[Constants.RELEASE_TYPES[this.props.Release]][this.props.ReleaseVersion];
|
||||
};
|
||||
|
||||
handleDownloadDependency = url => {
|
||||
this.props.downloadItem(extractFileNameFromURL(url), Constants.INSTALL_TYPES.Dependency, url, this.onDownloadFileComplete);
|
||||
};
|
||||
|
||||
handleDownloadRelease = () => {
|
||||
const selectedVersion = this.getSelectedVersion();
|
||||
const fileName = selectedVersion + '.zip';
|
||||
this.props.downloadItem(fileName, Constants.INSTALL_TYPES.Release, this.props.LocationsLookup[selectedVersion].urls, this.onDownloadFileComplete);
|
||||
};
|
||||
|
||||
handleDownloadUpgrade = () => {
|
||||
const name = (this.props.Platform === 'win32') ?
|
||||
'upgrade.exe' :
|
||||
(this.props.Platform === 'darwin') ?
|
||||
'upgrade.dmg' :
|
||||
'repertory-ui_' + this.props.UpgradeVersion + '_linux_x86_64.AppImage';
|
||||
this.props.downloadItem(name, Constants.INSTALL_TYPES.Upgrade, this.props.UpgradeData.urls, this.onDownloadFileComplete);
|
||||
};
|
||||
|
||||
installDependency = result => {
|
||||
if (result.Success) {
|
||||
this.props.installDependency(result.Destination, result.URL, this.onInstallDependencyComplete);
|
||||
}
|
||||
};
|
||||
|
||||
installRelease = result => {
|
||||
if (result.Success) {
|
||||
const selectedVersion = this.getSelectedVersion();
|
||||
this.props.installRelease(result.Destination, selectedVersion, () => {
|
||||
if (this._isMounted) {
|
||||
this.checkVersionInstalled();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
installUpgrade = result => {
|
||||
if (result.Success) {
|
||||
//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;
|
||||
this.props.installUpgrade(result.Destination, sha256, signature, !!result.SkipVerification, this.onInstallUpgradeComplete);
|
||||
}
|
||||
};
|
||||
|
||||
onDownloadFileComplete = (name, type, url, result) => {
|
||||
if (this._isMounted) {
|
||||
switch (type) {
|
||||
case Constants.INSTALL_TYPES.Dependency:
|
||||
this.installDependency(result);
|
||||
break;
|
||||
case Constants.INSTALL_TYPES.Release:
|
||||
this.installRelease(result);
|
||||
break;
|
||||
case Constants.INSTALL_TYPES.Upgrade:
|
||||
this.installUpgrade(result);
|
||||
break;
|
||||
default:
|
||||
this.props.notifyError('Unknown download type: ' + type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onInstallDependencyComplete = () => {
|
||||
if (this._isMounted) {
|
||||
this.checkVersionInstalled();
|
||||
}
|
||||
};
|
||||
|
||||
onInstallUpgradeComplete = (source, result) => {
|
||||
if (this._isMounted && !result.Success) {
|
||||
this.props.notifyError(result.Error, false,() => {
|
||||
if (this._isMounted) {
|
||||
// TODO Prompt to verify
|
||||
if (result.AllowSkipVerification) {
|
||||
this.installUpgrade({
|
||||
SkipVerification: true,
|
||||
Source: source,
|
||||
Success: true,
|
||||
});
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
};
|
||||
|
||||
saveState = () => {
|
||||
if (this.props.AppReady) {
|
||||
let state = {
|
||||
Release: this.props.Release,
|
||||
Version: this.props.ReleaseVersion,
|
||||
};
|
||||
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
state[provider] = this.props.ProviderState[provider];
|
||||
}
|
||||
|
||||
this.sendRequest(Constants.IPC_Save_State, {
|
||||
State: state
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
updateCheckScheduledJob = () => {
|
||||
if (this.props.AppPlatform !== 'unknown') {
|
||||
this.detectUpgrades();
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const selectedVersion = this.getSelectedVersion();
|
||||
|
||||
@@ -251,10 +104,10 @@ class App extends IPCContainer {
|
||||
!this.props.DownloadActive;
|
||||
|
||||
const configDisplay = this.createModalConditionally(showConfig, <Configuration version={selectedVersion} />);
|
||||
const dependencyDisplay = this.createModalConditionally(showDependencies, <DependencyList onDownload={this.handleDownloadDependency}/>);
|
||||
const dependencyDisplay = this.createModalConditionally(showDependencies, <DependencyList/>);
|
||||
const downloadDisplay = this.createModalConditionally(this.props.DownloadActive, <DownloadProgress/>);
|
||||
const errorDisplay = this.createModalConditionally(this.props.DisplayError, <ErrorDetails/>, true);
|
||||
const upgradeDisplay = this.createModalConditionally(showUpgrade, <UpgradeUI upgrade={this.handleDownloadUpgrade}/>);
|
||||
const upgradeDisplay = this.createModalConditionally(showUpgrade, <UpgradeUI/>);
|
||||
|
||||
let mainContent = [];
|
||||
if (this.props.AppReady) {
|
||||
@@ -262,8 +115,8 @@ class App extends IPCContainer {
|
||||
mainContent.push((
|
||||
<div key={'rvd_' + key++}
|
||||
style={{height: '32%'}}>
|
||||
<ReleaseVersionDisplay downloadClicked={this.handleDownloadRelease}
|
||||
downloadDisabled={!downloadEnabled}/>
|
||||
<ReleaseVersionDisplay downloadDisabled={!downloadEnabled}
|
||||
version={selectedVersion}/>
|
||||
</div>
|
||||
));
|
||||
|
||||
@@ -327,21 +180,16 @@ const mapStateToProps = state => {
|
||||
DisplayConfiguration: state.mounts.DisplayConfiguration,
|
||||
DisplayError: state.error.DisplayError,
|
||||
DownloadActive: state.download.DownloadActive,
|
||||
DownloadType: state.download.DownloadType,
|
||||
InstallActive: state.install.InstallActive,
|
||||
InstallType: state.install.InstallType,
|
||||
InstalledVersion: state.relver.InstalledVersion,
|
||||
LocationsLookup: state.relver.LocationsLookup,
|
||||
MissingDependencies: state.install.MissingDependencies,
|
||||
MountsBusy: state.mounts.MountsBusy,
|
||||
Platform: state.common.Platform,
|
||||
ProviderState: state.mounts.ProviderState,
|
||||
Release: state.relver.Release,
|
||||
ReleaseVersion: state.relver.Version,
|
||||
UpgradeAvailable: state.relver.UpgradeAvailable,
|
||||
UpgradeData: state.relver.UpgradeData,
|
||||
UpgradeDismissed: state.relver.UpgradeDismissed,
|
||||
UpgradeVersion: state.relver.UpgradeVersion,
|
||||
Version: state.common.Version,
|
||||
VersionLookup: state.relver.VersionLookup,
|
||||
};
|
||||
@@ -349,20 +197,10 @@ const mapStateToProps = state => {
|
||||
|
||||
const mapDispatchToProps = dispatch => {
|
||||
return {
|
||||
checkInstalled: (dependencies, version) => dispatch(checkInstalled(dependencies, version)),
|
||||
detectUIUpgrade: () => dispatch(detectUIUpgrade()),
|
||||
downloadItem: (name, type, url, completedCallback) => dispatch(downloadItem(name, type, url, completedCallback)),
|
||||
installDependency: (source, url, completedCallback) => dispatch(installDependency(source, url, completedCallback)),
|
||||
installRelease: (source, version, completedCallback) => dispatch(installRelease(source, version, completedCallback)),
|
||||
installUpgrade: (source, sha256, signature, skipVerification, completedCallback) => dispatch(installUpgrade(source, sha256, signature, skipVerification, completedCallback)),
|
||||
checkVersionInstalled: () => dispatch(checkVersionInstalled()),
|
||||
loadReleases: ()=> dispatch(loadReleases()),
|
||||
notifyError: (msg, critical, callback) => dispatch(notifyError(msg, critical, callback)),
|
||||
setActiveRelease: (release, version) => dispatch(setActiveRelease(release, version)),
|
||||
setAllowDownload: allow => dispatch(setAllowDownload(allow)),
|
||||
saveState: () => dispatch(saveState()),
|
||||
setDismissUIUpgrade: dismiss => dispatch(setDismissUIUpgrade(dismiss)),
|
||||
setInstalledVersion: version => dispatch(setInstalledVersion(version)),
|
||||
setProviderState: (provider, state) => dispatch(setProviderState(provider, state)),
|
||||
setReleaseUpgradeAvailable: available => dispatch(setReleaseUpgradeAvailable(available)),
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user