Skip to content

Commit

Permalink
Merge pull request #1132 from deXol/develop
Browse files Browse the repository at this point in the history
[BLE] Fix multiple low battery notification
  • Loading branch information
limpkin authored Jan 23, 2023
2 parents 47dbd37 + f397c5e commit ed65010
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "DeviceDetector.h"
#include "SystemNotifications/SystemNotification.h"

#include "qtcsv/stringdata.h"
#include "qtcsv/reader.h"

const QString MainWindow::NONE_STRING = tr("None");
Expand Down Expand Up @@ -291,15 +290,23 @@ MainWindow::MainWindow(WSClient *client, DbMasterController *mc, QWidget *parent
[this]()
{
ui->lineEdit_AvailableUsers->setText("");
m_firstBatteryPctReceived = BatteryNotiStatus::NO_STATUS;
});
connect(wsClient, &WSClient::updateBatteryPercent,
[this](int battery)
{
DeviceDetector::instance().setBattery(battery);
ui->pbBleBattery->setValue(battery);
if (battery < BATTERY_WARNING_LIMIT && !ui->label_charging->isVisible())
if (battery < BATTERY_WARNING_LIMIT && !ui->label_charging->isVisible() &&
BatteryNotiStatus::VALID_BATTERY_RECIEVED == m_firstBatteryPctReceived)
{
SystemNotification::instance().createNotification(tr("Low Battery"), tr("Battery is below %1%, please charge your Mooltipass.").arg(BATTERY_WARNING_LIMIT));
m_firstBatteryPctReceived = BatteryNotiStatus::LOW_BATTERY_DISPLAYED;
}
// Only display low battery warning after we received a valid battery pct
if (BatteryNotiStatus::NO_STATUS == m_firstBatteryPctReceived)
{
m_firstBatteryPctReceived = BatteryNotiStatus::VALID_BATTERY_RECIEVED;
}
});

Expand All @@ -313,6 +320,7 @@ MainWindow::MainWindow(WSClient *client, DbMasterController *mc, QWidget *parent
else
{
ui->label_charging->hide();
m_firstBatteryPctReceived = BatteryNotiStatus::NO_STATUS;
}
});

Expand Down
9 changes: 9 additions & 0 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,15 @@ private slots:

bool m_notesFetched = false;

enum class BatteryNotiStatus
{
NO_STATUS,
VALID_BATTERY_RECIEVED,
LOW_BATTERY_DISPLAYED
};

BatteryNotiStatus m_firstBatteryPctReceived = BatteryNotiStatus::NO_STATUS;

bool m_computerUnlocked = true;
struct LockUnlockItem
{
Expand Down

0 comments on commit ed65010

Please sign in to comment.