battery_saving.h 968 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. namespace base::Platform {
  9. class AbstractBatterySaving {
  10. public:
  11. virtual ~AbstractBatterySaving() = default;
  12. virtual std::optional<bool> enabled() const = 0;
  13. };
  14. [[nodiscard]] std::unique_ptr<AbstractBatterySaving> CreateBatterySaving(
  15. Fn<void()> changeCallback);
  16. } // namespace base::Platform
  17. namespace base {
  18. class BatterySaving final {
  19. public:
  20. BatterySaving();
  21. ~BatterySaving();
  22. [[nodiscard]] bool supported() const {
  23. return enabled().has_value();
  24. }
  25. [[nodiscard]] std::optional<bool> enabled() const;
  26. [[nodiscard]] rpl::producer<bool> value() const;
  27. private:
  28. const std::unique_ptr<Platform::AbstractBatterySaving> _helper;
  29. rpl::variable<std::optional<bool>> _value;
  30. };
  31. } // namespace base