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;
|
2023-02-27 14:09:12 +00:00
|
|
|
bool AllForced/* = false*/;
|
2023-02-21 12:31:55 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2023-02-27 14:09:12 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-02-27 14:09:12 +00:00
|
|
|
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({});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-27 14:09:12 +00:00
|
|
|
bool ForceAll() {
|
|
|
|
return AllForced;
|
2023-02-21 12:31:55 +00:00
|
|
|
}
|
|
|
|
|
2023-02-27 14:09:12 +00:00
|
|
|
rpl::producer<> Changes() {
|
|
|
|
return Events.events();
|
2023-02-21 12:31:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace PowerSaving
|