Compare commits
4 commits
a6b3444068
...
715fe60e1d
Author | SHA1 | Date | |
---|---|---|---|
715fe60e1d | |||
188f9ce928 | |||
63213c9d64 | |||
232fe409cb |
7 changed files with 32 additions and 11 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
GoTomato
|
18
README.md
18
README.md
|
@ -63,14 +63,15 @@ 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} |
|
| Welcome Message | {"mode":"Idle", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":0, "time_left":1500, "ongoing":false, "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":"Work", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":1, "time_left":900, "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 Running | {"mode":"ShortBreak", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":2, "time_left":50, "ongoing":true, "paused":false, "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 Paused | {"mode":"Work", "settings":{"work":1500, "shortBreak":300, "longBreak":900, "sessions":4}, "session":2, "time_left":456, "ongoing":true, "paused":true, "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} |
|
| 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"} |
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|
||||||
|
@ -80,3 +81,10 @@ go run .
|
||||||
```
|
```
|
||||||
|
|
||||||
open http://localhost:8081
|
open http://localhost:8081
|
||||||
|
|
||||||
|
## Building
|
||||||
|
|
||||||
|
```
|
||||||
|
go build -ldflags "-w"
|
||||||
|
upx --best --lzma GoTomato
|
||||||
|
```
|
||||||
|
|
|
@ -3,11 +3,14 @@ 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() {
|
||||||
|
@ -15,8 +18,16 @@ 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,
|
||||||
|
|
3
internal/metadata/version.go
Normal file
3
internal/metadata/version.go
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
package metadata
|
||||||
|
|
||||||
|
const GoTomatoVersion = "v0.0.1" // The GoTomato Version
|
|
@ -15,6 +15,3 @@ var DefaultPomodoroConfig = models.GoTomatoPomodoroConfig{
|
||||||
LongBreak: 15 * 60,
|
LongBreak: 15 * 60,
|
||||||
Sessions: 4,
|
Sessions: 4,
|
||||||
}
|
}
|
||||||
|
|
||||||
// used to check if client passed a config json
|
|
||||||
var UnsetPomodoroConfig models.GoTomatoPomodoroConfig
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ func handleClientCommands(ws *websocket.Conn) {
|
||||||
}
|
}
|
||||||
case "updateSettings":
|
case "updateSettings":
|
||||||
if !pomodoro.IsPomodoroOngoing() {
|
if !pomodoro.IsPomodoroOngoing() {
|
||||||
if clientCommand.PomodoroSettings != shared.UnsetPomodoroConfig {
|
if clientCommand.PomodoroSettings != (models.GoTomatoPomodoroConfig{}) {
|
||||||
shared.Message.PomodoroSettings = clientCommand.PomodoroSettings
|
shared.Message.PomodoroSettings = clientCommand.PomodoroSettings
|
||||||
shared.Message.TimeLeft = clientCommand.PomodoroSettings.Work
|
shared.Message.TimeLeft = clientCommand.PomodoroSettings.Work
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,4 +8,5 @@ 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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue