power_saving.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. namespace PowerSaving {
  9. enum Flag : uint32 {
  10. kAnimations = (1U << 0),
  11. kStickersPanel = (1U << 1),
  12. kStickersChat = (1U << 2),
  13. kEmojiPanel = (1U << 3),
  14. kEmojiReactions = (1U << 4),
  15. kEmojiChat = (1U << 5),
  16. kChatBackground = (1U << 6),
  17. kChatSpoiler = (1U << 7),
  18. kCalls = (1U << 8),
  19. kEmojiStatus = (1U << 9),
  20. kChatEffects = (1U << 10),
  21. kAll = (1U << 11) - 1,
  22. };
  23. inline constexpr bool is_flag_type(Flag) { return true; }
  24. using Flags = base::flags<Flag>;
  25. void Set(Flags flags);
  26. [[nodiscard]] Flags Current();
  27. void SetForceAll(bool force);
  28. [[nodiscard]] bool ForceAll();
  29. [[nodiscard]] rpl::producer<> Changes();
  30. [[nodiscard]] inline bool On(Flag flag) {
  31. return ForceAll() || (Current() & flag);
  32. }
  33. [[nodiscard]] inline rpl::producer<bool> OnValue(Flag flag) {
  34. return rpl::single(On(flag)) | rpl::then(Changes() | rpl::map([=] {
  35. return On(flag);
  36. })) | rpl::distinct_until_changed();
  37. }
  38. } // namespace PowerSaving