You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.ts 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { AnyAction } from 'redux';
  2. import { IStore } from '../app/types';
  3. import { SET_CONFIG } from '../base/config/actionTypes';
  4. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  5. import { CAPTURE_EVENTS } from '../remote-control/actionTypes';
  6. import { disableKeyboardShortcuts, enableKeyboardShortcuts } from './actions';
  7. MiddlewareRegistry.register((store: IStore) => (next: Function) => (action: AnyAction) => {
  8. const { dispatch } = store;
  9. switch (action.type) {
  10. case CAPTURE_EVENTS:
  11. if (action.isCapturingEvents) {
  12. dispatch(disableKeyboardShortcuts());
  13. } else {
  14. dispatch(enableKeyboardShortcuts());
  15. }
  16. return next(action);
  17. case SET_CONFIG: {
  18. const result = next(action);
  19. const state = store.getState();
  20. const { disableShortcuts } = state['features/base/config'];
  21. if (disableShortcuts !== undefined) {
  22. if (disableShortcuts) {
  23. dispatch(disableKeyboardShortcuts());
  24. } else {
  25. dispatch(enableKeyboardShortcuts());
  26. }
  27. }
  28. return result;
  29. }
  30. }
  31. return next(action);
  32. });