Redux changes and refactoring

This commit is contained in:
Scott E. Graves
2019-06-07 16:32:18 -05:00
parent 5c931bb66d
commit 7f3e90773e
9 changed files with 158 additions and 69 deletions

View File

@@ -1,3 +1,26 @@
import * as Constants from '../../constants';
import {createAction} from 'redux-starter-kit';
export const setApplicationReady = createAction('common/setApplicationReady');
let ipcRenderer;
if (!process.versions.hasOwnProperty('electron')) {
ipcRenderer = ((window && window.require) ? window.require('electron').ipcRenderer : null);
}
export const setApplicationReady = createAction('common/setApplicationReady');
export const showWindow = () => {
return dispatch => {
if (ipcRenderer) {
ipcRenderer.send(Constants.IPC_Show_Window);
}
};
};
export const shutdownApplication = () => {
return dispatch => {
dispatch(setApplicationReady(false));
if (ipcRenderer) {
ipcRenderer.send(Constants.IPC_Shutdown);
}
};
};

View File

@@ -0,0 +1,45 @@
import {showWindow, shutdownApplication} from './common_actions';
let ErrorActions = [];
export const CLEAR_ERROR = 'error/clearError';
export const clearError = () => {
return {
type: CLEAR_ERROR,
payload: null,
};
};
export const dismissError = () => {
return (dispatch, getState) => {
dispatch(clearError());
const errorAction = ErrorActions[0];
ErrorActions = ErrorActions.splice(1);
if (errorAction) {
errorAction();
}
if (getState().error.ErrorCritical) {
dispatch(shutdownApplication());
}
};
};
export const notifyError = (msg, critical, callback) => {
return dispatch => {
ErrorActions = [callback, ...ErrorActions];
msg = msg.toString();
dispatch(setErrorInfo(msg, critical));
dispatch(showWindow());
};
};
export const SET_ERROR_INFO = 'error/setErrorInfo';
export const setErrorInfo = (msg, critical) => {
return {
type: SET_ERROR_INFO,
payload: {
msg,
critical
}
}
};

View File

@@ -76,6 +76,5 @@ export const installUpgrade = (source, sha256, signature, skipVerification, comp
};
};
export const setInstallActive = createAction('install/setInstallActive');
export const setInstallComplete = createAction('install/setInstallComplete');