From 7eb7bae9ff2ecd1a73295d3e1d719c7162324ef5 Mon Sep 17 00:00:00 2001 From: Mattia Mascarello Date: Wed, 14 Jan 2026 01:44:33 +0100 Subject: [PATCH] Ignore battery percentage placeholder if not present in strings --- .gitignore | 3 ++- main.go | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index c14a297..62344ca 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -go.sum \ No newline at end of file +go.sum +battery-monitor \ No newline at end of file diff --git a/main.go b/main.go index fdca448..231a787 100644 --- a/main.go +++ b/main.go @@ -258,8 +258,13 @@ func (m *Monitor) check() error { if newLevel != m.currentLevel && newLevel != "normal" { log.Printf("Battery level changed to: %s (%d%%)", newLevel, capacity) + var message string 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 id, err := m.notifier.Send(title, message, "critical", level.Icon)