Refactoring
This commit is contained in:
63
src/App.js
63
src/App.js
@@ -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) {
|
||||
@@ -144,34 +135,6 @@ class App extends IPCContainer {
|
||||
}
|
||||
};
|
||||
|
||||
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()) {
|
||||
switch (type) {
|
||||
@@ -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)),
|
||||
|
||||
19
src/index.js
19
src/index.js
@@ -6,6 +6,8 @@ import createAppStore from './redux/store/createAppStore';
|
||||
import {getIPCRenderer} from './utils';
|
||||
import packageJson from '../package.json';
|
||||
import {Provider} from 'react-redux';
|
||||
import {setActiveRelease} from './redux/actions/release_version_actions';
|
||||
import {setProviderState} from './redux/actions/mount_actions';
|
||||
import * as serviceWorker from './serviceWorker';
|
||||
|
||||
const Constants = require('./constants');
|
||||
@@ -19,6 +21,21 @@ if (ipcRenderer) {
|
||||
}
|
||||
|
||||
const store = createAppStore(arg.Platform, arg.AppPlatform, packageJson.version);
|
||||
ipcRenderer.on(Constants.IPC_Get_State_Reply, (event, arg) => {
|
||||
if (arg.data) {
|
||||
store.dispatch(setActiveRelease(arg.data.Release, arg.data.Version));
|
||||
|
||||
for (const provider of Constants.PROVIDER_LIST) {
|
||||
let state = arg.data[provider] || this.props.ProviderState[provider];
|
||||
if (state.AutoMount === undefined) {
|
||||
state['AutoMount'] = false;
|
||||
}
|
||||
if (state.AutoRestart === undefined) {
|
||||
state['AutoRestart'] = false;
|
||||
}
|
||||
store.dispatch(setProviderState(provider, state));
|
||||
}
|
||||
}
|
||||
ReactDOM.render((
|
||||
<Provider store={store}>
|
||||
<App/>
|
||||
@@ -26,6 +43,8 @@ if (ipcRenderer) {
|
||||
), document.getElementById('root'));
|
||||
serviceWorker.unregister();
|
||||
});
|
||||
ipcRenderer.send(Constants.IPC_Get_State);
|
||||
});
|
||||
ipcRenderer.send(Constants.IPC_Get_Platform);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,57 @@
|
||||
import * as Constants from '../../constants';
|
||||
import {createAction} from 'redux-starter-kit';
|
||||
import {getIPCRenderer} from '../../utils';
|
||||
import {notifyError} from './error_actions';
|
||||
import {setAllowDownload} from './download_actions';
|
||||
import {
|
||||
setActiveRelease,
|
||||
setInstalledVersion,
|
||||
setReleaseUpgradeAvailable
|
||||
} from './release_version_actions';
|
||||
|
||||
const ipcRenderer = getIPCRenderer();
|
||||
|
||||
export const checkInstalled = (dependencies, version) => {
|
||||
return (dispatch, getState) => {
|
||||
const checkInstalledComplete = (event, arg) => {
|
||||
ipcRenderer.removeListener(Constants.IPC_Check_Installed_Reply, checkInstalledComplete);
|
||||
const result = arg.data;
|
||||
const updateState = () => {
|
||||
const installedVersion = result.Success && result.Exists ? result.Version : 'none';
|
||||
const state = getState();
|
||||
|
||||
let upgradeAvailable = false;
|
||||
if (installedVersion !== 'none') {
|
||||
const latestVersion = state.relver.VersionLookup[Constants.RELEASE_TYPES[state.relver.Release]].length - 1;
|
||||
let version = state.relver.ReleaseVersion;
|
||||
if (version === -1) {
|
||||
version = latestVersion;
|
||||
dispatch(setActiveRelease(state.relver.Release, version));
|
||||
} else {
|
||||
upgradeAvailable = version !== latestVersion;
|
||||
}
|
||||
}
|
||||
dispatch(setReleaseUpgradeAvailable(upgradeAvailable));
|
||||
dispatch(setAllowDownload(true));
|
||||
dispatch(setInstalledVersion(installedVersion));
|
||||
dispatch(setMissingDependencies(result.Dependencies));
|
||||
};
|
||||
|
||||
if (result.Success) {
|
||||
updateState();
|
||||
} else {
|
||||
dispatch(notifyError(result.Error, false, updateState));
|
||||
}
|
||||
};
|
||||
|
||||
ipcRenderer.on(Constants.IPC_Check_Installed_Reply, checkInstalledComplete);
|
||||
ipcRenderer.send(Constants.IPC_Check_Installed, {
|
||||
Dependencies: dependencies,
|
||||
Version: version,
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export const installDependency = (source, url, completedCallback) => {
|
||||
return (dispatch, getState) => {
|
||||
if (ipcRenderer && !getState().install.InstallActive) {
|
||||
|
||||
Reference in New Issue
Block a user