Refactoring

This commit is contained in:
Scott E. Graves
2019-07-15 14:54:28 -05:00
parent d7759402f6
commit f006beb8d9
14 changed files with 261 additions and 355 deletions

View File

@@ -21,4 +21,26 @@ export const shutdownApplication = () => {
ipcRenderer.send(Constants.IPC_Shutdown);
}
};
};
export const saveState = () => {
return (dispatch, getState) => {
const state = getState();
if (state.common.AppReady) {
let currentState = {
Release: state.relver.Release,
Version: state.relver.Version,
};
for (const provider of Constants.PROVIDER_LIST) {
currentState[provider] = currentState.mounts.ProviderState[provider];
}
if (ipcRenderer) {
ipcRenderer.send(Constants.IPC_Save_State, {
State: currentState
});
}
}
};
};

View File

@@ -1,6 +1,12 @@
import * as Constants from '../../constants';
import {createAction} from 'redux-starter-kit';
import {getIPCRenderer} from '../../utils';
import {notifyError} from './error_actions';
import {
installDependency,
installRelease,
installUpgrade
} from './install_actions';
export const setAllowDownload = createAction('download/setAllowDownload');
@@ -19,12 +25,36 @@ export const setDownloadBegin = (name, type, url) => {
export const setDownloadEnd = createAction('download/setDownloadEnd');
export const setDownloadProgress = createAction('download/setDownloadProgress');
export const downloadItem = (name, type, urls, completedCallback) => {
export const downloadItem = (name, type, urls) => {
return (dispatch, getState) => {
if (!Array.isArray(urls)) {
urls = [urls];
}
const downloadComplete = result => {
if (result.Success) {
switch (type) {
case Constants.INSTALL_TYPES.Dependency:
dispatch(installDependency(result.Destination, result.URL));
break;
case Constants.INSTALL_TYPES.Release:
dispatch(installRelease(result.Destination));
break;
case Constants.INSTALL_TYPES.Upgrade:
//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;
dispatch(installUpgrade(result.Destination, sha256, signature, !!result.SkipVerification));
break;
default:
dispatch(notifyError('Unknown download type: ' + type));
break;
}
} else {
dispatch(notifyError(result.Error));
}
};
const downloadAtIndex = index => {
const url = urls[index];
const state = getState();
@@ -42,7 +72,7 @@ export const downloadItem = (name, type, urls, completedCallback) => {
if (!arg.data.Success && (++index < urls.length)) {
downloadAtIndex(index);
} else {
completedCallback(name, type, url, arg.data);
downloadComplete(arg.data);
dispatch(setDownloadEnd(arg.data));
}
};

View File

@@ -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));
}
};

View File

@@ -53,6 +53,7 @@ export const loadReleases = () => {
}
dispatch(setReleaseUpgradeAvailable((version !== latestVersion)));
dispatch(setApplicationReady(true));
dispatch(detectUIUpgrade());
};
axios

View File

@@ -16,7 +16,7 @@ const versionLookup = Constants.RELEASE_TYPES.map(k=> {
export const releaseVersionReducer = createReducer({
InstalledVersion: 'none',
LocationsLookup: {},
Release: 1,
Release: 0,
ReleaseUpgradeAvailable: false,
UpgradeAvailable: false,
UpgradeData: null,