mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 22:27:20 +02:00
Automatically reload theme on file change
This commit is contained in:
parent
28f75525b2
commit
f7bc84fdd6
2 changed files with 23 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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<BackgroundUpdate> updates() const {
|
||||
return _updates.events();
|
||||
|
@ -276,6 +279,7 @@ private:
|
|||
QImage _themeImage;
|
||||
bool _themeTile = false;
|
||||
std::optional<Data::CloudTheme> _editingTheme;
|
||||
std::unique_ptr<QFileSystemWatcher> _themeWatcher;
|
||||
|
||||
Data::WallPaper _paperForRevert
|
||||
= Data::details::UninitializedWallPaper();
|
||||
|
|
Loading…
Add table
Reference in a new issue