Skip to content

Commit

Permalink
feat(battery): decouple not charging from discharging
Browse files Browse the repository at this point in the history
resolves #2237
  • Loading branch information
JanDeDobbeleer committed May 10, 2022
1 parent 0daeb98 commit e392ab6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
7 changes: 4 additions & 3 deletions docs/docs/segments/battery.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ Battery displays the remaining power percentage for your battery.
## Properties

- display_error: `boolean` - show the error context when failing to retrieve the battery information - defaults to `false`
- charging_icon: `string` - icon to display on the left when charging - defaults to empty
- discharging_icon: `string` - icon to display on the left when discharging - defaults to empty
- charged_icon: `string` - icon to display on the left when fully charged - defaults to empty
- charging_icon: `string` - icon to display when charging - defaults to empty
- discharging_icon: `string` - icon to display when discharging - defaults to empty
- charged_icon: `string` - icon to display when fully charged - defaults to empty
- not_charging_icon: `string` - icon to display when fully charged - defaults to empty

## Template ([info][templates])

Expand Down
6 changes: 5 additions & 1 deletion src/segments/battery.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
DischargingIcon properties.Property = "discharging_icon"
// ChargedIcon to display when fully charged
ChargedIcon properties.Property = "charged_icon"
// NotChargingIcon to display when on AC power
NotChargingIcon properties.Property = "not_charging_icon"
)

func (b *Battery) Template() string {
Expand All @@ -48,8 +50,10 @@ func (b *Battery) Enabled() bool {
}

switch b.BatteryInfo.State {
case battery.Discharging, battery.NotCharging:
case battery.Discharging:
b.Icon = b.props.GetString(DischargingIcon, "")
case battery.NotCharging:
b.Icon = b.props.GetString(NotChargingIcon, "")
case battery.Charging:
b.Icon = b.props.GetString(ChargingIcon, "")
case battery.Full:
Expand Down
12 changes: 9 additions & 3 deletions themes/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -371,19 +371,25 @@
"charging_icon": {
"type": "string",
"title": "Charging Icon",
"description": "Text/icon to display on the left when charging",
"description": "Text/icon to display when charging",
"default": ""
},
"discharging_icon": {
"type": "string",
"title": "discharging Dcon",
"description": "Text/icon to display on the left when discharging",
"description": "Text/icon to display when discharging",
"default": ""
},
"charged_icon": {
"type": "string",
"title": "Charged Icon",
"description": "Text/icon to display on the left when fully charged",
"description": "Text/icon to display when fully charged",
"default": ""
},
"not_charging_icon": {
"type": "string",
"title": "Not Charging Icon",
"description": "Text/icon to display when on AC power",
"default": ""
}
}
Expand Down

0 comments on commit e392ab6

Please sign in to comment.