Redux changes and refactoring

This commit is contained in:
Scott E. Graves
2019-06-07 15:34:09 -05:00
parent a326d7762f
commit 704a357dd0
5 changed files with 177 additions and 75 deletions

View File

@@ -0,0 +1,81 @@
import * as Constants from '../../constants';
import {createAction} from 'redux-starter-kit';
let ipcRenderer;
if (!process.versions.hasOwnProperty('electron')) {
ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
}
export const installDependency = (source, url, completedCallback) => {
return (dispatch, getState) => {
if (ipcRenderer && !getState().install.InstallActive) {
dispatch(setInstallActive(Constants.INSTALL_TYPES.Dependency));
const installDependencyComplete = (event, arg) => {
ipcRenderer.removeListener(Constants.IPC_Install_Dependency_Reply, installDependencyComplete);
dispatch(setInstallComplete(arg.data));
completedCallback(source, url, arg.data);
};
ipcRenderer.on(Constants.IPC_Install_Dependency_Reply, installDependencyComplete);
ipcRenderer.send(Constants.IPC_Install_Dependency, {
Source: source,
URL: url,
});
}
};
};
export const installRelease = (source, version, completedCallback) => {
return (dispatch, getState) => {
if (ipcRenderer && !getState().install.InstallActive) {
dispatch(setInstallActive(Constants.INSTALL_TYPES.Release));
const extractReleaseComplete = (event, arg) => {
ipcRenderer.removeListener(Constants.IPC_Extract_Release_Complete, extractReleaseComplete);
ipcRenderer.sendSync(Constants.IPC_Delete_File, {
FilePath: source,
});
dispatch(setInstallComplete(arg.data));
completedCallback(source, version, arg.data);
};
ipcRenderer.on(Constants.IPC_Extract_Release_Complete, extractReleaseComplete);
ipcRenderer.send(Constants.IPC_Extract_Release, {
Source: source,
Version: version,
});
}
};
};
export const installUpgrade = (source, sha256, signature, skipVerification, completedCallback) => {
return (dispatch, getState) => {
if (ipcRenderer && !getState().install.InstallActive) {
dispatch(setInstallActive(Constants.INSTALL_TYPES.Dependency));
const installUpgradeComplete = (event, arg) => {
ipcRenderer.removeListener(Constants.IPC_Install_Upgrade_Reply, installUpgradeComplete);
ipcRenderer.sendSync(Constants.IPC_Delete_File, {
FilePath: source,
});
dispatch(setInstallComplete(arg.data));
completedCallback(source, arg.data);
};
ipcRenderer.on(Constants.IPC_Install_Upgrade_Reply, installUpgradeComplete);
ipcRenderer.send(Constants.IPC_Install_Upgrade, {
Sha256: sha256,
Signature: signature,
SkipVerification: skipVerification,
Source: source,
});
}
};
};
export const setInstallActive = createAction('install/setInstallActive');
export const setInstallComplete = createAction('install/setInstallComplete');

View File

@@ -0,0 +1,25 @@
import {createReducer} from 'redux-starter-kit';
import {setInstallActive, setInstallComplete} from '../actions/install_actions';
export const installReducer = createReducer({
InstallActive: false,
InstallResult: null,
InstallType: null,
}, {
[setInstallActive]: (state, action) => {
return {
...state,
InstallActive: true,
InstallResult: null,
InstallType: action.payload,
};
},
[setInstallComplete]: (state, action) => {
return {
...state,
InstallActive: false,
InstallResult: action.payload,
InstallType: null,
}
}
});

View File

@@ -1,13 +1,15 @@
import {configureStore, getDefaultMiddleware} from 'redux-starter-kit';
import {createCommonReducer} from '../reducers/common_reducer';
import {downloadReducer} from '../reducers/download_reducer';
import {installReducer} from '../reducers/install_reducer';
import {mountReducer} from '../reducers/mount_reducer';
import {releaseVersionReducer} from '../reducers/release_version_reducer';
import {downloadReducer} from '../reducers/download_reducer';
export default function createAppStore(platform, appPlatform, version) {
const reducer = {
common: createCommonReducer(platform, appPlatform, version),
download: downloadReducer,
install: installReducer,
mounts: mountReducer,
relver: releaseVersionReducer,
};