Ensure permanent web version setting

This commit is contained in:
Alexander Zinchuk 2022-01-13 14:52:47 +01:00
parent fd6b35183c
commit e857cca4e6
3 changed files with 35 additions and 4 deletions

View File

@ -11,10 +11,11 @@ import {
} from '../../../config';
import { IS_SINGLE_COLUMN_LAYOUT } from '../../../util/environment';
import buildClassName from '../../../util/buildClassName';
import { isChatArchived } from '../../../modules/helpers';
import { formatDateToString } from '../../../util/dateFormat';
import { selectTheme } from '../../../modules/selectors';
import switchTheme from '../../../util/switchTheme';
import { setPermanentWebVersion } from '../../../util/permanentWebVersion';
import { selectTheme } from '../../../modules/selectors';
import { isChatArchived } from '../../../modules/helpers';
import useLang from '../../../hooks/useLang';
import { disableHistoryBack } from '../../../hooks/useHistoryBack';
@ -54,7 +55,6 @@ const ANIMATION_LEVEL_OPTIONS = [0, 1, 2];
const PRODUCTION_HOSTNAME = 'web.telegram.org';
const LEGACY_VERSION_URL = 'https://web.telegram.org/?legacy=1';
const WEBK_VERSION_URL = 'https://web.telegram.org/k/';
const PERMANENT_VERSION_KEY = 'kz_version';
const LeftMainHeader: FC<OwnProps & StateProps> = ({
content,
@ -158,7 +158,7 @@ const LeftMainHeader: FC<OwnProps & StateProps> = ({
}, [animationLevel, setSettingOption]);
const handleSwitchToWebK = () => {
localStorage.setItem(PERMANENT_VERSION_KEY, JSON.stringify('K'));
setPermanentWebVersion('K');
disableHistoryBack();
};

View File

@ -8,6 +8,7 @@ import { setLanguage } from '../../../util/langProvider';
import switchTheme from '../../../util/switchTheme';
import { selectTheme } from '../../selectors';
import { startWebsync } from '../../../util/websync';
import { ensurePermanentWebVersion } from '../../../util/permanentWebVersion';
const HISTORY_ANIMATION_DURATION = 450;
@ -28,7 +29,10 @@ addReducer('init', (global) => {
document.body.classList.add('initial');
document.body.classList.add(`animation-level-${animationLevel}`);
document.body.classList.add(IS_TOUCH_ENV ? 'is-touch-env' : 'is-pointer-env');
switchTheme(theme, animationLevel === ANIMATION_LEVEL_MAX);
ensurePermanentWebVersion();
startWebsync();
if (IS_IOS) {

View File

@ -0,0 +1,27 @@
const PERMANENT_VERSION_KEY = 'kz_version';
const AVAILABLE_VERSIONS = ['Z', 'K'] as const;
const DEFAULT_VERSION = 'Z';
export function setPermanentWebVersion(version: typeof AVAILABLE_VERSIONS[number]) {
localStorage.setItem(PERMANENT_VERSION_KEY, JSON.stringify(version));
}
export function ensurePermanentWebVersion() {
if (!hasPermanentWebVersion()) {
setPermanentWebVersion(DEFAULT_VERSION);
}
}
function hasPermanentWebVersion() {
const json = localStorage.getItem(PERMANENT_VERSION_KEY);
if (!json) {
return false;
}
try {
const version = JSON.parse(json);
return AVAILABLE_VERSIONS.includes(version);
} catch (err) {
return false;
}
}