Skip to content

Commit 418f3c2

Browse files
committed
Resolve conflict and fixes according to linter
1 parent ef337ae commit 418f3c2

2 files changed

Lines changed: 12 additions & 16 deletions

File tree

decks/main.deck

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,6 @@
6060
[keys.action_hold]
6161
keycode = "Mute"
6262

63-
[[keys]]
64-
index = 7
65-
[keys.widget]
66-
id = "timer"
67-
[keys.widget.config]
68-
times = "5s;10m;30m;1h5m" # optional
69-
format = "%Hh;%Im;%Ss"
70-
font = "bold;regular;thin" # optional
71-
#color = "#fefefe" # optional
72-
underflow = "false" # optional
73-
underflowColor = "#ff0000;#ff0000;#ff0000" # optional
74-
75-
7663
[[keys]]
7764
index = 8
7865
[keys.widget]

widget_timer.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"time"
88
)
99

10-
// TimerWidget is a widget displaying a timer
10+
// TimerWidget is a widget displaying a timer.
1111
type TimerWidget struct {
1212
*BaseWidget
1313

@@ -26,29 +26,34 @@ type TimerWidget struct {
2626
data TimerData
2727
}
2828

29+
// TimerData represents the current state of the timer.
2930
type TimerData struct {
3031
startTime time.Time
3132
pausedTime time.Time
3233
}
3334

35+
// IsPaused returns whether the timer is paused.
3436
func (d *TimerData) IsPaused() bool {
3537
return !d.pausedTime.IsZero()
3638
}
3739

40+
// IsRunning returns whether the timer is running.
3841
func (d *TimerData) IsRunning() bool {
3942
return !d.IsPaused() && d.HasDeadline()
4043
}
4144

45+
// HasDeadline returns whether the start time is set.
4246
func (d *TimerData) HasDeadline() bool {
4347
return !d.startTime.IsZero()
4448
}
4549

50+
// Clear resets the state of the timer.
4651
func (d *TimerData) Clear() {
4752
d.startTime = time.Time{}
4853
d.pausedTime = time.Time{}
4954
}
5055

51-
// NewTimerWidget returns a new TimerWidget
56+
// NewTimerWidget returns a new TimerWidget.
5257
func NewTimerWidget(bw *BaseWidget, opts WidgetConfig) *TimerWidget {
5358
bw.setInterval(time.Duration(opts.Interval)*time.Millisecond, time.Second/2)
5459

@@ -147,8 +152,10 @@ func (w *TimerWidget) Update() error {
147152
return w.render(w.dev, img)
148153
}
149154

155+
// Timespan represents the duration between two events.
150156
type Timespan time.Duration
151157

158+
// Format returns the formatted version of the timespan.
152159
func (t Timespan) Format(format string, adaptive bool) string {
153160
formatStr := format
154161
tm := map[string]string{
@@ -193,13 +200,15 @@ func (t Timespan) Format(format string, adaptive bool) string {
193200
return timeStr
194201
}
195202

203+
// ReplaceAll does a replacement with all entries of a map.
196204
func ReplaceAll(str string, tm map[string]string) string {
197205
for k, v := range tm {
198206
str = strings.ReplaceAll(str, k, v)
199207
}
200208
return str
201209
}
202210

211+
// TriggerAction updates the timer state.
203212
func (w *TimerWidget) TriggerAction(hold bool) {
204213
if hold {
205214
if w.data.IsPaused() {
@@ -211,7 +220,7 @@ func (w *TimerWidget) TriggerAction(hold bool) {
211220
if w.data.IsRunning() {
212221
w.data.pausedTime = time.Now()
213222
} else if w.data.IsPaused() && w.data.HasDeadline() {
214-
pausedDuration := time.Now().Sub(w.data.pausedTime)
223+
pausedDuration := time.Since(w.data.pausedTime)
215224
w.data.startTime = w.data.startTime.Add(pausedDuration)
216225
w.data.pausedTime = time.Time{}
217226
} else {

0 commit comments

Comments
 (0)