Don't try to close unopened notifications

This commit is contained in:
Matti Viljanen 2022-03-20 19:17:50 +02:00
parent 479dfd590b
commit 705cae455f
No known key found for this signature in database
GPG key ID: CF32A1495158F888
2 changed files with 10 additions and 3 deletions

View file

@ -269,14 +269,16 @@ void Battery::showHighNotification() {
&& !(charge == 100 && state == "idle")) { && !(charge == 100 && state == "idle")) {
logV(QString("Notification: %1").arg(settings->getNotificationTitle().arg(charge))); logV(QString("Notification: %1").arg(settings->getNotificationTitle().arg(charge)));
chargeNotification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationHighText(), settings->getHighAlertFile()); chargeNotification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationHighText(), settings->getHighAlertFile());
unclosedChargeNotification = true;
if(settings->getHighNotificationsInterval() == 50) { if(settings->getHighNotificationsInterval() == 50) {
logD("Stop high battery timer"); logD("Stop high battery timer");
highNotifyTimer->stop(); highNotifyTimer->stop();
} }
} }
else if(charge > settings->getLowAlert()) { else if(unclosedChargeNotification && charge > settings->getLowAlert()) {
logD("Close high battery notification"); logD("Close high battery notification");
chargeNotification->close(); chargeNotification->close();
unclosedChargeNotification = true;
} }
} }
@ -284,14 +286,16 @@ void Battery::showLowNotification() {
if(settings->getLowNotificationsInterval() > 0 && charge <= settings->getLowAlert() && state != "charging") { if(settings->getLowNotificationsInterval() > 0 && charge <= settings->getLowAlert() && state != "charging") {
logV(QString("Notification: %1").arg(settings->getNotificationTitle().arg(charge))); logV(QString("Notification: %1").arg(settings->getNotificationTitle().arg(charge)));
chargeNotification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationLowText(), settings->getLowAlertFile()); chargeNotification->send(settings->getNotificationTitle().arg(charge), settings->getNotificationLowText(), settings->getLowAlertFile());
unclosedChargeNotification = true;
if(settings->getLowNotificationsInterval() == 50) { if(settings->getLowNotificationsInterval() == 50) {
logD("Stop low battery timer"); logD("Stop low battery timer");
lowNotifyTimer->stop(); lowNotifyTimer->stop();
} }
} }
else if(charge < settings->getHighAlert()) { else if(unclosedChargeNotification && charge < settings->getHighAlert()) {
logD("Close low battery notification"); logD("Close low battery notification");
chargeNotification->close(); chargeNotification->close();
unclosedChargeNotification = true;
} }
} }
@ -329,12 +333,13 @@ void Battery::showHealthNotification() {
} }
logD(QString("Notification: %1").arg(settings->getNotificationHealthTitle().arg(titleArgs))); logD(QString("Notification: %1").arg(settings->getNotificationHealthTitle().arg(titleArgs)));
healthNotification->send(settings->getNotificationHealthTitle().arg(titleArgs), notificationText, settings->getHealthAlertFile()); healthNotification->send(settings->getNotificationHealthTitle().arg(titleArgs), notificationText, settings->getHealthAlertFile());
unclosedHealthNotification = true;
if(settings->getHealthNotificationsInterval() == 50) { if(settings->getHealthNotificationsInterval() == 50) {
logD("Stop health timer"); logD("Stop health timer");
healthNotifyTimer->stop(); healthNotifyTimer->stop();
} }
} }
else if(HealthState[health] == HealthThresh["ok"] || HealthState[health] < settings->getHealthAlert()) { else if(unclosedHealthNotification && (HealthState[health] == HealthThresh["ok"] || HealthState[health] < settings->getHealthAlert())) {
logD("Close health notification"); logD("Close health notification");
healthNotification->close(); healthNotification->close();
} }

View file

@ -59,6 +59,8 @@ public slots:
void shutdown(); void shutdown();
private: private:
bool unclosedChargeNotification = false;
bool unclosedHealthNotification = false;
BackgroundActivity::Frequency frequencies[14] = { BackgroundActivity::Frequency frequencies[14] = {
BackgroundActivity::Range, BackgroundActivity::Range,