From d919d14e391a6c984db45551afda884572f220e8 Mon Sep 17 00:00:00 2001
From: Kevin Lyda <kevin@lyda.ie>
Date: Thu, 6 Apr 2023 09:33:37 +0100
Subject: [PATCH] Be smarter about battery warning.

---
 modules/battery.go | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/modules/battery.go b/modules/battery.go
index 71de37f..eccca1d 100644
--- a/modules/battery.go
+++ b/modules/battery.go
@@ -128,9 +128,11 @@ func (b *BatteryMod) Render() string {
 	color := b.ColorOK
 	percent := 100 * (batt.Current / batt.Design)
 	if percent < 20 {
-		if len(b.WarnCmd) != 0 && time.Now().Unix()-b.warnTime > 60 {
+		now := time.Now().Unix()
+		if len(b.WarnCmd) != 0 && batt.State != battery.Charging && now-b.warnTime > 60 {
 			cmd := exec.Command(b.WarnCmd[0], b.WarnCmd[1:]...)
 			cmd.Run()
+			b.warnTime = now
 		}
 		color = b.Color20
 	}
-- 
GitLab