feat: update timer management
- rename timerRunning to pomodoroRunning
- move function and timer definition to correct source file
🤖
This commit is contained in:
parent
90f80cc685
commit
c9501c3bbb
3 changed files with 10 additions and 10 deletions
|
@ -12,12 +12,13 @@ const (
|
||||||
sessions = 4
|
sessions = 4
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var pomodoroRunning bool
|
||||||
var mu sync.Mutex // to synchronize access to shared state
|
var mu sync.Mutex // to synchronize access to shared state
|
||||||
|
|
||||||
// RunPomodoroTimer iterates the Pomodoro work/break sessions.
|
// RunPomodoroTimer iterates the Pomodoro work/break sessions.
|
||||||
func RunPomodoroTimer(clients map[*websocket.Conn]bool) {
|
func RunPomodoroTimer(clients map[*websocket.Conn]bool) {
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
timerRunning = true
|
pomodoroRunning = true
|
||||||
|
|
||||||
for session := 1; session <= sessions; session++ {
|
for session := 1; session <= sessions; session++ {
|
||||||
if !startTimer(clients, workDuration, "Work", session) {
|
if !startTimer(clients, workDuration, "Work", session) {
|
||||||
|
@ -34,6 +35,11 @@ func RunPomodoroTimer(clients map[*websocket.Conn]bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
timerRunning = false
|
pomodoroRunning = false
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsPomodoroRunning returns the status of the timer.
|
||||||
|
func IsPomodoroRunning() bool {
|
||||||
|
return pomodoroRunning
|
||||||
|
}
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var timerRunning bool
|
|
||||||
var timerStopChannel = make(chan bool, 1)
|
var timerStopChannel = make(chan bool, 1)
|
||||||
|
|
||||||
// startTimer runs the countdown and broadcasts every second.
|
// startTimer runs the countdown and broadcasts every second.
|
||||||
|
@ -44,8 +43,3 @@ func startTimer(clients map[*websocket.Conn]bool, remainingSeconds int, mode str
|
||||||
func StopTimer() {
|
func StopTimer() {
|
||||||
timerStopChannel <- true
|
timerStopChannel <- true
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsTimerRunning returns the status of the timer.
|
|
||||||
func IsTimerRunning() bool {
|
|
||||||
return timerRunning
|
|
||||||
}
|
|
||||||
|
|
|
@ -29,11 +29,11 @@ func handleClientCommands(ws *websocket.Conn) {
|
||||||
// Process the command
|
// Process the command
|
||||||
switch command.Command {
|
switch command.Command {
|
||||||
case "start":
|
case "start":
|
||||||
if !pomodoro.IsTimerRunning() {
|
if !pomodoro.IsPomodoroRunning() {
|
||||||
go pomodoro.RunPomodoroTimer(Clients) // Start the timer with the list of clients
|
go pomodoro.RunPomodoroTimer(Clients) // Start the timer with the list of clients
|
||||||
}
|
}
|
||||||
case "stop":
|
case "stop":
|
||||||
if pomodoro.IsTimerRunning() {
|
if pomodoro.IsPomodoroRunning() {
|
||||||
pomodoro.StopTimer() // Stop the timer in the Pomodoro package
|
pomodoro.StopTimer() // Stop the timer in the Pomodoro package
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue