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.1KB

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