From 3165c0254df15af8747fadfe2f3696f86591887a Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Fri, 14 Apr 2023 11:02:16 -0500 Subject: [PATCH] Find Active or Most Recent Timer --- cli/cli.go | 7 +++++++ cmd/i3status.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cli/cli.go b/cli/cli.go index bc37449..19fbb04 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -165,6 +165,13 @@ func (p *Program) GetFilteredTimerList(args []string) *timertxt.TimerList { return list.Filter(doFilters) } +func (p *Program) GetActiveOrMostRecent() (*timertxt.Timer, error) { + work, wErr := p.TimerList.GetActiveOrMostRecent() + if wErr == nil { + return work, nil + } + return p.GetMostRecentTimer() +} func (p *Program) GetMostRecentTimer() (*timertxt.Timer, error) { work, wErr := p.TimerList.GetMostRecentTimer() if wErr == nil && work.FinishDate.IsZero() { diff --git a/cmd/i3status.go b/cmd/i3status.go index 7ff5465..6edefdb 100644 --- a/cmd/i3status.go +++ b/cmd/i3status.go @@ -46,7 +46,7 @@ func opI3Status(cmd *cobra.Command, args []string) error { return nil } state := "Idle" - wrk, err := p.GetMostRecentTimer() + wrk, err := p.GetActiveOrMostRecent() if err != nil { fmt.Print("{\"icon\":\"time\",\"state\":\"Critical\", \"text\": \"Error loading timer entry\"}") return nil