BatteryWidget: add low battery threshold

NSpinBox: add bootstrap icons
This commit is contained in:
Ly-sec 2025-09-09 13:26:15 +02:00
parent 663f3abff5
commit b422a419cd
3 changed files with 16 additions and 5 deletions

View file

@ -57,9 +57,7 @@ Item {
// Only notify once we are a below threshold // Only notify once we are a below threshold
if (!charging && !root.hasNotifiedLowBattery && percent <= warningThreshold) { if (!charging && !root.hasNotifiedLowBattery && percent <= warningThreshold) {
root.hasNotifiedLowBattery = true root.hasNotifiedLowBattery = true
// Maybe go with toast ? ToastService.showWarning("Low Battery", `Battery is at ${Math.round(percent)}%. Please connect the charger.`)
Quickshell.execDetached(
["notify-send", "-u", "critical", "-i", "battery-caution", "Low Battery", `Battery is at ${p}%. Please connect charger.`])
} else if (root.hasNotifiedLowBattery && (charging || percent > warningThreshold + 5)) { } else if (root.hasNotifiedLowBattery && (charging || percent > warningThreshold + 5)) {
// Reset when charging starts or when battery recovers 5% above threshold // Reset when charging starts or when battery recovers 5% above threshold
root.hasNotifiedLowBattery = false root.hasNotifiedLowBattery = false

View file

@ -16,10 +16,13 @@ ColumnLayout {
// Local state // Local state
property bool valueAlwaysShowPercentage: widgetData.alwaysShowPercentage property bool valueAlwaysShowPercentage: widgetData.alwaysShowPercentage
!== undefined ? widgetData.alwaysShowPercentage : widgetMetadata.alwaysShowPercentage !== undefined ? widgetData.alwaysShowPercentage : widgetMetadata.alwaysShowPercentage
property int valueWarningThreshold: widgetData.warningThreshold
!== undefined ? widgetData.warningThreshold : widgetMetadata.warningThreshold
function saveSettings() { function saveSettings() {
var settings = Object.assign({}, widgetData || {}) var settings = Object.assign({}, widgetData || {})
settings.alwaysShowPercentage = valueAlwaysShowPercentage settings.alwaysShowPercentage = valueAlwaysShowPercentage
settings.warningThreshold = valueWarningThreshold
return settings return settings
} }
@ -28,4 +31,14 @@ ColumnLayout {
checked: root.valueAlwaysShowPercentage checked: root.valueAlwaysShowPercentage
onToggled: checked => root.valueAlwaysShowPercentage = checked onToggled: checked => root.valueAlwaysShowPercentage = checked
} }
NSpinBox {
label: "Low battery warning threshold"
description: "Show a warning when battery falls below this percentage."
value: valueWarningThreshold
suffix: "%"
minimum: 5
maximum: 50
onValueChanged: valueWarningThreshold = value
}
} }

View file

@ -95,7 +95,7 @@ RowLayout {
NIcon { NIcon {
anchors.centerIn: parent anchors.centerIn: parent
text: "dash-lg" text: "\uF2E6"
font.pointSize: Style.fontSizeS * scaling font.pointSize: Style.fontSizeS * scaling
color: decreaseArea.containsMouse ? Color.mOnPrimary : Color.mPrimary color: decreaseArea.containsMouse ? Color.mOnPrimary : Color.mPrimary
} }
@ -130,7 +130,7 @@ RowLayout {
NIcon { NIcon {
anchors.centerIn: parent anchors.centerIn: parent
text: "plus-lg" text: "\uF4FA"
font.pointSize: Style.fontSizeS * scaling font.pointSize: Style.fontSizeS * scaling
color: increaseArea.containsMouse ? Color.mOnPrimary : Color.mPrimary color: increaseArea.containsMouse ? Color.mOnPrimary : Color.mPrimary
} }