2022-10-19 11:38:38 +00:00
|
|
|
import { AnyAction } from 'redux';
|
2017-04-01 05:52:40 +00:00
|
|
|
|
2022-10-19 11:38:38 +00:00
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
2017-04-01 05:52:40 +00:00
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
import {
|
|
|
|
CLEAR_TOOLBOX_TIMEOUT,
|
2022-09-27 07:10:28 +00:00
|
|
|
SET_FULL_SCREEN,
|
|
|
|
SET_TOOLBOX_TIMEOUT
|
2018-03-07 00:28:19 +00:00
|
|
|
} from './actionTypes';
|
|
|
|
|
2022-09-14 12:48:09 +00:00
|
|
|
import './subscriber';
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2017-04-01 05:52:40 +00:00
|
|
|
/**
|
|
|
|
* Middleware which intercepts Toolbox actions to handle changes to the
|
|
|
|
* visibility timeout of the Toolbox.
|
|
|
|
*
|
2017-07-16 08:44:07 +00:00
|
|
|
* @param {Store} store - The redux store.
|
2017-04-01 05:52:40 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
2021-07-13 06:50:08 +00:00
|
|
|
|
2017-04-01 05:52:40 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case CLEAR_TOOLBOX_TIMEOUT: {
|
|
|
|
const { timeoutID } = store.getState()['features/toolbox'];
|
|
|
|
|
2022-10-19 11:38:38 +00:00
|
|
|
clearTimeout(timeoutID ?? undefined);
|
2017-04-01 05:52:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
case SET_FULL_SCREEN:
|
|
|
|
return _setFullScreen(next, action);
|
|
|
|
|
2017-04-01 05:52:40 +00:00
|
|
|
case SET_TOOLBOX_TIMEOUT: {
|
|
|
|
const { timeoutID } = store.getState()['features/toolbox'];
|
2022-10-19 11:38:38 +00:00
|
|
|
const { handler, timeoutMS }: { handler: Function; timeoutMS: number; } = action;
|
2017-04-01 05:52:40 +00:00
|
|
|
|
2022-10-19 11:38:38 +00:00
|
|
|
clearTimeout(timeoutID ?? undefined);
|
2018-04-09 05:03:26 +00:00
|
|
|
action.timeoutID = setTimeout(handler, timeoutMS);
|
2017-04-01 05:52:40 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2017-07-24 13:56:57 +00:00
|
|
|
}
|
|
|
|
|
2017-04-01 05:52:40 +00:00
|
|
|
return next(action);
|
|
|
|
});
|
2017-07-16 08:44:07 +00:00
|
|
|
|
2019-03-19 15:42:25 +00:00
|
|
|
type DocumentElement = {
|
2022-10-19 11:38:38 +00:00
|
|
|
mozRequestFullScreen?: Function;
|
|
|
|
requestFullscreen?: Function;
|
|
|
|
webkitRequestFullscreen?: Function;
|
|
|
|
};
|
2019-03-19 15:42:25 +00:00
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Makes an external request to enter or exit full screen mode.
|
|
|
|
*
|
|
|
|
* @param {Dispatch} next - The redux dispatch function to dispatch the
|
|
|
|
* specified action to the specified store.
|
|
|
|
* @param {Action} action - The redux action SET_FULL_SCREEN which is being
|
|
|
|
* dispatched in the specified store.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The value returned by {@code next(action)}.
|
|
|
|
*/
|
2022-10-19 11:38:38 +00:00
|
|
|
function _setFullScreen(next: Function, action: AnyAction) {
|
2021-11-04 21:10:43 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
if (typeof APP === 'object') {
|
|
|
|
const { fullScreen } = action;
|
|
|
|
|
|
|
|
if (fullScreen) {
|
2019-03-19 15:42:25 +00:00
|
|
|
const documentElement: DocumentElement
|
|
|
|
= document.documentElement || {};
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
if (typeof documentElement.requestFullscreen === 'function') {
|
|
|
|
documentElement.requestFullscreen();
|
|
|
|
} else if (
|
|
|
|
typeof documentElement.mozRequestFullScreen === 'function') {
|
|
|
|
documentElement.mozRequestFullScreen();
|
|
|
|
} else if (
|
|
|
|
typeof documentElement.webkitRequestFullscreen === 'function') {
|
|
|
|
documentElement.webkitRequestFullscreen();
|
|
|
|
}
|
2018-10-03 09:29:19 +00:00
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
return result;
|
|
|
|
}
|
2018-10-03 09:29:19 +00:00
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
if (typeof document.exitFullscreen === 'function') {
|
|
|
|
document.exitFullscreen();
|
2018-10-03 09:29:19 +00:00
|
|
|
|
2022-10-19 11:38:38 +00:00
|
|
|
// @ts-ignore
|
2021-11-04 21:10:43 +00:00
|
|
|
} else if (typeof document.mozCancelFullScreen === 'function') {
|
2022-10-19 11:38:38 +00:00
|
|
|
// @ts-ignore
|
2021-11-04 21:10:43 +00:00
|
|
|
document.mozCancelFullScreen();
|
2018-10-03 09:29:19 +00:00
|
|
|
|
2022-10-19 11:38:38 +00:00
|
|
|
// @ts-ignore
|
2021-11-04 21:10:43 +00:00
|
|
|
} else if (typeof document.webkitExitFullscreen === 'function') {
|
2022-10-19 11:38:38 +00:00
|
|
|
// @ts-ignore
|
2021-11-04 21:10:43 +00:00
|
|
|
document.webkitExitFullscreen();
|
2018-03-07 00:28:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-04 21:10:43 +00:00
|
|
|
return result;
|
2018-03-07 00:28:19 +00:00
|
|
|
}
|