- create a new shared state file to manage message state
- replace broadcast.Message with shared.Message in pomodoro logic
- update websocket client handling to use shared.Clients
- remove unnecessary broadcast imports from various files
- ensure consistent message handling across the application
🤖
33 lines
795 B
Go
33 lines
795 B
Go
package pomodoro
|
|
|
|
import (
|
|
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
|
|
"time"
|
|
)
|
|
|
|
// startTimer runs the countdown and shared. every second.
|
|
func startTimer(remainingSeconds int, mode string) bool {
|
|
for remainingSeconds > 0 {
|
|
select {
|
|
case <-pomodoroResetChannel:
|
|
return false
|
|
case <-pomodoroPauseChannel:
|
|
// Nothing to set here, just waiting for the signal
|
|
case <-pomodoroResumeChannel:
|
|
// Nothing to set here, just waiting for the signal
|
|
default:
|
|
// Broadcast the current state to all clients
|
|
if !IsPomodoroPaused() {
|
|
shared.Message.Mode = mode
|
|
shared.Message.TimeLeft = remainingSeconds
|
|
time.Sleep(time.Second)
|
|
remainingSeconds--
|
|
}
|
|
}
|
|
}
|
|
|
|
// Final shared.when time reaches zero
|
|
shared.Message.TimeLeft = remainingSeconds
|
|
|
|
return true
|
|
}
|