Check battery level automatically every minute and play sound when necessary

This commit is contained in:
Matti Viljanen 2019-01-05 22:02:01 +02:00
parent ac9e3a088b
commit 28ed6b936d
2 changed files with 33 additions and 6 deletions

View file

@ -31,15 +31,15 @@ DISTFILES += qml/harbour-batterybuddy.qml \
# Begin: include sound files
OTHER_FILES += sounds/upperLimit.ogg \
sounds/lowerLimit.ogg \
#OTHER_FILES += sounds/upperLimit.ogg \
# sounds/lowerLimit.ogg \
DEPLOYMENT_PATH = /usr/share/$${TARGET}
#DEPLOYMENT_PATH = /usr/share/$${TARGET}
sounds.files = sounds
sounds.path = $${DEPLOYMENT_PATH}
#sounds.files = sounds
#sounds.path = $${DEPLOYMENT_PATH}
INSTALLS += sounds
#INSTALLS += sounds
# End: include sound files

View file

@ -1,4 +1,5 @@
import QtQuick 2.0
import QtMultimedia 5.6
import Sailfish.Silica 1.0
Page {
@ -7,6 +8,32 @@ Page {
// The effective value will be restricted by ApplicationWindow.allowedOrientations
allowedOrientations: Orientation.All
MediaPlayer {
id: alertLow
audioRole: MediaPlayer.NotificationRole
autoLoad: true
source: settings.lowAlertFile
}
MediaPlayer {
id: alertHigh
audioRole: MediaPlayer.NotificationRole
autoLoad: true
source: settings.highAlertFile
}
Timer {
interval: 60000
running: true
repeat: true
onTriggered: {
if(battery.charge <= settings.lowerLimit && battery.charging === false)
alertLow.play()
else if(battery.charge >= settings.upperLimit && battery.charging === true)
alertLow.play()
}
}
// To enable PullDownMenu, place our content in a SilicaFlickable
SilicaFlickable {
anchors.fill: parent