diff --git a/src/global/actions/ui/initial.ts b/src/global/actions/ui/initial.ts index 18fd7f94d..ba4f0fe64 100644 --- a/src/global/actions/ui/initial.ts +++ b/src/global/actions/ui/initial.ts @@ -32,7 +32,7 @@ setSystemThemeChangeCallback((theme) => { // eslint-disable-next-line eslint-multitab-tt/no-immediate-global let global = getGlobal(); - if (!global.settings.byKey.shouldUseSystemTheme) return; + if (!global.isInited || !global.settings.byKey.shouldUseSystemTheme) return; global = replaceSettings(global, { theme }); setGlobal(global); diff --git a/src/global/actions/ui/passcode.ts b/src/global/actions/ui/passcode.ts index f55b4913a..664d418d8 100644 --- a/src/global/actions/ui/passcode.ts +++ b/src/global/actions/ui/passcode.ts @@ -16,7 +16,9 @@ import { clearPasscodeSettings, updatePasscodeSettings } from '../../reducers'; let noLockOnUnload = false; onBeforeUnload(() => { // eslint-disable-next-line eslint-multitab-tt/no-immediate-global - if (getGlobal().passcode.hasPasscode && !noLockOnUnload && Object.keys(getGlobal().byTabId).length === 1) { + const global = getGlobal(); + if (!global.isInited) return; + if (global.passcode.hasPasscode && !noLockOnUnload && Object.keys(global.byTabId).length === 1) { clearStoredSession(); } }); diff --git a/src/global/initialState.ts b/src/global/initialState.ts index 535fa9332..f668e7685 100644 --- a/src/global/initialState.ts +++ b/src/global/initialState.ts @@ -66,6 +66,7 @@ export const INITIAL_PERFORMANCE_STATE_MIN: PerformanceType = { }; export const INITIAL_GLOBAL_STATE: GlobalState = { + isInited: true, attachMenu: { bots: {} }, passcode: {}, twoFaSettings: {}, diff --git a/src/global/intervals.ts b/src/global/intervals.ts index a1a2ba00e..f069e1662 100644 --- a/src/global/intervals.ts +++ b/src/global/intervals.ts @@ -41,6 +41,8 @@ function stopIntervals() { function checkStoryExpiration() { // eslint-disable-next-line eslint-multitab-tt/no-immediate-global let global = getGlobal(); + if (!global.isInited) return; + const serverTime = getServerTime(); Object.values(global.stories.byPeerId).forEach((peerStories) => { diff --git a/src/global/types.ts b/src/global/types.ts index 010630438..ca38b204f 100644 --- a/src/global/types.ts +++ b/src/global/types.ts @@ -805,6 +805,7 @@ export type TabState = { }; export type GlobalState = { + isInited: boolean; config?: ApiConfig; appConfig?: ApiAppConfig; peerColors?: ApiPeerColors; diff --git a/src/lib/teact/teactn.tsx b/src/lib/teact/teactn.tsx index 1fdf9d338..5b70417b1 100644 --- a/src/lib/teact/teactn.tsx +++ b/src/lib/teact/teactn.tsx @@ -52,7 +52,9 @@ type ActivationFn = ( global: GlobalState, ownProps: OwnProps, stickToFirst: StickToFirstFn, ) => boolean; -let currentGlobal = {} as GlobalState; +let currentGlobal = { + isInited: false, +} as GlobalState; // eslint-disable-next-line @typescript-eslint/naming-convention let DEBUG_currentCapturedId: number | undefined;