2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Automatically reload theme on file change

This commit is contained in:
Ilya Fedin
2022-06-23 03:32:01 +04:00
committed by John Preston
parent 28f75525b2
commit f7bc84fdd6
2 changed files with 23 additions and 0 deletions

View File

@@ -41,6 +41,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include <QtCore/QBuffer>
#include <QtCore/QJsonDocument>
#include <QtCore/QJsonObject>
#include <QtCore/QFileSystemWatcher>
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<QFileSystemWatcher>(
QStringList(path));
QObject::connect(
_themeWatcher.get(),
&QFileSystemWatcher::fileChanged,
[](const QString &path) {
Apply(path);
KeepApplied();
});
}
} else {
_themeWatcher = nullptr;
}
if (update.paletteChanged()) {
style::NotifyPaletteChanged();
}