Fix broken battery notification timer

This commit is contained in:
Matti Viljanen 2020-03-28 10:13:00 +02:00
parent 01e06c8192
commit 49b197ff60
No known key found for this signature in database
GPG key ID: CF32A1495158F888
2 changed files with 14 additions and 9 deletions

View file

@ -63,17 +63,28 @@ ApplicationWindow
interval: settings.interval * 1000 interval: settings.interval * 1000
running: settings.notificationsEnabled running: settings.notificationsEnabled
repeat: true repeat: true
triggeredOnStart: true
onTriggered: { onTriggered: {
if(battery.charge <= settings.lowerLimit && battery.state === "discharging") { if(settings.notificationsEnabled && battery.charge <= settings.lowAlert && battery.state === "discharging") {
console.info("Battery notification timer: empty enough battery")
alertLow.play() alertLow.play()
notification.republish() notification.republish()
} }
else if(battery.charge >= settings.upperLimit && else if((battery.charge >= settings.highAlert && battery.state === "charging")
(battery.state === "charging" && battery.charging === true) || (battery.state === "idle" && battery.charging === false)) { || (battery.charge === 100 && battery.state === "idle")) {
console.info("Battery notification timer: full enough battery")
alertHigh.play() alertHigh.play()
notification.republish() notification.republish()
} }
else if(notification.replacesId > 0) { else if(notification.replacesId > 0) {
console.info("Battery notification timer: close notification")
notification.close()
}
}
onRunningChanged: {
console.debug("alertTimer is " + (running ? "" : "not ") + "running")
if(notification.replacesId > 0) {
console.info("Battery notification timer: close notification")
notification.close() notification.close()
} }
} }

View file

@ -23,12 +23,6 @@ Page {
id: settingsPage id: settingsPage
allowedOrientations: Orientation.Portrait | Orientation.Landscape | Orientation.LandscapeInverted allowedOrientations: Orientation.Portrait | Orientation.Landscape | Orientation.LandscapeInverted
onStatusChanged: {
if(status === PageStatus.Activating) {
settingsTimer.start()
}
}
Timer { Timer {
id: settingsTimer id: settingsTimer
interval: 10 interval: 10