forked from SkalskiP/make-sense
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppInitializer.ts
60 lines (54 loc) · 2.45 KB
/
AppInitializer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import {updateWindowSize} from '../../store/general/actionCreators';
import {ContextManager} from '../context/ContextManager';
import {store} from '../../index';
import {PlatformUtil} from '../../utils/PlatformUtil';
import {PlatformModel} from '../../staticModels/PlatformModel';
import {EventType} from '../../data/enums/EventType';
import {GeneralSelector} from '../../store/selectors/GeneralSelector';
import {EnvironmentUtil} from '../../utils/EnvironmentUtil';
export class AppInitializer {
public static inti():void {
AppInitializer.handleResize();
AppInitializer.detectDeviceParams();
AppInitializer.handleAccidentalPageExit();
window.addEventListener(EventType.RESIZE, AppInitializer.handleResize);
window.addEventListener(EventType.MOUSE_WHEEL, AppInitializer.disableGenericScrollZoom,{passive:false});
window.addEventListener(EventType.KEY_DOWN, AppInitializer.disableUnwantedKeyBoardBehaviour);
window.addEventListener(EventType.KEY_PRESS, AppInitializer.disableUnwantedKeyBoardBehaviour);
ContextManager.init();
}
private static handleAccidentalPageExit = () => {
window.onbeforeunload = (event) => {
const projectType = GeneralSelector.getProjectType();
if (projectType != null && EnvironmentUtil.isProd()) {
event.preventDefault();
event.returnValue = '';
}
}
};
private static handleResize = () => {
store.dispatch(updateWindowSize({
width: window.innerWidth,
height: window.innerHeight
}));
};
private static disableUnwantedKeyBoardBehaviour = (event: KeyboardEvent) => {
if (['=', '+', '-'].includes(event.key)) {
if (event.ctrlKey || (PlatformModel.isMac && event.metaKey)) {
event.preventDefault();
}
}
};
private static disableGenericScrollZoom = (event: MouseEvent) => {
if (event.ctrlKey || (PlatformModel.isMac && event.metaKey)) {
event.preventDefault();
}
};
private static detectDeviceParams = () => {
const userAgent: string = window.navigator.userAgent;
PlatformModel.mobileDeviceData = PlatformUtil.getMobileDeviceData(userAgent);
PlatformModel.isMac = PlatformUtil.isMac(userAgent);
PlatformModel.isSafari = PlatformUtil.isSafari(userAgent);
PlatformModel.isFirefox = PlatformUtil.isFirefox(userAgent);
};
}