-
Notifications
You must be signed in to change notification settings - Fork 973
Expand file tree
/
Copy pathindex.tsx
More file actions
130 lines (107 loc) · 3.83 KB
/
index.tsx
File metadata and controls
130 lines (107 loc) · 3.83 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import './util/handleError';
import './util/setupServiceWorker';
import './global/init';
import TeactDOM from './lib/teact/teact-dom';
import {
getActions, getGlobal,
} from './global';
import {
DEBUG, STRICTERDOM_ENABLED,
} from './config';
import { enableStrict, requestMutation } from './lib/fasterdom/fasterdom';
import { selectChat, selectCurrentMessageList, selectPeerFullInfo, selectTabState } from './global/selectors';
import { selectSharedSettings } from './global/selectors/sharedState';
import { betterView } from './util/betterView';
import { IS_TAURI } from './util/browser/globalEnvironment';
import listenOtherClients from './util/browser/listenOtherClients';
import { requestGlobal, subscribeToMultitabBroadcastChannel } from './util/browser/multitab';
import { establishMultitabRole, subscribeToMasterChange } from './util/establishMultitabRole';
import { initGlobal } from './util/init';
import { initLocalization } from './util/localization';
import { MULTITAB_STORAGE_KEY } from './util/multiaccount';
import { checkAndAssignPermanentWebVersion } from './util/permanentWebVersion';
import { onBeforeUnload } from './util/schedulers';
import initTauriApi from './util/tauri/initTauriApi';
import setupTauriListeners from './util/tauri/setupTauriListeners';
import updateWebmanifest from './util/updateWebmanifest';
import App from './components/App';
import './assets/fonts/roboto.css';
import './styles/index.scss';
if (STRICTERDOM_ENABLED) {
enableStrict();
}
if (IS_TAURI) {
initTauriApi();
setupTauriListeners();
}
init();
async function init() {
if (DEBUG) {
// eslint-disable-next-line no-console
console.log('>>> INIT');
}
if (!(window as any).isCompatTestPassed) return;
checkAndAssignPermanentWebVersion();
listenOtherClients();
subscribeToMultitabBroadcastChannel();
await requestGlobal(APP_VERSION);
localStorage.setItem(MULTITAB_STORAGE_KEY, '1');
onBeforeUnload(() => {
const global = getGlobal();
if (Object.keys(global.byTabId).length === 1) {
localStorage.removeItem(MULTITAB_STORAGE_KEY);
}
});
await initGlobal();
getActions().init();
getActions().updateShouldEnableDebugLog();
getActions().updateShouldDebugExportedSenders();
const global = getGlobal();
initLocalization(selectSharedSettings(global).language, true);
subscribeToMasterChange((isMasterTab) => {
getActions()
.switchMultitabRole({ isMasterTab }, { forceSyncOnIOs: true });
});
const shouldReestablishMasterToSelf = getGlobal().auth.state !== 'authorizationStateReady';
establishMultitabRole(shouldReestablishMasterToSelf);
if (DEBUG) {
// eslint-disable-next-line no-console
console.log('>>> START INITIAL RENDER');
}
requestMutation(() => {
updateWebmanifest();
TeactDOM.render(
<App />,
document.getElementById('root')!,
);
betterView();
});
if (DEBUG) {
// eslint-disable-next-line no-console
console.log('>>> FINISH INITIAL RENDER');
}
if (DEBUG) {
document.addEventListener('dblclick', () => {
const currentGlobal = getGlobal();
const currentMessageList = selectCurrentMessageList(currentGlobal);
// eslint-disable-next-line no-console
console.warn('TAB STATE', selectTabState(currentGlobal));
// eslint-disable-next-line no-console
console.warn('GLOBAL STATE', currentGlobal);
if (currentMessageList) {
// eslint-disable-next-line no-console
console.warn(
'CURRENT MESSAGE LIST',
selectChat(currentGlobal, currentMessageList.chatId),
selectPeerFullInfo(currentGlobal, currentMessageList.chatId),
currentGlobal.messages.byChatId[currentMessageList.chatId],
);
}
});
}
}
onBeforeUnload(() => {
const actions = getActions();
actions.leaveGroupCall?.({ isPageUnload: true });
actions.hangUp?.({ isPageUnload: true });
});