notifications!
This commit is contained in:
parent
f3529afeb1
commit
d821e5b5c0
|
@ -22,6 +22,13 @@
|
||||||
<default>#008800</default>
|
<default>#008800</default>
|
||||||
</entry>
|
</entry>
|
||||||
|
|
||||||
|
<entry name="batteryThreshold" type="Int">
|
||||||
|
<default>10</default>
|
||||||
|
</entry>
|
||||||
|
<entry name="notifications" type="Bool">
|
||||||
|
<default>true</default>
|
||||||
|
</entry>
|
||||||
|
|
||||||
<!-- debug -->
|
<!-- debug -->
|
||||||
<entry name="debug_active" type="Bool">
|
<entry name="debug_active" type="Bool">
|
||||||
<default>false</default>
|
<default>false</default>
|
||||||
|
|
|
@ -7,13 +7,10 @@ import org.kde.kirigami 2.14 as Kirigami
|
||||||
import "./lib/helper.js" as Helper
|
import "./lib/helper.js" as Helper
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
Layout.minimumWidth: units.iconSizes.medium
|
|
||||||
Layout.alignment: Qt.AlignHCenter
|
|
||||||
|
|
||||||
Rectangle { // battery
|
Rectangle { // battery
|
||||||
id: container
|
id: container
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.rightMargin: 2
|
anchors.rightMargin: 1
|
||||||
anchors.topMargin: 10 - batteryheight
|
anchors.topMargin: 10 - batteryheight
|
||||||
anchors.bottomMargin: 10 - batteryheight
|
anchors.bottomMargin: 10 - batteryheight
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
|
|
|
@ -17,6 +17,9 @@ QQC2.Pane {
|
||||||
property alias cfg_colorHalf: colorHalf.color
|
property alias cfg_colorHalf: colorHalf.color
|
||||||
property alias cfg_colorFull: colorFull.color
|
property alias cfg_colorFull: colorFull.color
|
||||||
|
|
||||||
|
property alias cfg_notifications: notifications.checked
|
||||||
|
property alias cfg_batteryThreshold: batteryThreshold.value
|
||||||
|
|
||||||
Kirigami.FormLayout {
|
Kirigami.FormLayout {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
wideMode: false
|
wideMode: false
|
||||||
|
@ -157,5 +160,40 @@ QQC2.Pane {
|
||||||
color: Helper.interpolateColor( 1, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
|
color: Helper.interpolateColor( 1, [ cfg_colorEmpty.toString(), cfg_colorHalf.toString(), cfg_colorFull.toString() ])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GridLayout {
|
||||||
|
columns: 3
|
||||||
|
rows: 2
|
||||||
|
rowSpacing: 10
|
||||||
|
|
||||||
|
// first row
|
||||||
|
Text {
|
||||||
|
text: "notifications:"
|
||||||
|
color: PlasmaCore.Theme.textColor
|
||||||
|
}
|
||||||
|
PlasmaComponents.CheckBox {
|
||||||
|
id: notifications
|
||||||
|
}
|
||||||
|
Text {
|
||||||
|
text: ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// second row
|
||||||
|
Text {
|
||||||
|
text: "battery threshold:"
|
||||||
|
color: PlasmaCore.Theme.textColor
|
||||||
|
}
|
||||||
|
PlasmaComponents.Slider {
|
||||||
|
id: batteryThreshold
|
||||||
|
value: 10
|
||||||
|
minimumValue: 1
|
||||||
|
maximumValue: 50
|
||||||
|
stepSize: 1
|
||||||
|
}
|
||||||
|
Text {
|
||||||
|
text: cfg_batteryThreshold
|
||||||
|
color: PlasmaCore.Theme.textColor
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@ import org.kde.plasma.plasmoid 2.0
|
||||||
import org.kde.plasma.core 2.0 as PlasmaCore
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
||||||
import org.kde.kirigami 2.14 as Kirigami
|
import org.kde.kirigami 2.14 as Kirigami
|
||||||
|
|
||||||
|
import org.kde.notification 1.0
|
||||||
|
|
||||||
import "./lib/helper.js" as Helper
|
import "./lib/helper.js" as Helper
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
|
@ -15,10 +17,14 @@ Item {
|
||||||
property string colorHalf: Plasmoid.configuration.colorHalf
|
property string colorHalf: Plasmoid.configuration.colorHalf
|
||||||
property string colorFull: Plasmoid.configuration.colorFull
|
property string colorFull: Plasmoid.configuration.colorFull
|
||||||
|
|
||||||
|
property bool notifications: Plasmoid.configuration.notifications
|
||||||
|
property int batteryThreshold: Plasmoid.configuration.batteryThreshold
|
||||||
|
|
||||||
property bool debug_active: Plasmoid.configuration.debug_active
|
property bool debug_active: Plasmoid.configuration.debug_active
|
||||||
property int debug_charge: Plasmoid.configuration.debug_charge
|
property int debug_charge: Plasmoid.configuration.debug_charge
|
||||||
|
|
||||||
property int batteryPercent: -2
|
property int batteryPercent: -2
|
||||||
|
property bool notification_sent: false;
|
||||||
|
|
||||||
PlasmaCore.DataSource {
|
PlasmaCore.DataSource {
|
||||||
id: hsSource
|
id: hsSource
|
||||||
|
@ -27,15 +33,36 @@ Item {
|
||||||
interval: pollingrate * 1e3
|
interval: pollingrate * 1e3
|
||||||
onNewData: {
|
onNewData: {
|
||||||
if(debug_active)
|
if(debug_active)
|
||||||
return batteryPercent = debug_charge;
|
batteryPercent = debug_charge;
|
||||||
|
else
|
||||||
|
batteryPercent = data['exit code'] > 0
|
||||||
|
? -2 // not connected
|
||||||
|
: +data.stdout;
|
||||||
|
|
||||||
return batteryPercent = data['exit code'] > 0
|
// send notification if necessary
|
||||||
? -2 // not connected
|
if(batteryPercent <= batteryThreshold && batteryPercent >= 0 && !notification_sent && notifications) {
|
||||||
: data['stdout'];
|
notification_sent = true;
|
||||||
|
notification.text = "Battery Level is low (" + batteryPercent + "%)";
|
||||||
|
notification.title = "Headset Battery Level Alert";
|
||||||
|
notification.iconName = "notification-battery-low";
|
||||||
|
notification.sendEvent();
|
||||||
|
}
|
||||||
|
else // reset notifications if battery level is over batteryThreshold
|
||||||
|
notification_sent = false;
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
|
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
|
||||||
Plasmoid.fullRepresentation: FullRepresentation{}
|
Plasmoid.fullRepresentation: FullRepresentation{}
|
||||||
Plasmoid.compactRepresentation: CompactRepresentation{}
|
Plasmoid.compactRepresentation: CompactRepresentation{}
|
||||||
|
|
||||||
|
Notification {
|
||||||
|
id: notification
|
||||||
|
componentName: "plasma_workspace"
|
||||||
|
eventId: "notification"
|
||||||
|
flags: Notification.Persistent
|
||||||
|
urgency: Notification.HighUrgency
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user