refactor(power): use onBattery to replace batteryState to check is used battery

This commit is contained in:
justforlxz 2019-06-13 15:08:24 +08:00
parent 099fa9f9f5
commit 2e7a4e6fa9
No known key found for this signature in database
GPG Key ID: 593AFD577C1B1A60
2 changed files with 2 additions and 3 deletions

View File

@ -210,9 +210,8 @@ void PowerPlugin::refreshTipsData()
const uint percentage = qMin(100.0, qMax(0.0, data.value("Display")));
const QString value = QString("%1%").arg(std::round(percentage));
const int batteryState = m_powerInter->batteryState()["Display"];
const bool charging = (batteryState == BatteryState::CHARGING || batteryState == BatteryState::FULLY_CHARGED);
if (!charging) {
if (m_powerInter->onBattery()) {
qulonglong timeToEmpty = m_systemPowerInter->batteryTimeToEmpty();
QDateTime time = QDateTime::fromTime_t(timeToEmpty).toUTC();
uint hour = time.toString("hh").toUInt();

View File

@ -67,7 +67,7 @@ QPixmap PowerStatusWidget::getBatteryIcon()
const uint value = qMin(100.0, qMax(0.0, data.value("Display")));
const int percentage = std::round(value);
const int batteryState = m_powerInter->batteryState()["Display"];
const bool plugged = (batteryState == BatteryState::CHARGING || batteryState == BatteryState::FULLY_CHARGED);
const bool plugged = !m_powerInter->onBattery();
QString percentageStr;
if (percentage < 10 && percentage >= 0) {