diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 520c4241d..2a347be87 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.cpp +++ b/Telegram/SourceFiles/window/themes/window_theme.cpp @@ -41,6 +41,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include #include +#include namespace Window { namespace Theme { @@ -540,6 +541,8 @@ ChatBackground::ChatBackground() : _adjustableColors({ st::historyScrollBarBgOver }) { } +ChatBackground::~ChatBackground() = default; + void ChatBackground::setThemeData(QImage &&themeImage, bool themeTile) { _themeImage = PostprocessBackgroundImage( std::move(themeImage), @@ -566,6 +569,22 @@ 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; + } if (update.paletteChanged()) { style::NotifyPaletteChanged(); } diff --git a/Telegram/SourceFiles/window/themes/window_theme.h b/Telegram/SourceFiles/window/themes/window_theme.h index 87dff002b..f59bbc15f 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.h +++ b/Telegram/SourceFiles/window/themes/window_theme.h @@ -11,6 +11,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "data/data_cloud_themes.h" #include "ui/style/style_core_palette.h" +class QFileSystemWatcher; + namespace style { struct colorizer; } // namespace style @@ -154,6 +156,7 @@ enum class ClearEditing { class ChatBackground final { public: ChatBackground(); + ~ChatBackground(); [[nodiscard]] rpl::producer updates() const { return _updates.events(); @@ -276,6 +279,7 @@ private: QImage _themeImage; bool _themeTile = false; std::optional _editingTheme; + std::unique_ptr _themeWatcher; Data::WallPaper _paperForRevert = Data::details::UninitializedWallPaper();