Skip to content

Commit

Permalink
Don't watch theme file while using theme editor.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Jun 23, 2022
1 parent f7bc84f commit ce39eb2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
38 changes: 22 additions & 16 deletions Telegram/SourceFiles/window/themes/window_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QFileSystemWatcher>(
QStringList(path));
QObject::connect(
_themeWatcher.get(),
&QFileSystemWatcher::fileChanged,
[](const QString &path) {
Apply(path);
KeepApplied();
});
}
} else {
_themeWatcher = nullptr;
}
refreshThemeWatcher();
if (update.paletteChanged()) {
style::NotifyPaletteChanged();
}
Expand All @@ -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<QFileSystemWatcher>(
QStringList(path));
QObject::connect(
_themeWatcher.get(),
&QFileSystemWatcher::fileChanged,
[](const QString &path) {
Apply(path);
KeepApplied();
});
}
}

void ChatBackground::checkUploadWallPaper() {
if (!_session) {
_wallPaperUploadLifetime = rpl::lifetime();
Expand Down Expand Up @@ -826,6 +830,7 @@ std::optional<Data::CloudTheme> ChatBackground::editingTheme() const {

void ChatBackground::setEditingTheme(const Data::CloudTheme &editing) {
_editingTheme = editing;
refreshThemeWatcher();
}

void ChatBackground::clearEditingTheme(ClearEditing clear) {
Expand All @@ -841,6 +846,7 @@ void ChatBackground::clearEditingTheme(ClearEditing clear) {
reapplyWithNightMode(std::nullopt, _nightMode);
KeepApplied();
}
refreshThemeWatcher();
}

void ChatBackground::adjustPaletteUsingBackground(const QImage &image) {
Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/window/themes/window_theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit ce39eb2

Please sign in to comment.