Refactoring
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import * as Constants from '../../constants';
|
||||
import {createAction} from 'redux-starter-kit';
|
||||
import {getIPCRenderer} from '../../utils';
|
||||
import {
|
||||
getIPCRenderer,
|
||||
getSelectedVersionFromState
|
||||
} from '../../utils';
|
||||
import {notifyError} from './error_actions';
|
||||
import {setAllowDownload} from './download_actions';
|
||||
import {
|
||||
@@ -55,7 +58,26 @@ export const checkInstalled = (dependencies, version) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const installDependency = (source, url, completedCallback) => {
|
||||
export const checkVersionInstalled = () => {
|
||||
return (dispatch, getState) => {
|
||||
const state = getState();
|
||||
|
||||
dispatch(setAllowDownload(false));
|
||||
const selectedVersion = getSelectedVersionFromState(state);
|
||||
if (selectedVersion && (selectedVersion !== 'unavailable')) {
|
||||
let dependencies = [];
|
||||
if (state.relver.LocationsLookup[selectedVersion] && state.relver.LocationsLookup[selectedVersion].dependencies) {
|
||||
dependencies = state.relver.LocationsLookup[selectedVersion].dependencies;
|
||||
}
|
||||
dispatch(checkInstalled(dependencies, selectedVersion));
|
||||
} else {
|
||||
dispatch(setInstalledVersion('none'));
|
||||
dispatch(setAllowDownload(true));
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
export const installDependency = (source, url) => {
|
||||
return (dispatch, getState) => {
|
||||
if (ipcRenderer && !getState().install.InstallActive) {
|
||||
dispatch(setInstallActive(Constants.INSTALL_TYPES.Dependency));
|
||||
@@ -67,7 +89,7 @@ export const installDependency = (source, url, completedCallback) => {
|
||||
FilePath: source,
|
||||
});
|
||||
dispatch(setInstallComplete(result));
|
||||
completedCallback(source, url, result);
|
||||
dispatch(checkVersionInstalled());
|
||||
};
|
||||
|
||||
if (result.Success && source.toLowerCase().endsWith('.dmg')) {
|
||||
@@ -100,18 +122,19 @@ export const installDependency = (source, url, completedCallback) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const installRelease = (source, version, completedCallback) => {
|
||||
export const installRelease = source => {
|
||||
return (dispatch, getState) => {
|
||||
if (ipcRenderer && !getState().install.InstallActive) {
|
||||
dispatch(setInstallActive(Constants.INSTALL_TYPES.Release));
|
||||
|
||||
const version = getSelectedVersionFromState(getState());
|
||||
const extractReleaseComplete = (event, arg) => {
|
||||
ipcRenderer.send(Constants.IPC_Delete_File, {
|
||||
FilePath: source,
|
||||
});
|
||||
|
||||
dispatch(setInstallComplete(arg.data));
|
||||
completedCallback(source, version, arg.data);
|
||||
dispatch(checkVersionInstalled());
|
||||
};
|
||||
|
||||
ipcRenderer.once(Constants.IPC_Extract_Release_Complete, extractReleaseComplete);
|
||||
@@ -123,19 +146,25 @@ export const installRelease = (source, version, completedCallback) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const installUpgrade = (source, sha256, signature, skipVerification, completedCallback) => {
|
||||
export const installUpgrade = (source, sha256, signature, skipVerification) => {
|
||||
return (dispatch, getState) => {
|
||||
if (ipcRenderer && !getState().install.InstallActive) {
|
||||
dispatch(setInstallActive(Constants.INSTALL_TYPES.Upgrade));
|
||||
dispatch(setApplicationReady(false));
|
||||
|
||||
const installUpgradeComplete = (event, arg) => {
|
||||
if (arg.data.Success) {
|
||||
const result = arg.data;
|
||||
if (result.Success) {
|
||||
dispatch(shutdownApplication());
|
||||
} else {
|
||||
dispatch(setApplicationReady(true));
|
||||
dispatch(setInstallComplete(arg.data));
|
||||
completedCallback(source, arg.data);
|
||||
dispatch(setInstallComplete(result));
|
||||
dispatch(notifyError(result.Error, false, () => {
|
||||
// TODO Prompt to verify
|
||||
if (result.AllowSkipVerification) {
|
||||
dispatch(installUpgrade(source, sha256, signature, true));
|
||||
}
|
||||
}, false));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user