diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 2a347be876bf6a..4ff4a80a51ca30 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -569,22 +569,7 @@ void ChatBackground::start() { _updates.events( ) | rpl::start_with_next([=](const BackgroundUpdate &update) { - if (const auto path = _themeObject.pathAbsolute - ; !path.isEmpty() && QFileInfo(path).isNativePath()) { - if (!_themeWatcher || !_themeWatcher->files().contains(path)) { - _themeWatcher = std::make_unique( - QStringList(path)); - QObject::connect( - _themeWatcher.get(), - &QFileSystemWatcher::fileChanged, - [](const QString &path) { - Apply(path); - KeepApplied(); - }); - } - } else { - _themeWatcher = nullptr; - } + refreshThemeWatcher(); if (update.paletteChanged()) { style::NotifyPaletteChanged(); } @@ -603,6 +588,25 @@ void ChatBackground::start() { Core::App().settings().setSystemDarkMode(Platform::IsDarkMode()); } +void ChatBackground::refreshThemeWatcher() { + const auto path = _themeObject.pathAbsolute; + if (path.isEmpty() + || !QFileInfo(path).isNativePath() + || editingTheme()) { + _themeWatcher = nullptr; + } else if (!_themeWatcher || !_themeWatcher->files().contains(path)) { + _themeWatcher = std::make_unique( + QStringList(path)); + QObject::connect( + _themeWatcher.get(), + &QFileSystemWatcher::fileChanged, + [](const QString &path) { + Apply(path); + KeepApplied(); + }); + } +} + void ChatBackground::checkUploadWallPaper() { if (!_session) { _wallPaperUploadLifetime = rpl::lifetime(); @@ -826,6 +830,7 @@ std::optional ChatBackground::editingTheme() const { void ChatBackground::setEditingTheme(const Data::CloudTheme &editing) { _editingTheme = editing; + refreshThemeWatcher(); } void ChatBackground::clearEditingTheme(ClearEditing clear) { @@ -841,6 +846,7 @@ void ChatBackground::clearEditingTheme(ClearEditing clear) { reapplyWithNightMode(std::nullopt, _nightMode); KeepApplied(); } + refreshThemeWatcher(); } void ChatBackground::adjustPaletteUsingBackground(const QImage &image) { diff --git a/Telegram/SourceFiles/window/themes/window_theme.h b/Telegram/SourceFiles/window/themes/window_theme.h index f59bbc15ff3589..f8458c2ac4abc3 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.h +++ b/Telegram/SourceFiles/window/themes/window_theme.h @@ -243,6 +243,7 @@ class ChatBackground final { [[nodiscard]] bool isNonDefaultBackground(); void checkUploadWallPaper(); [[nodiscard]] QImage postprocessBackgroundImage(QImage image); + void refreshThemeWatcher(); friend bool IsNightMode(); friend void SetNightModeValue(bool nightMode);