diff options
| author | Hayden Hamilton <hayden@hhvn.uk> | 2026-06-03 16:33:56 +0100 |
|---|---|---|
| committer | Hayden Hamilton <hayden@hhvn.uk> | 2026-06-03 16:33:56 +0100 |
| commit | eca2774bae841168afff8a435b5f8341cbdd6eb7 (patch) | |
| tree | 307d88d5d83b372a8a696a25c1611781c5a207e9 | |
| parent | 25cd38bb49d22ffa42008a83ae86fba405fd2e14 (diff) | |
// Previously this status would sleep all the way until the next day.
// This worked fine until the device entered sleep/hibernation
//
// Therefore a limit was added. Not the ideal solution,
// as if the device is woken within config.MaxSleep,
// then the date will not update until some extra time has elapsed.
//
// TODO: a better solution
if (until > config.MaxSleep) {
until = config.MaxSleep
}
time.Sleep(until)
| -rw-r--r-- | config/config.go | 8 | ||||
| -rw-r--r-- | status/04-date.go | 18 |
2 files changed, 24 insertions, 2 deletions
diff --git a/config/config.go b/config/config.go index 6b52e8c..9487d30 100644 --- a/config/config.go +++ b/config/config.go @@ -1,6 +1,9 @@ package config // import "hhvn.uk/hbspbar/config" -import "image/color" +import ( + "image/color" + "time" +) // Bar height var H uint = 17 @@ -39,3 +42,6 @@ var FontYPad int = 1 // Space between status elements var StatusPad int = 15 + +// Maximum time.Sleep() allowed +var MaxSleep = time.Minute * 15 diff --git a/status/04-date.go b/status/04-date.go index cd8f7f2..fba68d6 100644 --- a/status/04-date.go +++ b/status/04-date.go @@ -17,7 +17,23 @@ func date(b *Block) error { // Sleep til the next day comes around tmrw := time.Now().AddDate(0, 0, 1) tmrw = time.Date(tmrw.Year(), tmrw.Month(), tmrw.Day(), 0, 0, 0, 0, time.Local) - time.Sleep(time.Until(tmrw)) + + var until time.Duration + until = time.Until(tmrw) + + // Previously this status would sleep all the way until the next day. + // This worked fine until the device entered sleep/hibernation + // + // Therefore a limit was added. Not the ideal solution, + // as if the device is woken within config.MaxSleep, + // then the date will not update until some extra time has elapsed. + // + // TODO: a better solution + if (until > config.MaxSleep) { + until = config.MaxSleep + } + + time.Sleep(until) } _, err := b.drawText(0, config.Fg, time.Now().Local().Format("Mon 02/01")) |