Skip to content

Commit

Permalink
Resolve conflict and fixes according to linter
Browse files Browse the repository at this point in the history
  • Loading branch information
zMoooooritz committed Feb 8, 2022
1 parent ef337ae commit 418f3c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
13 changes: 0 additions & 13 deletions decks/main.deck
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,6 @@
[keys.action_hold]
keycode = "Mute"

[[keys]]
index = 7
[keys.widget]
id = "timer"
[keys.widget.config]
times = "5s;10m;30m;1h5m" # optional
format = "%Hh;%Im;%Ss"
font = "bold;regular;thin" # optional
#color = "#fefefe" # optional
underflow = "false" # optional
underflowColor = "#ff0000;#ff0000;#ff0000" # optional


[[keys]]
index = 8
[keys.widget]
Expand Down
15 changes: 12 additions & 3 deletions widget_timer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"
)

// TimerWidget is a widget displaying a timer
// TimerWidget is a widget displaying a timer.
type TimerWidget struct {
*BaseWidget

Expand All @@ -26,29 +26,34 @@ type TimerWidget struct {
data TimerData
}

// TimerData represents the current state of the timer.
type TimerData struct {
startTime time.Time
pausedTime time.Time
}

// IsPaused returns whether the timer is paused.
func (d *TimerData) IsPaused() bool {
return !d.pausedTime.IsZero()
}

// IsRunning returns whether the timer is running.
func (d *TimerData) IsRunning() bool {
return !d.IsPaused() && d.HasDeadline()
}

// HasDeadline returns whether the start time is set.
func (d *TimerData) HasDeadline() bool {
return !d.startTime.IsZero()
}

// Clear resets the state of the timer.
func (d *TimerData) Clear() {
d.startTime = time.Time{}
d.pausedTime = time.Time{}
}

// NewTimerWidget returns a new TimerWidget
// NewTimerWidget returns a new TimerWidget.
func NewTimerWidget(bw *BaseWidget, opts WidgetConfig) *TimerWidget {
bw.setInterval(time.Duration(opts.Interval)*time.Millisecond, time.Second/2)

Expand Down Expand Up @@ -147,8 +152,10 @@ func (w *TimerWidget) Update() error {
return w.render(w.dev, img)
}

// Timespan represents the duration between two events.
type Timespan time.Duration

// Format returns the formatted version of the timespan.
func (t Timespan) Format(format string, adaptive bool) string {
formatStr := format
tm := map[string]string{
Expand Down Expand Up @@ -193,13 +200,15 @@ func (t Timespan) Format(format string, adaptive bool) string {
return timeStr
}

// ReplaceAll does a replacement with all entries of a map.
func ReplaceAll(str string, tm map[string]string) string {
for k, v := range tm {
str = strings.ReplaceAll(str, k, v)
}
return str
}

// TriggerAction updates the timer state.
func (w *TimerWidget) TriggerAction(hold bool) {
if hold {
if w.data.IsPaused() {
Expand All @@ -211,7 +220,7 @@ func (w *TimerWidget) TriggerAction(hold bool) {
if w.data.IsRunning() {
w.data.pausedTime = time.Now()
} else if w.data.IsPaused() && w.data.HasDeadline() {
pausedDuration := time.Now().Sub(w.data.pausedTime)
pausedDuration := time.Since(w.data.pausedTime)
w.data.startTime = w.data.startTime.Add(pausedDuration)
w.data.pausedTime = time.Time{}
} else {
Expand Down

0 comments on commit 418f3c2

Please sign in to comment.