Compare commits
No commits in common. "3995534ff4df5c19938a0d7006e74d8acc757404" and "1a47c0607b09c562f4cba9f11f8d4767cd9c5f18" have entirely different histories.
3995534ff4
...
1a47c0607b
7 changed files with 24 additions and 32 deletions
|
@ -3,25 +3,21 @@ 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"
|
||||
)
|
||||
|
||||
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")
|
||||
"github.com/charmbracelet/log"
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
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()
|
||||
|
||||
if *showVersionFlag {
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
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
|
||||
|
@ -101,10 +99,3 @@ 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,6 +1,8 @@
|
|||
package pomodoro
|
||||
|
||||
import "time"
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type Timer struct {
|
||||
TimeLeft chan int // time left
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
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",
|
||||
|
|
|
@ -2,11 +2,10 @@ 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,12 +2,11 @@ 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
|
||||
|
@ -50,7 +49,11 @@ func handleClientCommands(ws *websocket.Conn) {
|
|||
}
|
||||
case "updateSettings":
|
||||
if !pomodoro.IsPomodoroOngoing() {
|
||||
pomodoro.UpdateSettings(clientCommand.Settings)
|
||||
if clientCommand.Settings != (models.PomodoroConfig{}) {
|
||||
shared.Message.Settings = clientCommand.Settings
|
||||
shared.Message.TimeLeft = clientCommand.Settings.Work
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
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