first commit

This commit is contained in:
Flummi 2024-01-17 20:06:16 +01:00
commit efbda53ab4
Signed by: Flummi
GPG Key ID: AA2AEF822A6F4817
10 changed files with 87 additions and 0 deletions

1
README.md Normal file
View File

@ -0,0 +1 @@
# Headset Battery Widget

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -0,0 +1,65 @@
import QtQuick 2.0
import QtQuick.Layouts 1.3
import org.kde.plasma.plasmoid 2.0
import org.kde.plasma.core 2.0 as PlasmaCore
Item {
id: main
property int batteryPercent: -2
PlasmaCore.DataSource {
id: hsSource
engine: "executable"
connectedSources: ["headsetcontrol -bc"]
interval: 2000
onNewData: {
if(data['exit_code'] > 0)
return console.log('error lol');
batteryPercent = data['stdout'];
}
}
Plasmoid.preferredRepresentation: Plasmoid.compactRepresentation
Plasmoid.compactRepresentation: Item {
Layout.minimumWidth: units.iconSizes.medium
Image {
anchors.fill: parent
smooth: true
fillMode: Image.PreserveAspectFit
source: batteryIcon()
Plasmoid.toolTipMainText: "battery status:"
Plasmoid.toolTipSubText: batteryStatus()
}
function batteryIcon() {
let iconName = "battery_100"
if(batteryPercent == -1) // charing
iconName = "battery_charging"
else if(batteryPercent == -2) // not connected
iconName = "battery_nc";
else if(batteryPercent > 80)
iconName = "battery_100";
else if(batteryPercent > 60)
iconName = "battery_80";
else if(batteryPercent > 40)
iconName = "battery_60";
else if(batteryPercent > 20)
iconName = "battery_40";
else
iconName = "battery_20";
return "../icons/" + iconName + ".png";
}
function batteryStatus() {
if(batteryPercent == -1)
return "charging";
else if(batteryPercent == -2)
return "not connected";
else
return batteryPercent + " %";
}
}
}

21
package/metadata.json Normal file
View File

@ -0,0 +1,21 @@
{
"KPlugin": {
"Authors": [{
"Email": "flummi@srv.fail",
"Name": "Flummi"
}],
"Category": "System Information",
"Dependencies": [
],
"Icon": "battery",
"Id": "org.kde.plasma.headsetcontrol-battery-widget",
"Name": "Headset Battery Widget",
"ServiceTypes": [
"Plasma/Applet"
],
"Version": "1",
"Website": "https://git.lat/Flummi/headsetcontrol-battery-widget"
},
"X-Plasma-API": "declarativeappletscript",
"X-Plasma-MainScript": "ui/main.qml"
}