File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ import (
2121 "github.com/remotemobprogramming/mob/v5/help"
2222 "github.com/remotemobprogramming/mob/v5/open"
2323 "github.com/remotemobprogramming/mob/v5/say"
24- timerpkg "github.com/remotemobprogramming/mob/v5/timer"
24+ "github.com/remotemobprogramming/mob/v5/timer/localtimer "
2525 "github.com/remotemobprogramming/mob/v5/workdir"
2626)
2727
@@ -453,7 +453,7 @@ func currentTime() string {
453453
454454func moo (configuration config.Configuration ) {
455455 voiceMessage := "moo"
456- err := timerpkg .ExecuteCommandsInBackgroundProcess (timerpkg .VoiceCommand (voiceMessage , configuration .VoiceCommand ))
456+ err := localtimer .ExecuteCommandsInBackgroundProcess (localtimer .VoiceCommand (voiceMessage , configuration .VoiceCommand ))
457457
458458 if err != nil {
459459 say .Warning (fmt .Sprintf ("can't run voice command on your system (%s)" , runtime .GOOS ))
Original file line number Diff line number Diff line change 44 config "github.com/remotemobprogramming/mob/v5/configuration"
55 "github.com/remotemobprogramming/mob/v5/exit"
66 timerpkg "github.com/remotemobprogramming/mob/v5/timer"
7+ _ "github.com/remotemobprogramming/mob/v5/timer/localtimer"
8+ _ "github.com/remotemobprogramming/mob/v5/timer/webtimer"
79)
810
911func StartTimer (timerInMinutes string , configuration config.Configuration ) {
Original file line number Diff line number Diff line change 1- package timer
1+ package localtimer
22
33import (
44 "fmt"
@@ -9,9 +9,16 @@ import (
99 config "github.com/remotemobprogramming/mob/v5/configuration"
1010 "github.com/remotemobprogramming/mob/v5/exit"
1111 "github.com/remotemobprogramming/mob/v5/say"
12+ "github.com/remotemobprogramming/mob/v5/timer"
1213 "github.com/remotemobprogramming/mob/v5/workdir"
1314)
1415
16+ func init () {
17+ timer .Register (func (configuration config.Configuration ) timer.Timer {
18+ return NewProcessLocalTimer (configuration )
19+ })
20+ }
21+
1522// ProcessLocalTimer is a Timer implementation that uses background OS processes.
1623type ProcessLocalTimer struct {
1724 configuration config.Configuration
Original file line number Diff line number Diff line change @@ -18,14 +18,22 @@ type Timer interface {
1818 StartBreakTimer (minutes int ) error
1919}
2020
21- // GetTimers returns all timers that report themselves as active.
21+ // Factory creates a Timer for the given configuration.
22+ type Factory func (configuration config.Configuration ) Timer
23+
24+ var factories []Factory
25+
26+ // Register adds a Timer factory to the registry.
27+ // Implementation packages call this in their init() function.
28+ func Register (f Factory ) {
29+ factories = append (factories , f )
30+ }
31+
32+ // GetTimers returns all registered timers that report themselves as active.
2233func GetTimers (configuration config.Configuration ) []Timer {
23- all := []Timer {
24- NewWebTimer (configuration ),
25- NewProcessLocalTimer (configuration ),
26- }
2734 var active []Timer
28- for _ , t := range all {
35+ for _ , f := range factories {
36+ t := f (configuration )
2937 if t .IsActive () {
3038 active = append (active , t )
3139 }
Original file line number Diff line number Diff line change 1- package timer
1+ package webtimer
22
33import (
44 "encoding/json"
55 "fmt"
66
77 config "github.com/remotemobprogramming/mob/v5/configuration"
88 "github.com/remotemobprogramming/mob/v5/httpclient"
9+ "github.com/remotemobprogramming/mob/v5/timer"
910)
1011
12+ func init () {
13+ timer .Register (func (configuration config.Configuration ) timer.Timer {
14+ return NewWebTimer (configuration )
15+ })
16+ }
17+
1118// WebTimer is a Timer implementation that notifies a remote timer service via HTTP.
1219type WebTimer struct {
13- room string
14- timerUser string
15- timerUrl string
16- timerInsecure bool
20+ room string
21+ timerUser string
22+ timerUrl string
23+ timerInsecure bool
1724}
1825
1926func NewWebTimer (configuration config.Configuration ) WebTimer {
You can’t perform that action at this time.
0 commit comments