Refactoring

This commit is contained in:
Scott E. Graves
2019-06-08 14:05:45 -05:00
parent 0e3098eb8e
commit b6b89df37b
3 changed files with 77 additions and 65 deletions

View File

@@ -23,6 +23,7 @@ import {
setAllowDownload
} from './redux/actions/download_actions';
import {
checkInstalled,
installDependency,
installRelease,
installUpgrade,
@@ -41,13 +42,6 @@ const Constants = require('./constants');
const Scheduler = require('node-schedule');
class App extends IPCContainer {
constructor(props) {
super(props);
this.setRequestHandler(Constants.IPC_Check_Installed_Reply, this.onCheckInstalledReply);
this.setRequestHandler(Constants.IPC_Get_State_Reply, this.onGetStateReply);
}
checkVersionInstalled = () => {
this.props.setAllowDownload(false);
const selectedVersion = this.getSelectedVersion();
@@ -57,18 +51,15 @@ class App extends IPCContainer {
dependencies = this.props.LocationsLookup[selectedVersion].dependencies;
}
this.sendRequest(Constants.IPC_Check_Installed, {
Dependencies: dependencies,
Version: selectedVersion,
});
this.props.checkInstalled(dependencies, selectedVersion);
} else {
this.props.setInstalledVersion('none');
}
};
componentDidMount() {
this.sendRequest(Constants.IPC_Get_State);
this.scheduledUpdateJob = Scheduler.scheduleJob('23 11 * * *', this.updateCheckScheduledJob);
this.detectUpgrades();
}
componentDidUpdate(prevProps) {
@@ -143,34 +134,6 @@ class App extends IPCContainer {
this.props.installUpgrade(result.Destination, sha256, signature, !!result.SkipVerification, this.onInstallUpgradeComplete);
}
};
onCheckInstalledReply = (event, arg) => {
const action = () => {
const installedVersion = arg.data.Success && arg.data.Exists ? arg.data.Version : 'none';
let upgradeAvailable = false;
if (installedVersion !== 'none') {
const latestVersion = this.props.VersionLookup[Constants.RELEASE_TYPES[this.props.Release]].length - 1;
let version = this.props.ReleaseVersion;
if (version === -1) {
version = latestVersion;
this.props.setActiveRelease(this.props.Release, version);
} else {
upgradeAvailable = version !== latestVersion;
}
}
this.props.setReleaseUpgradeAvailable(upgradeAvailable);
this.props.setAllowDownload(true);
this.props.setInstalledVersion(installedVersion);
this.props.setMissingDependencies(arg.data.Dependencies);
};
if (arg.data.Success) {
action();
} else {
this.props.notifyError(arg.data.Error, false, action);
}
};
onDownloadFileComplete = (name, type, url, result) => {
if (this.isMounted()) {
@@ -191,25 +154,6 @@ class App extends IPCContainer {
}
};
onGetStateReply = (event, arg) => {
if (arg.data) {
this.props.setActiveRelease(arg.data.Release, arg.data.Version);
for (const provider of Constants.PROVIDER_LIST) {
let data = arg.data[provider] || this.props.ProviderState[provider];
if (data.AutoMount === undefined) {
data['AutoMount'] = false;
}
if (data.AutoRestart === undefined) {
data['AutoRestart'] = false;
}
this.props.setProviderState(provider, data);
}
}
this.detectUpgrades();
};
onInstallDependencyComplete = (source, url, result) => {
if (this.isMounted()) {
if (result.Success && source.toLowerCase().endsWith('.dmg')) {
@@ -458,6 +402,7 @@ 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)),