Redux changes and refactoring
This commit is contained in:
@@ -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);
|
||||
}
|
||||
};
|
||||
};
|
||||
45
src/redux/actions/error_actions.js
Normal file
45
src/redux/actions/error_actions.js
Normal 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
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -76,6 +76,5 @@ export const installUpgrade = (source, sha256, signature, skipVerification, comp
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
export const setInstallActive = createAction('install/setInstallActive');
|
||||
export const setInstallComplete = createAction('install/setInstallComplete');
|
||||
|
||||
26
src/redux/reducers/error_reducer.js
Normal file
26
src/redux/reducers/error_reducer.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import {createReducer} from 'redux-starter-kit';
|
||||
import {CLEAR_ERROR, SET_ERROR_INFO} from '../actions/error_actions';
|
||||
|
||||
export const errorReducer = createReducer({
|
||||
DisplayError: false,
|
||||
ErrorCritical: false,
|
||||
ErrorStack: [],
|
||||
}, {
|
||||
[CLEAR_ERROR]: state => {
|
||||
const errorStack = (state.ErrorStack.length > 0) ? state.ErrorStack.slice(1) : [];
|
||||
return {
|
||||
...state,
|
||||
DisplayError: (errorStack.length > 0),
|
||||
ErrorStack: errorStack,
|
||||
}
|
||||
},
|
||||
[SET_ERROR_INFO]: (state, action) => {
|
||||
const errorStack = [action.payload.msg, ...state.ErrorStack];
|
||||
return {
|
||||
...state,
|
||||
DisplayError: true,
|
||||
ErrorCritical: state.ErrorCritical || action.payload.critical,
|
||||
ErrorStack: errorStack,
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1,6 +1,7 @@
|
||||
import {configureStore, getDefaultMiddleware} from 'redux-starter-kit';
|
||||
import {createCommonReducer} from '../reducers/common_reducer';
|
||||
import {downloadReducer} from '../reducers/download_reducer';
|
||||
import {errorReducer} from '../reducers/error_reducer';
|
||||
import {installReducer} from '../reducers/install_reducer';
|
||||
import {mountReducer} from '../reducers/mount_reducer';
|
||||
import {releaseVersionReducer} from '../reducers/release_version_reducer';
|
||||
@@ -9,6 +10,7 @@ export default function createAppStore(platform, appPlatform, version) {
|
||||
const reducer = {
|
||||
common: createCommonReducer(platform, appPlatform, version),
|
||||
download: downloadReducer,
|
||||
error: errorReducer,
|
||||
install: installReducer,
|
||||
mounts: mountReducer,
|
||||
relver: releaseVersionReducer,
|
||||
|
||||
Reference in New Issue
Block a user