Compare commits

..

No commits in common. "2aa8163189f1ac7c3162fbbd38058871283e5a6e" and "cb6616f400db3d0c294a25da16c89a8ac030ac3d" have entirely different histories.

6 changed files with 22 additions and 42 deletions

View file

@ -53,7 +53,6 @@ All fields are mandatory and may not be ommitted.
The server periodically (every second) sends JSON-encoded messages to all connected clients to update them on the current state of the Pomodoro session. These messages contain the following fields: The server periodically (every second) sends JSON-encoded messages to all connected clients to update them on the current state of the Pomodoro session. These messages contain the following fields:
- mode: Indicates the current phase of the Pomodoro session ("Work", "ShortBreak", "LongBreak", "End" or "Idle"). - mode: Indicates the current phase of the Pomodoro session ("Work", "ShortBreak", "LongBreak", "End" or "Idle").
- "End" is send only once, after all sessions are finished
- settings: Contains the current Pomodoro settings: - settings: Contains the current Pomodoro settings:
- work: Length of the work session in seconds (e.g., 1500 for 25 minutes). - work: Length of the work session in seconds (e.g., 1500 for 25 minutes).
- shortBreak: Length of the short break in seconds (e.g., 300 for 5 minutes). - shortBreak: Length of the short break in seconds (e.g., 300 for 5 minutes).
@ -63,15 +62,14 @@ The server periodically (every second) sends JSON-encoded messages to all connec
- time_left: The remaining time for the current mode, in seconds (e.g., 900 for 15 minutes). - time_left: The remaining time for the current mode, in seconds (e.g., 900 for 15 minutes).
- ongoing: Whether a Pomodoro session is currently ongoing. - ongoing: Whether a Pomodoro session is currently ongoing.
- paused: Whether the timer is paused. - paused: Whether the timer is paused.
* version: The protocol version of the send message (this is always the same as the major app version)
| Message Type | Example | | Message Type | Example |
| --- | --- | | --- | --- |
| Welcome Message | {"mode":"Idle", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":0, "time_left":1500, "ongoing":false, "paused":false, "version":"v0"} | | Welcome Message | {"mode":"Idle", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":0, "time_left":1500, "ongoing":false, "paused":false} |
| Session Running | {"mode":"Work", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":1, "time_left":900, "ongoing":true, "paused":false, "version":"v0"} | | Session Running | {"mode":"Work", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":1, "time_left":900, "ongoing":true, "paused":false} |
| Session Running | {"mode":"ShortBreak", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":2, "time_left":50, "ongoing":true, "paused":false, "version":"v0"} | | Session Running | {"mode":"ShortBreak", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":2, "time_left":50, "ongoing":true, "paused":false} |
| Session Paused | {"mode":"Work", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":2, "time_left":456, "ongoing":true, "paused":true, "version":"v0"} | | Session Paused | {"mode":"Work", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":2, "time_left":456, "ongoing":true, "paused":true} |
| Session End/Reset | {"mode":"End", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":0, "time_left":0, "ongoing":false, "paused":false, "version":"v0"} | | Session End/Reset | {"mode":"End", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":0, "time_left":0, "ongoing":false, "paused":false} |
## Testing ## Testing

View file

@ -3,14 +3,11 @@ package server
import ( import (
"flag" "flag"
"fmt" "fmt"
"git.smsvc.net/pomodoro/GoTomato/internal/metadata"
"git.smsvc.net/pomodoro/GoTomato/internal/shared" "git.smsvc.net/pomodoro/GoTomato/internal/shared"
"git.smsvc.net/pomodoro/GoTomato/internal/websocket" "git.smsvc.net/pomodoro/GoTomato/internal/websocket"
"git.smsvc.net/pomodoro/GoTomato/pkg/models" "git.smsvc.net/pomodoro/GoTomato/pkg/models"
"log" "log"
"net/http" "net/http"
"os"
"strings"
) )
func Start() { func Start() {
@ -18,16 +15,8 @@ func Start() {
listenAddress := flag.String("listenAddress", shared.DefaultServerConfig.ListenAddress, "IP address to listen on") listenAddress := flag.String("listenAddress", shared.DefaultServerConfig.ListenAddress, "IP address to listen on")
listenPort := flag.Int("listenPort", shared.DefaultServerConfig.ListenPort, "Port to listen on") listenPort := flag.Int("listenPort", shared.DefaultServerConfig.ListenPort, "Port to listen on")
password := flag.String("password", "", "Control password for pomodoro session (optional)") password := flag.String("password", "", "Control password for pomodoro session (optional)")
showVersionFlag := flag.Bool("version", false, "Output version")
flag.Parse() flag.Parse()
shared.Message.GoTomatoVersion = strings.Split(metadata.GoTomatoVersion, ".")[0]
if *showVersionFlag {
fmt.Printf("App-Version: %s\n", metadata.GoTomatoVersion)
fmt.Printf("Protocol-Version: %s\n", shared.Message.GoTomatoVersion)
os.Exit(0)
}
serverConfig := models.GoTomatoServerConfig{ serverConfig := models.GoTomatoServerConfig{
ListenAddress: *listenAddress, ListenAddress: *listenAddress,
ListenPort: *listenPort, ListenPort: *listenPort,

View file

@ -1,3 +0,0 @@
package metadata
const GoTomatoVersion = "v0.0.1" // The GoTomato Version

View file

@ -2,8 +2,8 @@ package pomodoro
import ( import (
"git.smsvc.net/pomodoro/GoTomato/internal/shared" "git.smsvc.net/pomodoro/GoTomato/internal/shared"
// "git.smsvc.net/pomodoro/GoTomato/pkg/models"
"sync" "sync"
"time"
) )
var pomodoroResetChannel = make(chan bool, 1) var pomodoroResetChannel = make(chan bool, 1)
@ -41,24 +41,17 @@ func RunPomodoro() {
shared.Message.Mode = "End" shared.Message.Mode = "End"
} }
time.Sleep(time.Second)
mu.Lock() mu.Lock()
shared.Message.Ongoing = false shared.Message.Ongoing = false
shared.Message.Paused = false shared.Message.Paused = false
mu.Unlock() mu.Unlock()
shared.Message.Mode = "Idle"
shared.Message.Session = 0
shared.Message.TimeLeft = shared.Message.PomodoroSettings.Work
} }
// Stops and resets the running Pomodoro // ResetPomodoro resets the running Pomodoro timer.
func ResetPomodoro() { func ResetPomodoro() {
shared.Message.Mode = "Idle" // Send a reset signal to stop any running timers
shared.Message.Session = 0
shared.Message.TimeLeft = shared.Message.PomodoroSettings.Work
pomodoroResetChannel <- true pomodoroResetChannel <- true
shared.Message = shared.ResetToDefault()
} }
func PausePomodoro() { func PausePomodoro() {

View file

@ -4,7 +4,10 @@ import (
"git.smsvc.net/pomodoro/GoTomato/pkg/models" "git.smsvc.net/pomodoro/GoTomato/pkg/models"
) )
var Message = models.ServerMessage{ var Message = ResetToDefault()
func ResetToDefault() models.ServerMessage {
return models.ServerMessage{
Mode: "Idle", Mode: "Idle",
PomodoroSettings: DefaultPomodoroConfig, PomodoroSettings: DefaultPomodoroConfig,
Session: 0, Session: 0,
@ -12,5 +15,6 @@ var Message = models.ServerMessage{
Ongoing: false, Ongoing: false,
Paused: false, Paused: false,
} }
}
var PomodoroPassword string var PomodoroPassword string

View file

@ -8,5 +8,4 @@ type ServerMessage struct {
TimeLeft int `json:"time_left"` // Remaining time in seconds TimeLeft int `json:"time_left"` // Remaining time in seconds
Ongoing bool `json:"ongoing"` // Ongoing pomodoro Ongoing bool `json:"ongoing"` // Ongoing pomodoro
Paused bool `json:"paused"` // Is timer paused Paused bool `json:"paused"` // Is timer paused
GoTomatoVersion string `json:"version"` // Version of the server
} }