Skip to content

Commit cb6878c

Browse files
hollesseclaude
andcommitted
Remove IsActive() from Timer interface - factories return nil instead
Timer implementations now control their activation by returning nil from their factory functions when not configured, eliminating the need for the IsActive() method in the Timer interface. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9a8f74b commit cb6878c

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

timer/localtimer/localtimer.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import (
1515

1616
func init() {
1717
timer.Register(func(configuration config.Configuration) timer.Timer {
18+
if !configuration.TimerLocal {
19+
return nil
20+
}
1821
return NewProcessLocalTimer(configuration)
1922
})
2023
}
@@ -28,10 +31,6 @@ func NewProcessLocalTimer(configuration config.Configuration) ProcessLocalTimer
2831
return ProcessLocalTimer{configuration: configuration}
2932
}
3033

31-
func (t ProcessLocalTimer) IsActive() bool {
32-
return t.configuration.TimerLocal
33-
}
34-
3534
func (t ProcessLocalTimer) StartTimer(minutes int) error {
3635
timeoutInSeconds := minutes * 60
3736
if err := ExecuteCommandsInBackgroundProcess(

timer/timer.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import (
1313

1414
// Timer abstracts timer functionality so different implementations can be used.
1515
type Timer interface {
16-
IsActive() bool
1716
StartTimer(minutes int) error
1817
StartBreakTimer(minutes int) error
1918
}
2019

2120
// Factory creates a Timer for the given configuration.
21+
// Returns nil if the timer should not be active.
2222
type Factory func(configuration config.Configuration) Timer
2323

2424
var factories []Factory
@@ -29,12 +29,12 @@ func Register(f Factory) {
2929
factories = append(factories, f)
3030
}
3131

32-
// GetTimers returns all registered timers that report themselves as active.
32+
// GetTimers returns all registered timers that are active for the given configuration.
3333
func GetTimers(configuration config.Configuration) []Timer {
3434
var active []Timer
3535
for _, f := range factories {
3636
t := f(configuration)
37-
if t.IsActive() {
37+
if t != nil {
3838
active = append(active, t)
3939
}
4040
}
@@ -48,9 +48,8 @@ func RunTimer(timerInMinutes string, configuration config.Configuration) error {
4848
return err
4949
}
5050

51-
timeoutInSeconds := timeoutInMinutes * 60
5251
timeOfTimeout := time.Now().Add(time.Minute * time.Duration(timeoutInMinutes)).Format("15:04")
53-
say.Debug(fmt.Sprintf("Starting timer at %s for %d minutes = %d seconds (parsed from user input %s)", timeOfTimeout, timeoutInMinutes, timeoutInSeconds, timerInMinutes))
52+
say.Debug(fmt.Sprintf("Starting timer at %s for %d minutes (parsed from user input %s)", timeOfTimeout, timeoutInMinutes, timerInMinutes))
5453

5554
timers := GetTimers(configuration)
5655
if len(timers) == 0 {
@@ -76,9 +75,8 @@ func RunBreakTimer(timerInMinutes string, configuration config.Configuration) er
7675
return err
7776
}
7877

79-
timeoutInSeconds := timeoutInMinutes * 60
8078
timeOfTimeout := time.Now().Add(time.Minute * time.Duration(timeoutInMinutes)).Format("15:04")
81-
say.Debug(fmt.Sprintf("Starting break timer at %s for %d minutes = %d seconds (parsed from user input %s)", timeOfTimeout, timeoutInMinutes, timeoutInSeconds, timerInMinutes))
79+
say.Debug(fmt.Sprintf("Starting break timer at %s for %d minutes (parsed from user input %s)", timeOfTimeout, timeoutInMinutes, timerInMinutes))
8280

8381
timers := GetTimers(configuration)
8482
if len(timers) == 0 {

timer/webtimer/webtimer.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import (
1111

1212
func init() {
1313
timer.Register(func(configuration config.Configuration) timer.Timer {
14+
if configuration.TimerRoom == "" {
15+
return nil
16+
}
1417
return NewWebTimer(configuration)
1518
})
1619
}
@@ -32,10 +35,6 @@ func NewWebTimer(configuration config.Configuration) WebTimer {
3235
}
3336
}
3437

35-
func (t WebTimer) IsActive() bool {
36-
return t.room != ""
37-
}
38-
3938
func (t WebTimer) StartTimer(minutes int) error {
4039
if err := httpPutTimer(minutes, t.room, t.timerUser, t.timerUrl, t.timerInsecure); err != nil {
4140
return fmt.Errorf("remote timer couldn't be started: %w", err)

0 commit comments

Comments
 (0)