From c3b35cdd2d5b403a52103b90088b11251318ee63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torjus=20H=C3=A5kestad?= Date: Sun, 10 Mar 2024 19:07:34 +0100 Subject: [PATCH] Add duration to log --- main.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index fa5349a..51a18b5 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "log/slog" "os" "os/signal" + "time" "github.com/godbus/dbus/v5" "github.com/holoplot/go-evdev" @@ -49,6 +50,7 @@ func main() { input.Close() }() + var lastOn time.Time // Start listening for PTT key slog.Info("Starting event listener", "version", Version) for !done { @@ -62,10 +64,12 @@ func main() { } if ev.Code == evdev.KEY_F24 && ev.Value == 1 { slog.Info("PTT ON") + lastOn = time.Now() obj.Call("net.sourceforge.mumble.Mumble.startTalking", 0) } if ev.Code == evdev.KEY_F24 && ev.Value == 0 { - slog.Info("PTT OFF") + speakDuration := time.Since(lastOn).String() + slog.Info("PTT OFF", "duration", speakDuration) obj.Call("net.sourceforge.mumble.Mumble.stopTalking", 0) } }