tdesktop/Telegram/SourceFiles/ui/power_saving.cpp

57 lines
987 B
C++
Raw Normal View History

2023-02-21 12:31:55 +00:00
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "ui/power_saving.h"
namespace PowerSaving {
namespace {
Flags Data/* = {}*/;
rpl::event_stream<> Events;
bool AllForced/* = false*/;
2023-02-21 12:31:55 +00:00
} // namespace
void Set(Flags flags) {
if (const auto diff = Data ^ flags) {
Data = flags;
if (!AllForced) {
if (diff & kAnimations) {
anim::SetDisabled(On(kAnimations));
}
Events.fire({});
}
}
}
2023-02-21 12:31:55 +00:00
Flags Current() {
return Data;
}
void SetForceAll(bool force) {
if (AllForced == force) {
return;
}
AllForced = force;
if (const auto diff = Data ^ kAll) {
2023-02-21 12:31:55 +00:00
if (diff & kAnimations) {
anim::SetDisabled(On(kAnimations));
}
Events.fire({});
}
}
bool ForceAll() {
return AllForced;
2023-02-21 12:31:55 +00:00
}
rpl::producer<> Changes() {
return Events.events();
2023-02-21 12:31:55 +00:00
}
} // namespace PowerSaving