Compare commits

...

6 commits

Author SHA1 Message Date
5750ec96cb refactor: update version output
- use `Println` for better readability
2024-10-29 11:05:45 +01:00
d69a4bec10 format: use group style variable declaration to define cli flags 2024-10-29 11:05:45 +01:00
e2ab19066d format: update import statements order for consistency 2024-10-29 11:05:45 +01:00
3a6be4c187 feat: update settings handling for pomodoro configuration
- add `UpdateSettings()` to update pomodoro configuration
- refactor client command handling to use `UpdateSettings()`

🤖
2024-10-29 11:05:45 +01:00
f0d7dc80fc feat: update protocol version handling
- add ProtocolVersion variable to metadata package
- don't set `ServerMessage.ProtocolVersion` in `main`
- update `ServerMessage` default to include ProtocolVersion

🤖
2024-10-29 11:05:44 +01:00
f8ab1375d1 chore: bump version to v0.0.4 2024-10-29 11:05:30 +01:00
9 changed files with 46 additions and 35 deletions

View file

@ -3,28 +3,30 @@ package server
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/charmbracelet/log"
"net/http"
"os"
"git.smsvc.net/pomodoro/GoTomato/internal/metadata" "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"
"github.com/charmbracelet/log" )
"net/http"
"os" var (
"strings" // Define CLI flags
listenAddress = flag.String("listenAddress", shared.DefaultServerConfig.ListenAddress, "IP address to listen on")
listenPort = flag.Int("listenPort", shared.DefaultServerConfig.ListenPort, "Port to listen on")
password = flag.String("password", "", "Control password for pomodoro session (optional)")
showVersionFlag = flag.Bool("version", false, "Output version")
) )
func Start() { func Start() {
// Define CLI flags for ListenAddress and ListenPort
listenAddress := flag.String("listenAddress", shared.DefaultServerConfig.ListenAddress, "IP address to listen on")
listenPort := flag.Int("listenPort", shared.DefaultServerConfig.ListenPort, "Port to listen on")
password := flag.String("password", "", "Control password for pomodoro session (optional)")
showVersionFlag := flag.Bool("version", false, "Output version")
flag.Parse() flag.Parse()
shared.Message.ProtocolVersion = strings.Split(metadata.GoTomatoVersion, ".")[0]
if *showVersionFlag { if *showVersionFlag {
fmt.Printf("App-Version: %s\n", metadata.GoTomatoVersion) fmt.Println("App-Version:", metadata.GoTomatoVersion)
fmt.Printf("Protocol-Version: %s\n", shared.Message.ProtocolVersion) fmt.Println("Protocol-Version:", metadata.ProtocolVersion)
os.Exit(0) os.Exit(0)
} }

View file

@ -1,3 +1,6 @@
package metadata package metadata
const GoTomatoVersion = "v0.0.3" // The GoTomato Version import "strings"
const GoTomatoVersion = "v0.0.4" // The GoTomato Version
var ProtocolVersion = strings.Split(GoTomatoVersion, ".")[0]

View file

@ -1,9 +1,11 @@
package pomodoro package pomodoro
import ( import (
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
"sync" "sync"
"time" "time"
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
) )
var mu sync.Mutex // to synchronize access to shared state var mu sync.Mutex // to synchronize access to shared state
@ -99,3 +101,10 @@ func IsPomodoroPaused() bool {
defer mu.Unlock() // Ensures that the mutex is unlocked after the function is done defer mu.Unlock() // Ensures that the mutex is unlocked after the function is done
return shared.Message.Paused return shared.Message.Paused
} }
func UpdateSettings(settings models.PomodoroConfig) {
if settings != (models.PomodoroConfig{}) {
shared.Message.Settings = settings
shared.Message.TimeLeft = settings.Work
}
}

View file

@ -1,8 +1,6 @@
package pomodoro package pomodoro
import ( import "time"
"time"
)
type Timer struct { type Timer struct {
TimeLeft chan int // time left TimeLeft chan int // time left

View file

@ -1,8 +1,6 @@
package shared package shared
import ( import "git.smsvc.net/pomodoro/GoTomato/pkg/models"
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
)
var DefaultServerConfig = models.ServerConfig{ var DefaultServerConfig = models.ServerConfig{
ListenAddress: "0.0.0.0", ListenAddress: "0.0.0.0",

View file

@ -1,6 +1,7 @@
package shared package shared
import ( import (
"git.smsvc.net/pomodoro/GoTomato/internal/metadata"
"git.smsvc.net/pomodoro/GoTomato/pkg/models" "git.smsvc.net/pomodoro/GoTomato/pkg/models"
) )
@ -11,6 +12,7 @@ var Message = models.ServerMessage{
TimeLeft: DefaultPomodoroConfig.Work, TimeLeft: DefaultPomodoroConfig.Work,
Ongoing: false, Ongoing: false,
Paused: false, Paused: false,
ProtocolVersion: metadata.ProtocolVersion,
} }
var PomodoroPassword string var PomodoroPassword string

View file

@ -2,10 +2,11 @@ package websocket
import ( import (
"encoding/json" "encoding/json"
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
"github.com/charmbracelet/log" "github.com/charmbracelet/log"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"time" "time"
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
) )
// sends continous messages to all connected WebSocket clients. // sends continous messages to all connected WebSocket clients.

View file

@ -2,11 +2,12 @@ package websocket
import ( import (
"encoding/json" "encoding/json"
"github.com/charmbracelet/log"
"github.com/gorilla/websocket"
"git.smsvc.net/pomodoro/GoTomato/internal/pomodoro" "git.smsvc.net/pomodoro/GoTomato/internal/pomodoro"
"git.smsvc.net/pomodoro/GoTomato/internal/shared" "git.smsvc.net/pomodoro/GoTomato/internal/shared"
"git.smsvc.net/pomodoro/GoTomato/pkg/models" "git.smsvc.net/pomodoro/GoTomato/pkg/models"
"github.com/charmbracelet/log"
"github.com/gorilla/websocket"
) )
// handleClientCommands listens for commands from WebSocket clients // handleClientCommands listens for commands from WebSocket clients
@ -49,11 +50,7 @@ func handleClientCommands(ws *websocket.Conn) {
} }
case "updateSettings": case "updateSettings":
if !pomodoro.IsPomodoroOngoing() { if !pomodoro.IsPomodoroOngoing() {
if clientCommand.Settings != (models.PomodoroConfig{}) { pomodoro.UpdateSettings(clientCommand.Settings)
shared.Message.Settings = clientCommand.Settings
shared.Message.TimeLeft = clientCommand.Settings.Work
}
} }
} }
} }

View file

@ -1,11 +1,12 @@
package websocket package websocket
import ( import (
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
"github.com/charmbracelet/log" "github.com/charmbracelet/log"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
"net/http" "net/http"
"sync" "sync"
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
) )
// Clients is a map of connected WebSocket clients, where each client is represented by the Client struct // Clients is a map of connected WebSocket clients, where each client is represented by the Client struct