2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Implement some power saving options.

This commit is contained in:
John Preston
2023-02-21 16:31:55 +04:00
parent 02bc950b57
commit 2a4c39b9d7
53 changed files with 446 additions and 108 deletions

View File

@@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/premium_graphics.h"
#include "ui/emoji_config.h"
#include "ui/painter.h"
#include "ui/power_saving.h"
#include "ui/ui_utility.h"
#include "ui/cached_round_corners.h"
#include "boxes/sticker_set_box.h"
@@ -709,9 +710,13 @@ object_ptr<TabbedSelector::InnerFooter> EmojiListWidget::createFooter() {
Expects(_footer == nullptr);
using FooterDescriptor = StickersListFooter::Descriptor;
const auto flag = powerSavingFlag();
const auto footerPaused = [method = pausedMethod(), flag]() {
return On(flag) || method();
};
auto result = object_ptr<StickersListFooter>(FooterDescriptor{
.session = &session(),
.paused = pausedMethod(),
.paused = footerPaused,
.parent = this,
.st = &st(),
});
@@ -1006,7 +1011,7 @@ void EmojiListWidget::validateEmojiPaintContext(
.size = QSize(_customSingleSize, _customSingleSize),
.now = crl::now(),
.scale = context.progress,
.paused = paused(),
.paused = On(powerSavingFlag()) || paused(),
.scaled = context.expanding,
};
if (!_emojiPaintContext) {
@@ -2179,6 +2184,14 @@ QPoint EmojiListWidget::buttonRippleTopLeft(int section) const {
: QPoint());
}
PowerSaving::Flag EmojiListWidget::powerSavingFlag() const {
const auto reactions = (_mode == Mode::FullReactions)
|| (_mode == Mode::RecentReactions);
return reactions
? PowerSaving::kEmojiReactions
: PowerSaving::kEmojiPanel;
}
void EmojiListWidget::refreshEmoji() {
refreshRecent();
refreshCustom();

View File

@@ -24,6 +24,10 @@ namespace Data {
class StickersSet;
} // namespace Data
namespace PowerSaving {
enum Flag : uint32;
} // namespace PowerSaving
namespace tr {
template <typename ...Tags>
struct phrase;
@@ -322,6 +326,7 @@ private:
[[nodiscard]] std::unique_ptr<Ui::RippleAnimation> createButtonRipple(
int section);
[[nodiscard]] QPoint buttonRippleTopLeft(int section) const;
[[nodiscard]] PowerSaving::Flag powerSavingFlag() const;
void repaintCustom(uint64 setId);

View File

@@ -22,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/wrap/vertical_layout.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/popup_menu.h"
#include "ui/power_saving.h"
#include "ui/ui_utility.h"
#include "data/data_session.h"
#include "data/data_user.h"
@@ -325,6 +326,9 @@ void InitMessageFieldHandlers(
const style::InputField *fieldStyle) {
field->setTagMimeProcessor(
FieldTagMimeProcessor(session, allowPremiumEmoji));
const auto paused = [customEmojiPaused] {
return On(PowerSaving::kEmojiChat) || customEmojiPaused();
};
field->setCustomEmojiFactory(
session->data().customEmojiManager().factory(),
std::move(customEmojiPaused));

View File

@@ -27,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/premium_graphics.h"
#include "ui/image/image.h"
#include "ui/cached_round_corners.h"
#include "ui/power_saving.h"
#include "lottie/lottie_multi_player.h"
#include "lottie/lottie_single_player.h"
#include "lottie/lottie_animation.h"
@@ -265,10 +266,14 @@ auto StickersListWidget::choosingUpdated() const
object_ptr<TabbedSelector::InnerFooter> StickersListWidget::createFooter() {
Expects(_footer == nullptr);
const auto footerPaused = [method = pausedMethod()] {
return On(PowerSaving::kStickersPanel) || method();
};
using FooterDescriptor = StickersListFooter::Descriptor;
auto result = object_ptr<StickersListFooter>(FooterDescriptor{
.session = &session(),
.paused = pausedMethod(),
.paused = footerPaused,
.parent = this,
.settingsButtonVisible = true,
});
@@ -854,7 +859,8 @@ void StickersListWidget::paintStickers(Painter &p, QRect clip) {
: &_selected);
const auto now = crl::now();
const auto paused = this->paused();
const auto paused = On(PowerSaving::kStickersPanel)
|| this->paused();
if (sets.empty() && _section == Section::Search) {
paintEmptySearchResults(p);
}