Compare commits
5 commits
5750ec96cb
...
f0ba6396b7
Author | SHA1 | Date | |
---|---|---|---|
f0ba6396b7 | |||
f5f51711a1 | |||
7b0c0df477 | |||
1b01041a14 | |||
1a47c0607b |
9 changed files with 45 additions and 34 deletions
|
@ -3,28 +3,30 @@ package server
|
|||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/charmbracelet/log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/metadata"
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/websocket"
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
"github.com/charmbracelet/log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
// 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() {
|
||||
// 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()
|
||||
|
||||
shared.Message.ProtocolVersion = strings.Split(metadata.GoTomatoVersion, ".")[0]
|
||||
if *showVersionFlag {
|
||||
fmt.Printf("App-Version: %s\n", metadata.GoTomatoVersion)
|
||||
fmt.Printf("Protocol-Version: %s\n", shared.Message.ProtocolVersion)
|
||||
fmt.Println("App-Version:", metadata.GoTomatoVersion)
|
||||
fmt.Println("Protocol-Version:", metadata.ProtocolVersion)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
package metadata
|
||||
|
||||
import "strings"
|
||||
|
||||
const GoTomatoVersion = "v0.0.3" // The GoTomato Version
|
||||
var ProtocolVersion = strings.Split(GoTomatoVersion, ".")[0]
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package pomodoro
|
||||
|
||||
import (
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
|
||||
"sync"
|
||||
"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
|
||||
|
@ -99,3 +101,10 @@ func IsPomodoroPaused() bool {
|
|||
defer mu.Unlock() // Ensures that the mutex is unlocked after the function is done
|
||||
return shared.Message.Paused
|
||||
}
|
||||
|
||||
func UpdateSettings(settings models.PomodoroConfig) {
|
||||
if settings != (models.PomodoroConfig{}) {
|
||||
shared.Message.Settings = settings
|
||||
shared.Message.TimeLeft = settings.Work
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package pomodoro
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
import "time"
|
||||
|
||||
type Timer struct {
|
||||
TimeLeft chan int // time left
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package shared
|
||||
|
||||
import (
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
)
|
||||
import "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
|
||||
var DefaultServerConfig = models.ServerConfig{
|
||||
ListenAddress: "0.0.0.0",
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package shared
|
||||
|
||||
import (
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/metadata"
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
)
|
||||
|
||||
|
@ -11,6 +12,7 @@ var Message = models.ServerMessage{
|
|||
TimeLeft: DefaultPomodoroConfig.Work,
|
||||
Ongoing: false,
|
||||
Paused: false,
|
||||
ProtocolVersion: metadata.ProtocolVersion,
|
||||
}
|
||||
|
||||
var PomodoroPassword string
|
||||
|
|
|
@ -2,10 +2,11 @@ package websocket
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/gorilla/websocket"
|
||||
"time"
|
||||
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
|
||||
)
|
||||
|
||||
// sends continous messages to all connected WebSocket clients.
|
||||
|
|
|
@ -2,11 +2,12 @@ package websocket
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/gorilla/websocket"
|
||||
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/pomodoro"
|
||||
"git.smsvc.net/pomodoro/GoTomato/internal/shared"
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
// handleClientCommands listens for commands from WebSocket clients
|
||||
|
@ -49,11 +50,7 @@ func handleClientCommands(ws *websocket.Conn) {
|
|||
}
|
||||
case "updateSettings":
|
||||
if !pomodoro.IsPomodoroOngoing() {
|
||||
if clientCommand.Settings != (models.PomodoroConfig{}) {
|
||||
shared.Message.Settings = clientCommand.Settings
|
||||
shared.Message.TimeLeft = clientCommand.Settings.Work
|
||||
}
|
||||
|
||||
pomodoro.UpdateSettings(clientCommand.Settings)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
package websocket
|
||||
|
||||
import (
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/gorilla/websocket"
|
||||
"net/http"
|
||||
"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
|
||||
|
|
Loading…
Reference in a new issue