mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 17:33:05 +00:00
Fix battery icon not updating when charging
Use property BatteryState instead of OnBattery which does not update when the battery is plugged into a power source (tried on a Matebook D 14). Battery is considered charging if BatteryState is 1 (charging) or 4 (fully charged). Change-Id: I5a0cf7bf8ee4cd313af885322d1edb67868c555a
This commit is contained in:
parent
b6fa4335eb
commit
4dfd6cabc4
@ -102,7 +102,8 @@ QWidget *PowerPlugin::itemTipsWidget(const QString &itemKey)
|
||||
|
||||
const uint percentage = qMin(100.0, qMax(0.0, data.value("Display")));
|
||||
const QString value = QString("%1%").arg(std::round(percentage));
|
||||
const bool charging = !m_powerInter->onBattery();
|
||||
const int batteryState = m_powerInter->batteryState()["Display"];
|
||||
const bool charging = (batteryState == BatteryState::CHARGING || batteryState == BatteryState::FULLY_CHARGED);
|
||||
|
||||
if (!charging) {
|
||||
qint64 timeToEmpty = -1;
|
||||
@ -115,8 +116,6 @@ QWidget *PowerPlugin::itemTipsWidget(const QString &itemKey)
|
||||
.arg(QDateTime::fromTime_t(timeToEmpty).toUTC().toString("hh:mm:ss"))
|
||||
);
|
||||
} else {
|
||||
const int batteryState = m_powerInter->batteryState()["Display"];
|
||||
|
||||
if (batteryState == BatteryState::FULLY_CHARGED || percentage == 100.)
|
||||
m_tipsLabel->setText(tr("Charged %1 Battery Is Charged").arg(value));
|
||||
else {
|
||||
|
@ -20,6 +20,7 @@
|
||||
*/
|
||||
|
||||
#include "powerstatuswidget.h"
|
||||
#include "powerplugin.h"
|
||||
|
||||
#include <QPainter>
|
||||
#include <QIcon>
|
||||
@ -65,7 +66,8 @@ QPixmap PowerStatusWidget::getBatteryIcon()
|
||||
const BatteryPercentageMap data = m_powerInter->batteryPercentage();
|
||||
const uint value = qMin(100.0, qMax(0.0, data.value("Display")));
|
||||
const int percentage = std::round(value);
|
||||
const bool plugged = !m_powerInter->onBattery();
|
||||
const int batteryState = m_powerInter->batteryState()["Display"];
|
||||
const bool plugged = (batteryState == BatteryState::CHARGING || batteryState == BatteryState::FULLY_CHARGED);
|
||||
|
||||
QString percentageStr;
|
||||
if (percentage < 10 && percentage >= 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user