Merge remote-tracking branch 'handydevcom/power_saving_v3' into aurora_beta

This commit is contained in:
Nikolai Sinyov 2024-07-02 16:27:46 +03:00
commit e813f334bb
4 changed files with 20 additions and 1 deletions

View file

@ -81,6 +81,8 @@ namespace {
const QString TYPE_ANIMATED_EMOJI("animatedEmoji"); const QString TYPE_ANIMATED_EMOJI("animatedEmoji");
const QString TYPE_INPUT_MESSAGE_REPLY_TO_MESSAGE("inputMessageReplyToMessage"); const QString TYPE_INPUT_MESSAGE_REPLY_TO_MESSAGE("inputMessageReplyToMessage");
const QString TYPE_DRAFT_MESSAGE("draftMessage"); const QString TYPE_DRAFT_MESSAGE("draftMessage");
const double POWERSAVING_TDLIB_REQUEST_INTERVAL = 100;
} }
static QString getChatPositionOrder(const QVariantMap &position) static QString getChatPositionOrder(const QVariantMap &position)
@ -191,9 +193,15 @@ void TDLibReceiver::setActive(bool active)
} else { } else {
LOG("Deactivating receiver loop, this may take a while..."); LOG("Deactivating receiver loop, this may take a while...");
} }
this->powerSavingMode = false;
this->isActive = active; this->isActive = active;
} }
void TDLibReceiver::setPowerSavingMode(bool powerSavingMode)
{
this->powerSavingMode = powerSavingMode;
}
void TDLibReceiver::receiverLoop() void TDLibReceiver::receiverLoop()
{ {
LOG("Starting receiver loop"); LOG("Starting receiver loop");
@ -205,6 +213,9 @@ void TDLibReceiver::receiverLoop()
VERBOSE("Raw result:" << receivedJsonDocument.toJson(QJsonDocument::Indented).constData()); VERBOSE("Raw result:" << receivedJsonDocument.toJson(QJsonDocument::Indented).constData());
processReceivedDocument(receivedJsonDocument); processReceivedDocument(receivedJsonDocument);
} }
if(this->powerSavingMode) {
msleep(POWERSAVING_TDLIB_REQUEST_INTERVAL);
}
} }
LOG("Stopping receiver loop"); LOG("Stopping receiver loop");
} }

View file

@ -35,6 +35,7 @@ class TDLibReceiver : public QThread
public: public:
explicit TDLibReceiver(void *tdLibClient, QObject *parent = nullptr); explicit TDLibReceiver(void *tdLibClient, QObject *parent = nullptr);
void setActive(bool active); void setActive(bool active);
void setPowerSavingMode(bool active);
signals: signals:
void versionDetected(const QString &version); void versionDetected(const QString &version);
@ -115,6 +116,7 @@ private:
QHash<QString, Handler> handlers; QHash<QString, Handler> handlers;
void *tdLibClient; void *tdLibClient;
bool isActive; bool isActive;
bool powerSavingMode;
private: private:
static const QVariantList cleanupList(const QVariantList& list, bool *updated = Q_NULLPTR); static const QVariantList cleanupList(const QVariantList& list, bool *updated = Q_NULLPTR);

View file

@ -22,6 +22,7 @@
#include <QDir> #include <QDir>
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#include <QGuiApplication>
#include <QLocale> #include <QLocale>
#include <QProcess> #include <QProcess>
#include <QSysInfo> #include <QSysInfo>
@ -102,7 +103,7 @@ TDLibWrapper::TDLibWrapper(AppSettings *settings, MceInterface *mce, QObject *pa
connect(this->appSettings, SIGNAL(useOpenWithChanged()), this, SLOT(handleOpenWithChanged())); connect(this->appSettings, SIGNAL(useOpenWithChanged()), this, SLOT(handleOpenWithChanged()));
connect(this->appSettings, SIGNAL(storageOptimizerChanged()), this, SLOT(handleStorageOptimizerChanged())); connect(this->appSettings, SIGNAL(storageOptimizerChanged()), this, SLOT(handleStorageOptimizerChanged()));
connect(qGuiApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(handleApplicationStateChanged(Qt::ApplicationState)));
connect(networkConfigurationManager, SIGNAL(configurationChanged(QNetworkConfiguration)), this, SLOT(handleNetworkConfigurationChanged(QNetworkConfiguration))); connect(networkConfigurationManager, SIGNAL(configurationChanged(QNetworkConfiguration)), this, SLOT(handleNetworkConfigurationChanged(QNetworkConfiguration)));
this->setLogVerbosityLevel(); this->setLogVerbosityLevel();
@ -2211,6 +2212,10 @@ void TDLibWrapper::handleGetPageSourceFinished()
} }
} }
void TDLibWrapper::handleApplicationStateChanged(Qt::ApplicationState state) {
this->tdLibReceiver->setPowerSavingMode(state != Qt::ApplicationState::ApplicationActive);
}
QVariantMap& TDLibWrapper::fillTdlibParameters(QVariantMap& parameters) QVariantMap& TDLibWrapper::fillTdlibParameters(QVariantMap& parameters)
{ {
parameters.insert("api_id", TDLIB_API_ID); parameters.insert("api_id", TDLIB_API_ID);

View file

@ -373,6 +373,7 @@ public slots:
void handleNetworkConfigurationChanged(const QNetworkConfiguration &config); void handleNetworkConfigurationChanged(const QNetworkConfiguration &config);
void handleActiveEmojiReactionsUpdated(const QStringList& emojis); void handleActiveEmojiReactionsUpdated(const QStringList& emojis);
void handleGetPageSourceFinished(); void handleGetPageSourceFinished();
void handleApplicationStateChanged(Qt::ApplicationState state);
private: private:
void setOption(const QString &name, const QString &type, const QVariant &value); void setOption(const QString &name, const QString &type, const QVariant &value);