Dark Theme: Use system theme
This commit is contained in:
parent
07d89c55bf
commit
44f29bc909
@ -24,6 +24,7 @@ import { renderWaveformToDataUri } from './helpers/waveform';
|
|||||||
import buildClassName from '../../util/buildClassName';
|
import buildClassName from '../../util/buildClassName';
|
||||||
import renderText from './helpers/renderText';
|
import renderText from './helpers/renderText';
|
||||||
import { decodeWaveform, interpolateArray } from '../../util/waveform';
|
import { decodeWaveform, interpolateArray } from '../../util/waveform';
|
||||||
|
import { selectTheme } from '../../modules/selectors';
|
||||||
import useMediaWithDownloadProgress from '../../hooks/useMediaWithDownloadProgress';
|
import useMediaWithDownloadProgress from '../../hooks/useMediaWithDownloadProgress';
|
||||||
import useShowTransition from '../../hooks/useShowTransition';
|
import useShowTransition from '../../hooks/useShowTransition';
|
||||||
import useBuffering from '../../hooks/useBuffering';
|
import useBuffering from '../../hooks/useBuffering';
|
||||||
@ -456,4 +457,6 @@ function renderSeekline(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default memo(withGlobal<OwnProps>((global) => ({ theme: global.settings.byKey.theme }))(Audio));
|
export default memo(withGlobal<OwnProps>((global) => ({
|
||||||
|
theme: selectTheme(global),
|
||||||
|
}))(Audio));
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import './UiLoader.scss';
|
|||||||
import telegramLogoPath from '../../assets/telegram-logo.svg';
|
import telegramLogoPath from '../../assets/telegram-logo.svg';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import monkeyPath from '../../assets/monkey.svg';
|
import monkeyPath from '../../assets/monkey.svg';
|
||||||
import { selectIsRightColumnShown } from '../../modules/selectors';
|
import { selectIsRightColumnShown, selectTheme } from '../../modules/selectors';
|
||||||
|
|
||||||
type OwnProps = {
|
type OwnProps = {
|
||||||
page: 'main' | 'authCode' | 'authPassword' | 'authPhoneNumber' | 'authQrCode';
|
page: 'main' | 'authCode' | 'authPassword' | 'authPhoneNumber' | 'authQrCode';
|
||||||
@ -152,7 +152,7 @@ const UiLoader: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
|
|
||||||
export default withGlobal<OwnProps>(
|
export default withGlobal<OwnProps>(
|
||||||
(global): StateProps => {
|
(global): StateProps => {
|
||||||
const { theme } = global.settings.byKey;
|
const theme = selectTheme(global);
|
||||||
const { background, backgroundColor } = global.settings.themes[theme] || {};
|
const { background, backgroundColor } = global.settings.themes[theme] || {};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import buildClassName from '../../../util/buildClassName';
|
|||||||
import { pick } from '../../../util/iteratees';
|
import { pick } from '../../../util/iteratees';
|
||||||
import { isChatArchived } from '../../../modules/helpers';
|
import { isChatArchived } from '../../../modules/helpers';
|
||||||
import { formatDateToString } from '../../../util/dateFormat';
|
import { formatDateToString } from '../../../util/dateFormat';
|
||||||
|
import { selectTheme } from '../../../modules/selectors';
|
||||||
import switchTheme from '../../../util/switchTheme';
|
import switchTheme from '../../../util/switchTheme';
|
||||||
import useLang from '../../../hooks/useLang';
|
import useLang from '../../../hooks/useLang';
|
||||||
|
|
||||||
@ -135,6 +136,7 @@ const LeftMainHeader: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
const newTheme = theme === 'light' ? 'dark' : 'light';
|
const newTheme = theme === 'light' ? 'dark' : 'light';
|
||||||
|
|
||||||
setSettingOption({ theme: newTheme });
|
setSettingOption({ theme: newTheme });
|
||||||
|
setSettingOption({ shouldUseSystemTheme: false });
|
||||||
switchTheme(newTheme, animationLevel > 0);
|
switchTheme(newTheme, animationLevel > 0);
|
||||||
}, [animationLevel, setSettingOption, theme]);
|
}, [animationLevel, setSettingOption, theme]);
|
||||||
|
|
||||||
@ -296,7 +298,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
} = global.globalSearch;
|
} = global.globalSearch;
|
||||||
const { currentUserId } = global;
|
const { currentUserId } = global;
|
||||||
const { byId: chatsById } = global.chats;
|
const { byId: chatsById } = global.chats;
|
||||||
const { theme, animationLevel } = global.settings.byKey;
|
const { animationLevel } = global.settings.byKey;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
searchQuery,
|
searchQuery,
|
||||||
@ -305,7 +307,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
chatsById,
|
chatsById,
|
||||||
globalSearchChatId: chatId,
|
globalSearchChatId: chatId,
|
||||||
searchDate: date,
|
searchDate: date,
|
||||||
theme,
|
theme: selectTheme(global),
|
||||||
animationLevel,
|
animationLevel,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import { pick } from '../../../util/iteratees';
|
|||||||
import { throttle } from '../../../util/schedulers';
|
import { throttle } from '../../../util/schedulers';
|
||||||
import { openSystemFilesDialog } from '../../../util/systemFilesDialog';
|
import { openSystemFilesDialog } from '../../../util/systemFilesDialog';
|
||||||
import { getAverageColor, getPatternColor, rgb2hex } from '../../../util/colors';
|
import { getAverageColor, getPatternColor, rgb2hex } from '../../../util/colors';
|
||||||
|
import { selectTheme } from '../../../modules/selectors';
|
||||||
import useLang from '../../../hooks/useLang';
|
import useLang from '../../../hooks/useLang';
|
||||||
|
|
||||||
import ListItem from '../../ui/ListItem';
|
import ListItem from '../../ui/ListItem';
|
||||||
@ -158,7 +159,7 @@ const SettingsGeneralBackground: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
|
|
||||||
export default memo(withGlobal<OwnProps>(
|
export default memo(withGlobal<OwnProps>(
|
||||||
(global): StateProps => {
|
(global): StateProps => {
|
||||||
const { theme } = global.settings.byKey;
|
const theme = selectTheme(global);
|
||||||
const { background, isBlurred } = global.settings.themes[theme] || {};
|
const { background, isBlurred } = global.settings.themes[theme] || {};
|
||||||
const { loadedWallpapers } = global.settings;
|
const { loadedWallpapers } = global.settings;
|
||||||
|
|
||||||
|
|||||||
@ -12,6 +12,7 @@ import {
|
|||||||
getPatternColor, hex2rgb, hsb2rgb, rgb2hex, rgb2hsb,
|
getPatternColor, hex2rgb, hsb2rgb, rgb2hex, rgb2hsb,
|
||||||
} from '../../../util/colors';
|
} from '../../../util/colors';
|
||||||
import { captureEvents, RealTouchEvent } from '../../../util/captureEvents';
|
import { captureEvents, RealTouchEvent } from '../../../util/captureEvents';
|
||||||
|
import { selectTheme } from '../../../modules/selectors';
|
||||||
import useFlag from '../../../hooks/useFlag';
|
import useFlag from '../../../hooks/useFlag';
|
||||||
import buildClassName from '../../../util/buildClassName';
|
import buildClassName from '../../../util/buildClassName';
|
||||||
|
|
||||||
@ -336,7 +337,7 @@ function drawHue(canvas: HTMLCanvasElement) {
|
|||||||
|
|
||||||
export default memo(withGlobal<OwnProps>(
|
export default memo(withGlobal<OwnProps>(
|
||||||
(global): StateProps => {
|
(global): StateProps => {
|
||||||
const { theme } = global.settings.byKey;
|
const theme = selectTheme(global);
|
||||||
const { backgroundColor } = global.settings.themes[theme] || {};
|
const { backgroundColor } = global.settings.themes[theme] || {};
|
||||||
return {
|
return {
|
||||||
backgroundColor,
|
backgroundColor,
|
||||||
|
|||||||
@ -165,7 +165,6 @@ const VideoPlayer: FC<OwnProps> = ({
|
|||||||
style={videoStyle}
|
style={videoStyle}
|
||||||
onEnded={handleEnded}
|
onEnded={handleEnded}
|
||||||
onClick={togglePlayState}
|
onClick={togglePlayState}
|
||||||
onDoubleClick={handleFullscreenChange}
|
|
||||||
// eslint-disable-next-line react/jsx-props-no-spreading
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
||||||
{...bufferingHandlers}
|
{...bufferingHandlers}
|
||||||
onTimeUpdate={handleTimeUpdate}
|
onTimeUpdate={handleTimeUpdate}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import {
|
|||||||
selectIsInSelectMode,
|
selectIsInSelectMode,
|
||||||
selectIsRightColumnShown,
|
selectIsRightColumnShown,
|
||||||
selectPinnedIds,
|
selectPinnedIds,
|
||||||
|
selectTheme,
|
||||||
} from '../../modules/selectors';
|
} from '../../modules/selectors';
|
||||||
import { getCanPostInChat, getMessageSendingRestrictionReason, isChatPrivate } from '../../modules/helpers';
|
import { getCanPostInChat, getMessageSendingRestrictionReason, isChatPrivate } from '../../modules/helpers';
|
||||||
import captureEscKeyListener from '../../util/captureEscKeyListener';
|
import captureEscKeyListener from '../../util/captureEscKeyListener';
|
||||||
@ -325,7 +326,7 @@ const MiddleColumn: FC<StateProps & DispatchProps> = ({
|
|||||||
|
|
||||||
export default memo(withGlobal(
|
export default memo(withGlobal(
|
||||||
(global): StateProps => {
|
(global): StateProps => {
|
||||||
const { theme } = global.settings.byKey;
|
const theme = selectTheme(global);
|
||||||
const {
|
const {
|
||||||
isBlurred: isBackgroundBlurred, background: customBackground, backgroundColor, patternColor,
|
isBlurred: isBackgroundBlurred, background: customBackground, backgroundColor, patternColor,
|
||||||
} = global.settings.themes[theme] || {};
|
} = global.settings.themes[theme] || {};
|
||||||
|
|||||||
@ -105,10 +105,11 @@ export const INITIAL_STATE: GlobalState = {
|
|||||||
|
|
||||||
settings: {
|
settings: {
|
||||||
byKey: {
|
byKey: {
|
||||||
|
theme: 'light',
|
||||||
|
shouldUseSystemTheme: true,
|
||||||
messageTextSize: DEFAULT_MESSAGE_TEXT_SIZE_PX,
|
messageTextSize: DEFAULT_MESSAGE_TEXT_SIZE_PX,
|
||||||
animationLevel: ANIMATION_LEVEL_DEFAULT,
|
animationLevel: ANIMATION_LEVEL_DEFAULT,
|
||||||
messageSendKeyCombo: 'enter',
|
messageSendKeyCombo: 'enter',
|
||||||
theme: 'light',
|
|
||||||
shouldAutoDownloadMediaFromContacts: true,
|
shouldAutoDownloadMediaFromContacts: true,
|
||||||
shouldAutoDownloadMediaInPrivateChats: true,
|
shouldAutoDownloadMediaInPrivateChats: true,
|
||||||
shouldAutoDownloadMediaInGroups: true,
|
shouldAutoDownloadMediaInGroups: true,
|
||||||
|
|||||||
@ -5,11 +5,11 @@ import {
|
|||||||
} from '../../../util/environment';
|
} from '../../../util/environment';
|
||||||
import { setLanguage } from '../../../util/langProvider';
|
import { setLanguage } from '../../../util/langProvider';
|
||||||
import switchTheme from '../../../util/switchTheme';
|
import switchTheme from '../../../util/switchTheme';
|
||||||
|
import { selectTheme } from '../../selectors';
|
||||||
|
|
||||||
addReducer('init', (global) => {
|
addReducer('init', (global) => {
|
||||||
const {
|
const { animationLevel, messageTextSize, language } = global.settings.byKey;
|
||||||
theme, animationLevel, messageTextSize, language,
|
const theme = selectTheme(global);
|
||||||
} = global.settings.byKey;
|
|
||||||
|
|
||||||
setLanguage(language);
|
setLanguage(language);
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { GlobalState } from '../../global/types';
|
import { GlobalState } from '../../global/types';
|
||||||
import { RightColumnContent } from '../../types';
|
import { RightColumnContent } from '../../types';
|
||||||
|
|
||||||
import { IS_MOBILE_SCREEN } from '../../util/environment';
|
import { IS_MOBILE_SCREEN, SYSTEM_THEME } from '../../util/environment';
|
||||||
import { selectCurrentMessageList, selectIsPollResultsOpen } from './messages';
|
import { selectCurrentMessageList, selectIsPollResultsOpen } from './messages';
|
||||||
import { selectCurrentTextSearch } from './localSearch';
|
import { selectCurrentTextSearch } from './localSearch';
|
||||||
import { selectCurrentStickerSearch, selectCurrentGifSearch } from './symbols';
|
import { selectCurrentStickerSearch, selectCurrentGifSearch } from './symbols';
|
||||||
@ -53,3 +53,9 @@ export function selectRightColumnContentKey(global: GlobalState) {
|
|||||||
export function selectIsRightColumnShown(global: GlobalState) {
|
export function selectIsRightColumnShown(global: GlobalState) {
|
||||||
return selectRightColumnContentKey(global) !== undefined;
|
return selectRightColumnContentKey(global) !== undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function selectTheme(global: GlobalState) {
|
||||||
|
const { theme, shouldUseSystemTheme } = global.settings.byKey;
|
||||||
|
|
||||||
|
return shouldUseSystemTheme ? SYSTEM_THEME : theme;
|
||||||
|
}
|
||||||
|
|||||||
@ -45,6 +45,7 @@ export type LangCode = (
|
|||||||
|
|
||||||
export interface ISettings extends NotifySettings, Record<string, any> {
|
export interface ISettings extends NotifySettings, Record<string, any> {
|
||||||
theme: ThemeKey;
|
theme: ThemeKey;
|
||||||
|
shouldUseSystemTheme: boolean;
|
||||||
messageTextSize: number;
|
messageTextSize: number;
|
||||||
animationLevel: 0 | 1 | 2;
|
animationLevel: 0 | 1 | 2;
|
||||||
messageSendKeyCombo: 'enter' | 'ctrl-enter';
|
messageSendKeyCombo: 'enter' | 'ctrl-enter';
|
||||||
|
|||||||
@ -56,6 +56,10 @@ export const DPR = window.devicePixelRatio || 1;
|
|||||||
|
|
||||||
export const MASK_IMAGE_DISABLED = true;
|
export const MASK_IMAGE_DISABLED = true;
|
||||||
|
|
||||||
|
export const SYSTEM_THEME = (
|
||||||
|
window && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||||
|
) ? 'dark' : 'light';
|
||||||
|
|
||||||
let isWebpSupportedCache: boolean | undefined;
|
let isWebpSupportedCache: boolean | undefined;
|
||||||
|
|
||||||
export function isWebpSupported() {
|
export function isWebpSupported() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user