From 4add6234b65eef9fcec626106a0e776766ffa917 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 23 Jun 2020 19:24:45 +0400 Subject: [PATCH] Fix reading background before style init. --- .../window/themes/window_theme.cpp | 43 +++++++++++-------- .../SourceFiles/window/themes/window_theme.h | 4 +- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index b450964dc3..b3940bd825 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -536,12 +536,17 @@ void ChatBackground::setThemeData(QImage &&themeImage, bool themeTile) { } void ChatBackground::initialRead() { - if (!Data::details::IsUninitializedWallPaper(_paper)) { + if (started()) { return; - } - if (!Local::readBackground()) { + } else if (!Local::readBackground()) { set(Data::ThemeWallPaper()); } + if (_localStoredTileDayValue) { + _tileDayValue = *_localStoredTileDayValue; + } + if (_localStoredTileNightValue) { + _tileNightValue = *_localStoredTileNightValue; + } } void ChatBackground::start() { @@ -855,16 +860,9 @@ bool ChatBackground::isMonoColorImage() const { return _isMonoColorImage; } -void ChatBackground::ensureInitialRead() { - if (_pixmap.isNull() && !_paper.backgroundColor()) { - // We should start first, otherwise the default call - // to initialRead() will reset this value to _themeTile. - initialRead(); - } -} - void ChatBackground::setTile(bool tile) { - ensureInitialRead(); + Expects(started()); + const auto old = this->tile(); if (nightMode()) { setTileNightValue(tile); @@ -881,13 +879,19 @@ void ChatBackground::setTile(bool tile) { } void ChatBackground::setTileDayValue(bool tile) { - ensureInitialRead(); - _tileDayValue = tile; + if (started()) { + _tileDayValue = tile; + } else { + _localStoredTileDayValue = tile; + } } void ChatBackground::setTileNightValue(bool tile) { - ensureInitialRead(); - _tileNightValue = tile; + if (started()) { + _tileNightValue = tile; + } else { + _localStoredTileNightValue = tile; + } } void ChatBackground::setThemeObject(const Object &object) { @@ -920,8 +924,13 @@ void ChatBackground::reset() { writeNewBackgroundSettings(); } +bool ChatBackground::started() const { + return !Data::details::IsUninitializedWallPaper(_paper); +} + void ChatBackground::saveForRevert() { - ensureInitialRead(); + Expects(started()); + if (!Data::details::IsTestingThemeWallPaper(_paper) && !Data::details::IsTestingDefaultWallPaper(_paper)) { _paperForRevert = _paper; diff --git a/Telegram/SourceFiles/window/themes/window_theme.h b/Telegram/SourceFiles/window/themes/window_theme.h index 71715cbe28..3be1b99eb2 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.h +++ b/Telegram/SourceFiles/window/themes/window_theme.h @@ -178,8 +178,8 @@ private: QColor original; }; + [[nodiscard]] bool started() const; void initialRead(); - void ensureInitialRead(); void saveForRevert(); void setPreparedImage(QImage original, QImage prepared); void preparePixmaps(QImage image); @@ -226,6 +226,8 @@ private: bool _nightMode = false; bool _tileDayValue = false; bool _tileNightValue = true; + std::optional _localStoredTileDayValue; + std::optional _localStoredTileNightValue; bool _isMonoColorImage = false;