Compare commits

..

No commits in common. "0b2f83cd35bbc73fcedd5944277297c351a835db" and "3d5cb29c54b2a17455e20189695706c381a28dbb" have entirely different histories.

5 changed files with 15 additions and 47 deletions

View file

@ -6,10 +6,6 @@ A pomodoro server written in Go
`go install git.smsvc.net/pomodoro/GoTomato@latest`
## Usage
See `GoTomato --help` for Parameters
## Testing
```

View file

@ -1,31 +1,16 @@
package server
import (
"flag"
"fmt"
"git.smsvc.net/pomodoro/GoTomato/internal/websocket"
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
"log"
"net/http"
)
func Start() {
// Define CLI flags for ListenAddress and ListenPort
listenAddress := flag.String("listenAddress", "0.0.0.0", "IP address to listen on")
listenPort := flag.Int("listenPort", 8080, "Port to listen on")
flag.Parse()
serverConfig := models.GoTomatoServerConfig{
ListenAddress: *listenAddress,
ListenPort: *listenPort,
}
listen := fmt.Sprintf("%s:%d", serverConfig.ListenAddress, serverConfig.ListenPort)
http.HandleFunc("/ws", websocket.HandleConnections)
log.Printf("Pomodoro WebSocket server started on %s\n", listen)
err := http.ListenAndServe(listen, nil)
log.Println("Pomodoro WebSocket server started on :8080")
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatalf("Error starting server: %v", err)
}

View file

@ -7,12 +7,12 @@ import (
"sync"
)
var PomodoroConfig = models.GoTomatoTimerConfig{
Work: 15 * 60,
ShortBreak: 5 * 60,
LongBreak: 10 * 60,
Sessions: 4,
}
const (
workDuration = 15 * 60
shortBreakDuration = 5 * 60
longBreakDuration = 10 * 60
sessions = 4
)
var pomodoroRunning bool
var pomodoroPaused bool
@ -30,16 +30,16 @@ func RunPomodoroTimer(clients map[*websocket.Conn]*models.Client) {
pomodoroPaused = false
mu.Unlock()
for session := 1; session <= PomodoroConfig.Sessions; session++ {
if !startTimer(clients, PomodoroConfig.Work, "Work", session) {
for session := 1; session <= sessions; session++ {
if !startTimer(clients, workDuration, "Work", session) {
break
}
if session == PomodoroConfig.Sessions {
if !startTimer(clients, PomodoroConfig.LongBreak, "LongBreak", session) {
if session == sessions {
if !startTimer(clients, longBreakDuration, "LongBreak", session) {
break
}
} else {
if !startTimer(clients, PomodoroConfig.ShortBreak, "ShortBreak", session) {
if !startTimer(clients, shortBreakDuration, "ShortBreak", session) {
break
}
}

View file

@ -23,7 +23,7 @@ func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int
broadcast.BroadcastMessage(clients, models.BroadcastMessage{
Mode: mode,
Session: session,
MaxSession: PomodoroConfig.Sessions,
MaxSession: sessions,
TimeLeft: remainingSeconds,
})
time.Sleep(time.Second)
@ -36,7 +36,7 @@ func startTimer(clients map[*websocket.Conn]*models.Client, remainingSeconds int
broadcast.BroadcastMessage(clients, models.BroadcastMessage{
Mode: mode,
Session: session,
MaxSession: PomodoroConfig.Sessions,
MaxSession: sessions,
TimeLeft: 0,
})

View file

@ -1,13 +0,0 @@
package models
type GoTomatoTimerConfig struct {
Work int `json:"work"`
ShortBreak int `json:"shortBreak"`
LongBreak int `json:"longBreak"`
Sessions int `json:"sessions"`
}
type GoTomatoServerConfig struct {
ListenAddress string `json:"listenAddress, default:"0.0.0.0"`
ListenPort int `json:"listenPort, default:8080"`
}