Compare commits

..

4 Commits

Author SHA1 Message Date
4adea966fa critical notification & bugfix 2024-01-25 16:53:07 +01:00
d821e5b5c0 notifications! 2024-01-25 16:21:39 +01:00
f3529afeb1 debug mode 2024-01-22 03:08:31 +01:00
b15a5946a7 fix 100% charge lol 2024-01-22 03:08:25 +01:00
7 changed files with 159 additions and 12 deletions

View File

@ -5,6 +5,11 @@ ConfigModel {
ConfigCategory {
name: i18n("General")
icon: "configure"
source: "configGeneral.qml"
source: "config/general.qml"
}
ConfigCategory {
name: i18n("Debug")
icon: "cab_view"
source: "config/debug.qml"
}
}

View File

@ -12,7 +12,6 @@
<entry name="batteryheight" type="Int">
<default>8</default>
</entry>
<entry name="colorEmpty" type="String">
<default>#ff0000</default>
</entry>
@ -22,5 +21,20 @@
<entry name="colorFull" type="String">
<default>#008800</default>
</entry>
<entry name="batteryThreshold" type="Int">
<default>10</default>
</entry>
<entry name="notifications" type="Bool">
<default>true</default>
</entry>
<!-- debug -->
<entry name="debug_active" type="Bool">
<default>false</default>
</entry>
<entry name="debug_charge" type="Int">
<default>0</default>
</entry>
</group>
</kcfg>

View File

@ -7,13 +7,10 @@ import org.kde.kirigami 2.14 as Kirigami
import "./lib/helper.js" as Helper
Item {
Layout.minimumWidth: units.iconSizes.medium
Layout.alignment: Qt.AlignHCenter
Rectangle { // battery
id: container
anchors.fill: parent
anchors.rightMargin: 2
anchors.rightMargin: 1
anchors.topMargin: 10 - batteryheight
anchors.bottomMargin: 10 - batteryheight
color: "transparent"
@ -29,7 +26,7 @@ Item {
anchors.left: parent.left
anchors.top: parent.top
anchors.bottom: parent.bottom
color: Helper.interpolateColor(parseFloat("." + batteryPercent), [ colorEmpty, colorHalf, colorFull ])
color: Helper.interpolateColor(batteryPercent / 100, [ colorEmpty, colorHalf, colorFull ])
width: parent.width * Math.max(0, Math.min(batteryPercent, 100)) / 100
}
Kirigami.Icon { // headphones icon

View File

@ -0,0 +1,57 @@
import QtQuick 2.0
import QtQuick.Layouts 1.3
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import QtQuick.Controls 2.5 as QQC2
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kquickcontrols 2.0 as KQControls
import "../lib/helper.js" as Helper
QQC2.Pane {
id: root
property alias cfg_debug_active: debug_active.checked
property alias cfg_debug_charge: debug_charge.value
Kirigami.FormLayout {
anchors.fill: parent
wideMode: false
GridLayout {
columns: 3
rows: 2
rowSpacing: 10
// first row
Text {
text: "debug:"
color: PlasmaCore.Theme.textColor
}
PlasmaComponents.CheckBox {
id: debug_active
}
Text {
text: ""
}
// second row
Text {
text: "battery charge:"
color: PlasmaCore.Theme.textColor
}
PlasmaComponents.Slider {
id: debug_charge
value: 0
minimumValue: -2
maximumValue: 100
stepSize: 1
}
Text {
text: cfg_debug_charge + "%"
color: PlasmaCore.Theme.textColor
}
}
}
}

View File

@ -6,7 +6,7 @@ import QtQuick.Controls 2.5 as QQC2
import org.kde.kirigami 2.4 as Kirigami
import org.kde.kquickcontrols 2.0 as KQControls
import "./lib/helper.js" as Helper
import "../lib/helper.js" as Helper
QQC2.Pane {
id: root
@ -17,6 +17,9 @@ QQC2.Pane {
property alias cfg_colorHalf: colorHalf.color
property alias cfg_colorFull: colorFull.color
property alias cfg_notifications: notifications.checked
property alias cfg_batteryThreshold: batteryThreshold.value
Kirigami.FormLayout {
anchors.fill: parent
wideMode: false
@ -157,5 +160,40 @@ QQC2.Pane {
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
}
}
}
}

View File

@ -14,7 +14,7 @@ const rgb2Hex = rgb => "#" + ((1 << 24) + (rgb.r << 16) + (rgb.g << 8) + rgb.b).
const interpolateColor = (f, c) => {
if(!f) return "transparent";
if(f >= 1) return c.pop();
if(f <= 0) return c[0];
if(f <= 0) return c.shift();
f *= c.length - 1;
const i = ~~f;

View File

@ -4,6 +4,8 @@ import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.kirigami 2.14 as Kirigami
import org.kde.notification 1.0
import "./lib/helper.js" as Helper
Item {
@ -14,7 +16,15 @@ Item {
property string colorEmpty: Plasmoid.configuration.colorEmpty
property string colorHalf: Plasmoid.configuration.colorHalf
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 int debug_charge: Plasmoid.configuration.debug_charge
property int batteryPercent: -2
property bool notification_sent: false;
PlasmaCore.DataSource {
id: hsSource
@ -22,13 +32,39 @@ Item {
connectedSources: ["headsetcontrol -bc"]
interval: pollingrate * 1e3
onNewData: {
return batteryPercent = data['exit code'] > 0
if(debug_active)
batteryPercent = debug_charge;
else
batteryPercent = data['exit code'] > 0
? -2 // not connected
: data['stdout'];
: +data.stdout;
// send notification if necessary
if(batteryPercent <= batteryThreshold && batteryPercent >= 0 && !notification_sent && notifications) {
notification_sent = true;
notification.text = "Battery Level is low (" + batteryPercent + "%)";
notification.title = "Headset Battery Level Alert";
notification.iconName = "notification-battery-low";
notification.sendEvent();
}
// reset notifications if battery level is over batteryThreshold
if((batteryPercent > batteryThreshold || batteryPercent < 0) && notification_sent && notifications) {
notification_sent = false;
}
return;
}
}
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
Plasmoid.fullRepresentation: FullRepresentation{}
Plasmoid.compactRepresentation: CompactRepresentation{}
Notification {
id: notification
componentName: "plasma_workspace"
eventId: "notification"
flags: Notification.DefaultEvent
urgency: Notification.CriticalUrgency
}
}