mirror of
https://github.com/MatMasIt/ligthweight_battery_notify.git
synced 2026-01-20 11:36:52 +01:00
Ignore battery percentage placeholder if not present in strings
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
go.sum
|
go.sum
|
||||||
|
battery-monitor
|
||||||
7
main.go
7
main.go
@@ -258,8 +258,13 @@ func (m *Monitor) check() error {
|
|||||||
if newLevel != m.currentLevel && newLevel != "normal" {
|
if newLevel != m.currentLevel && newLevel != "normal" {
|
||||||
log.Printf("Battery level changed to: %s (%d%%)", newLevel, capacity)
|
log.Printf("Battery level changed to: %s (%d%%)", newLevel, capacity)
|
||||||
|
|
||||||
|
var message string
|
||||||
title := level.Title
|
title := level.Title
|
||||||
message := fmt.Sprintf(level.Message, capacity)
|
if strings.Contains(level.Message, "%d") {
|
||||||
|
message = fmt.Sprintf(level.Message, capacity)
|
||||||
|
} else {
|
||||||
|
message = level.Message
|
||||||
|
}
|
||||||
|
|
||||||
// Send notification - it will replace previous one if ID exists
|
// Send notification - it will replace previous one if ID exists
|
||||||
id, err := m.notifier.Send(title, message, "critical", level.Icon)
|
id, err := m.notifier.Send(title, message, "critical", level.Icon)
|
||||||
|
|||||||
Reference in New Issue
Block a user