This commit is contained in:
Eduard Kuzmenko 2023-03-02 15:44:00 +04:00
parent 9e0f20c766
commit 662c3e837c
9 changed files with 74 additions and 13 deletions

View File

@ -10,6 +10,7 @@ import {LangPackKey, _i18n} from '../lib/langPack';
import getDeepProperty from '../helpers/object/getDeepProperty'; import getDeepProperty from '../helpers/object/getDeepProperty';
import rootScope from '../lib/rootScope'; import rootScope from '../lib/rootScope';
import apiManagerProxy from '../lib/mtproto/mtprotoworker'; import apiManagerProxy from '../lib/mtproto/mtprotoworker';
import simulateEvent from '../helpers/dom/dispatchEvent';
export type CheckboxFieldOptions = { export type CheckboxFieldOptions = {
text?: LangPackKey, text?: LangPackKey,
@ -19,6 +20,7 @@ export type CheckboxFieldOptions = {
toggle?: boolean, toggle?: boolean,
stateKey?: string, stateKey?: string,
stateValues?: any[], stateValues?: any[],
stateValueReverse?: boolean,
disabled?: boolean, disabled?: boolean,
checked?: boolean, checked?: boolean,
restriction?: boolean, restriction?: boolean,
@ -73,12 +75,16 @@ export default class CheckboxField {
value = options.stateValues[input.checked ? 1 : 0]; value = options.stateValues[input.checked ? 1 : 0];
} else { } else {
value = input.checked; value = input.checked;
if(options.stateValueReverse) {
value = !value;
}
} }
rootScope.managers.appStateManager.setByKey(options.stateKey, value); rootScope.managers.appStateManager.setByKey(options.stateKey, value);
}; };
apiManagerProxy.getState().then((state) => { options.checked === undefined && apiManagerProxy.getState().then((state) => {
loaded = true; loaded = true;
const stateValue = getDeepProperty(state, options.stateKey); const stateValue = getDeepProperty(state, options.stateKey);
let checked: boolean; let checked: boolean;
@ -86,6 +92,10 @@ export default class CheckboxField {
checked = options.stateValues.indexOf(stateValue) === 1; checked = options.stateValues.indexOf(stateValue) === 1;
} else { } else {
checked = stateValue; checked = stateValue;
if(options.stateValueReverse) {
checked = !checked;
}
} }
this.setValueSilently(checked); this.setValueSilently(checked);
@ -162,17 +172,20 @@ export default class CheckboxField {
} */ } */
this.setValueSilently(checked); this.setValueSilently(checked);
simulateEvent(this.input, 'change');
const event = new Event('change', {bubbles: true, cancelable: true});
this.input.dispatchEvent(event);
} }
public setValueSilently(checked: boolean) { public setValueSilently(checked: boolean) {
this.input.checked = checked; this.input.checked = checked;
} }
public isDisabled() {
return this.label.classList.contains('checkbox-disabled');
}
public toggleDisability(disable: boolean) { public toggleDisability(disable: boolean) {
this.label.classList.toggle('checkbox-disabled', disable); this.label.classList.toggle('checkbox-disabled', disable);
this.input.disabled = disable;
return () => this.toggleDisability(!disable); return () => this.toggleDisability(!disable);
} }
} }

View File

@ -4,6 +4,7 @@
* https://github.com/morethanwords/tweb/blob/master/LICENSE * https://github.com/morethanwords/tweb/blob/master/LICENSE
*/ */
import simulateEvent from '../helpers/dom/dispatchEvent';
import getDeepProperty from '../helpers/object/getDeepProperty'; import getDeepProperty from '../helpers/object/getDeepProperty';
import {LangPackKey, _i18n} from '../lib/langPack'; import {LangPackKey, _i18n} from '../lib/langPack';
import apiManagerProxy from '../lib/mtproto/mtprotoworker'; import apiManagerProxy from '../lib/mtproto/mtprotoworker';
@ -75,9 +76,7 @@ export default class RadioField {
set checked(checked: boolean) { set checked(checked: boolean) {
this.setValueSilently(checked); this.setValueSilently(checked);
simulateEvent(this.input, 'change');
const event = new Event('change', {bubbles: true, cancelable: true});
this.input.dispatchEvent(event);
} }
public setValueSilently(checked: boolean) { public setValueSilently(checked: boolean) {

View File

@ -285,6 +285,10 @@ export default class Row {
return media; return media;
} }
public isDisabled() {
return this.container.classList.contains('is-disabled');
}
public toggleDisability(disable = !this.container.classList.contains('is-disabled')) { public toggleDisability(disable = !this.container.classList.contains('is-disabled')) {
this.container.classList.toggle('is-disabled', disable); this.container.classList.toggle('is-disabled', disable);
return () => this.toggleDisability(!disable); return () => this.toggleDisability(!disable);

View File

@ -55,6 +55,8 @@ import {FOLDER_ID_ARCHIVE} from '../../lib/mtproto/mtproto_config';
import mediaSizes from '../../helpers/mediaSizes'; import mediaSizes from '../../helpers/mediaSizes';
import {fastRaf} from '../../helpers/schedulers'; import {fastRaf} from '../../helpers/schedulers';
import {getInstallPrompt} from '../../helpers/dom/installPrompt'; import {getInstallPrompt} from '../../helpers/dom/installPrompt';
import liteMode from '../../helpers/liteMode';
import AppPowerSavingTab from './tabs/powerSaving';
export const LEFT_COLUMN_ACTIVE_CLASSNAME = 'is-left-column-shown'; export const LEFT_COLUMN_ACTIVE_CLASSNAME = 'is-left-column-shown';
@ -175,8 +177,17 @@ export class AppSidebarLeft extends SidebarSlider {
checkboxField: new CheckboxField({ checkboxField: new CheckboxField({
toggle: true, toggle: true,
checked: true, checked: true,
stateKey: 'settings.animationsEnabled' stateKey: 'settings.liteMode.animations',
}) stateValueReverse: true
}),
verify: () => !liteMode.isEnabled()
}, {
icon: 'animations',
text: 'LiteMode.Title',
onClick: () => {
this.createTab(AppPowerSavingTab).open();
},
verify: () => liteMode.isEnabled()
}, { }, {
icon: 'help', icon: 'help',
text: 'TelegramFeatures', text: 'TelegramFeatures',

View File

@ -35,6 +35,7 @@ import RLottiePlayer from '../../../lib/rlottie/rlottiePlayer';
import themeController from '../../../helpers/themeController'; import themeController from '../../../helpers/themeController';
import liteMode from '../../../helpers/liteMode'; import liteMode from '../../../helpers/liteMode';
import AppPowerSavingTab from './powerSaving'; import AppPowerSavingTab from './powerSaving';
import {toastNew} from '../../toast';
export class RangeSettingSelector { export class RangeSettingSelector {
public container: HTMLDivElement; public container: HTMLDivElement;
@ -130,8 +131,28 @@ export default class AppGeneralSettingsTab extends SliderSuperTabEventable {
const onUpdate = () => { const onUpdate = () => {
i.compareAndUpdate({key: getLiteModeStatus()}); i.compareAndUpdate({key: getLiteModeStatus()});
animationsCheckboxField.setValueSilently(liteMode.isAvailable('animations'));
animationsCheckboxField.toggleDisability(liteMode.isEnabled());
}; };
onUpdate();
const animationsCheckboxField = new CheckboxField({
text: 'EnableAnimations',
name: 'animations',
stateKey: 'settings.liteMode.animations',
stateValueReverse: true,
checked: false,
listenerSetter: this.listenerSetter
});
const animationsRow = new Row({
checkboxField: animationsCheckboxField,
clickable: () => {
if(animationsCheckboxField.isDisabled()) {
toastNew({langPackKey: 'LiteMode.DisableAlert'});
}
},
listenerSetter: this.listenerSetter
});
const liteModeRow = new Row({ const liteModeRow = new Row({
icon: 'animations', icon: 'animations',
@ -143,11 +164,14 @@ export default class AppGeneralSettingsTab extends SliderSuperTabEventable {
listenerSetter: this.listenerSetter listenerSetter: this.listenerSetter
}); });
onUpdate();
this.listenerSetter.add(rootScope)('settings_updated', onUpdate); this.listenerSetter.add(rootScope)('settings_updated', onUpdate);
container.append( container.append(
range.container, range.container,
chatBackgroundButton, chatBackgroundButton,
animationsRow.container,
liteModeRow.container liteModeRow.container
); );
} }

View File

@ -39,8 +39,8 @@ export default class AppPowerSavingTab extends SliderSuperTab {
'all', 'all',
'video', 'video',
'gif', 'gif',
['stickers', ['stickers_panel', 'stickers_chat']], // ['stickers', ['stickers_panel', 'stickers_chat']],
['emoji', ['emoji_panel', 'emoji_messages']], // ['emoji', ['emoji_panel', 'emoji_messages']],
['effects', ['effects_reactions', 'effects_premiumstickers', 'effects_emoji']], ['effects', ['effects_reactions', 'effects_premiumstickers', 'effects_emoji']],
['chat', ['chat_background', 'chat_spoilers']], ['chat', ['chat_background', 'chat_spoilers']],
'animations' 'animations'

View File

@ -21,7 +21,7 @@ const App = {
version: process.env.VERSION, version: process.env.VERSION,
versionFull: process.env.VERSION_FULL, versionFull: process.env.VERSION_FULL,
build: +process.env.BUILD, build: +process.env.BUILD,
langPackVersion: '0.9.7', langPackVersion: '0.9.8',
langPack: 'webk', langPack: 'webk',
langPackCode: 'en', langPackCode: 'en',
domains: MAIN_DOMAINS, domains: MAIN_DOMAINS,

View File

@ -14,6 +14,10 @@ export type LiteModeKey = 'all' | 'gif' | 'video' |
'chat' | 'chat_background' | 'chat_spoilers' | 'animations'; 'chat' | 'chat_background' | 'chat_spoilers' | 'animations';
export class LiteMode { export class LiteMode {
public isEnabled() {
return rootScope.settings.liteMode.all;
}
public isAvailable(key: LiteModeKey) { public isAvailable(key: LiteModeKey) {
return !rootScope.settings.liteMode.all && !rootScope.settings.liteMode[key]; return !rootScope.settings.liteMode.all && !rootScope.settings.liteMode[key];
} }

View File

@ -377,6 +377,12 @@ async function loadStateInner() {
} }
} }
if(state.build < 309) {
state.settings.liteMode.animations = !state.settings.animationsEnabled;
state.settings.liteMode.video = !state.settings.autoPlay.videos;
state.settings.liteMode.gif = !state.settings.autoPlay.gifs;
}
if(compareVersion(state.version, STATE_VERSION) !== 0) { if(compareVersion(state.version, STATE_VERSION) !== 0) {
newVersion = STATE_VERSION; newVersion = STATE_VERSION;
oldVersion = state.version; oldVersion = state.version;