From ce39eb2da9582d374bee4ff7e51ad9b5fdb2647e Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 23 Jun 2022 10:35:52 +0400 Subject: [PATCH] Don't watch theme file while using theme editor. --- .../window/themes/window_theme.cpp | 38 +++++++++++-------- .../SourceFiles/window/themes/window_theme.h | 1 + 2 files changed, 23 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/window/themes/window_theme.cpp b/Telegram/SourceFiles/window/themes/window_theme.cpp index 2a347be876..4ff4a80a51 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 f59bbc15ff..f8458c2ac4 100644 --- a/Telegram/SourceFiles/window/themes/window_theme.h +++ b/Telegram/SourceFiles/window/themes/window_theme.h @@ -243,6 +243,7 @@ private: [[nodiscard]] bool isNonDefaultBackground(); void checkUploadWallPaper(); [[nodiscard]] QImage postprocessBackgroundImage(QImage image); + void refreshThemeWatcher(); friend bool IsNightMode(); friend void SetNightModeValue(bool nightMode);