From 61b2f71bf353812b0d8e0d2bcd1a999fb1022842 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sat, 26 Oct 2024 09:15:49 +0200 Subject: [PATCH 1/5] break: rename `ServerMessage.PomodoroSettings` -> `.Settings` --- internal/pomodoro/pomodoro.go | 4 ++-- internal/shared/state.go | 12 ++++++------ internal/websocket/client_commands.go | 2 +- pkg/models/server.go | 14 +++++++------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/internal/pomodoro/pomodoro.go b/internal/pomodoro/pomodoro.go index 5f0af99..be39e6e 100644 --- a/internal/pomodoro/pomodoro.go +++ b/internal/pomodoro/pomodoro.go @@ -29,7 +29,7 @@ func RunPomodoro() { shared.Message.Paused = false mu.Unlock() - pomodoroConfig := shared.Message.PomodoroSettings + pomodoroConfig := shared.Message.Settings for session := 1; session <= pomodoroConfig.Sessions; session++ { timer = timer.Init() @@ -66,7 +66,7 @@ func RunPomodoro() { shared.Message.Mode = "Idle" shared.Message.Session = 0 - shared.Message.TimeLeft = shared.Message.PomodoroSettings.Work + shared.Message.TimeLeft = shared.Message.Settings.Work } func ResetPomodoro() { diff --git a/internal/shared/state.go b/internal/shared/state.go index 04c6949..1f8c670 100644 --- a/internal/shared/state.go +++ b/internal/shared/state.go @@ -5,12 +5,12 @@ import ( ) var Message = models.ServerMessage{ - Mode: "Idle", - PomodoroSettings: DefaultPomodoroConfig, - Session: 0, - TimeLeft: DefaultPomodoroConfig.Work, - Ongoing: false, - Paused: false, + Mode: "Idle", + Settings: DefaultPomodoroConfig, + Session: 0, + TimeLeft: DefaultPomodoroConfig.Work, + Ongoing: false, + Paused: false, } var PomodoroPassword string diff --git a/internal/websocket/client_commands.go b/internal/websocket/client_commands.go index 4a0cbd1..88535e4 100644 --- a/internal/websocket/client_commands.go +++ b/internal/websocket/client_commands.go @@ -50,7 +50,7 @@ func handleClientCommands(ws *websocket.Conn) { case "updateSettings": if !pomodoro.IsPomodoroOngoing() { if clientCommand.PomodoroSettings != (models.GoTomatoPomodoroConfig{}) { - shared.Message.PomodoroSettings = clientCommand.PomodoroSettings + shared.Message.Settings = clientCommand.PomodoroSettings shared.Message.TimeLeft = clientCommand.PomodoroSettings.Work } diff --git a/pkg/models/server.go b/pkg/models/server.go index c95d5f2..674eeba 100644 --- a/pkg/models/server.go +++ b/pkg/models/server.go @@ -2,11 +2,11 @@ package models // ServerMessage represents the data sent to the client via WebSocket. type ServerMessage struct { - Mode string `json:"mode"` // "Idle", "Work", "ShortBreak", "LongBreak" or "End" - PomodoroSettings GoTomatoPomodoroConfig `json:"settings"` // The currrent pomodoro settings - Session int `json:"session"` // Current session number - TimeLeft int `json:"time_left"` // Remaining time in seconds - Ongoing bool `json:"ongoing"` // Ongoing pomodoro - Paused bool `json:"paused"` // Is timer paused - GoTomatoVersion string `json:"version"` // Version of the server + Mode string `json:"mode"` // "Idle", "Work", "ShortBreak", "LongBreak" or "End" + Settings GoTomatoPomodoroConfig `json:"settings"` // The currrent pomodoro settings + Session int `json:"session"` // Current session number + TimeLeft int `json:"time_left"` // Remaining time in seconds + Ongoing bool `json:"ongoing"` // Ongoing pomodoro + Paused bool `json:"paused"` // Is timer paused + GoTomatoVersion string `json:"version"` // Version of the server } From 16bc946a307b2a3ef46621dcefa579d3a9561ecb Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sat, 26 Oct 2024 09:16:48 +0200 Subject: [PATCH 2/5] break: rename `ClientCommand.PomodoroSettings` -> `.Settings` --- internal/websocket/client_commands.go | 6 +++--- pkg/models/client.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/websocket/client_commands.go b/internal/websocket/client_commands.go index 88535e4..d5c953b 100644 --- a/internal/websocket/client_commands.go +++ b/internal/websocket/client_commands.go @@ -49,9 +49,9 @@ func handleClientCommands(ws *websocket.Conn) { } case "updateSettings": if !pomodoro.IsPomodoroOngoing() { - if clientCommand.PomodoroSettings != (models.GoTomatoPomodoroConfig{}) { - shared.Message.Settings = clientCommand.PomodoroSettings - shared.Message.TimeLeft = clientCommand.PomodoroSettings.Work + if clientCommand.Settings != (models.GoTomatoPomodoroConfig{}) { + shared.Message.Settings = clientCommand.Settings + shared.Message.TimeLeft = clientCommand.Settings.Work } } diff --git a/pkg/models/client.go b/pkg/models/client.go index 6862cb1..34b6455 100644 --- a/pkg/models/client.go +++ b/pkg/models/client.go @@ -8,9 +8,9 @@ import ( // ClientCommand represents a command from the client (start/stop). type ClientCommand struct { - Command string `json:"command"` // comman send to the server - Password string `json:"password"` // pomodoro control password - PomodoroSettings GoTomatoPomodoroConfig `json:"settings"` // pomodoro config + Command string `json:"command"` // comman send to the server + Password string `json:"password"` // pomodoro control password + Settings GoTomatoPomodoroConfig `json:"settings"` // pomodoro config } type Client struct { From 0180aea8c1b1d6a258e12bb2dd58593c6bf7f02a Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sat, 26 Oct 2024 09:18:09 +0200 Subject: [PATCH 3/5] break: rename `ServerMessage.GoTomatoVersion` -> `.ProtocolVersion` --- cmd/server/main.go | 4 ++-- pkg/models/server.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 46dc46f..f78b256 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -21,10 +21,10 @@ func Start() { showVersionFlag := flag.Bool("version", false, "Output version") flag.Parse() - shared.Message.GoTomatoVersion = strings.Split(metadata.GoTomatoVersion, ".")[0] + 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.GoTomatoVersion) + fmt.Printf("Protocol-Version: %s\n", shared.Message.ProtocolVersion) os.Exit(0) } diff --git a/pkg/models/server.go b/pkg/models/server.go index 674eeba..a432499 100644 --- a/pkg/models/server.go +++ b/pkg/models/server.go @@ -8,5 +8,5 @@ type ServerMessage struct { TimeLeft int `json:"time_left"` // Remaining time in seconds Ongoing bool `json:"ongoing"` // Ongoing pomodoro Paused bool `json:"paused"` // Is timer paused - GoTomatoVersion string `json:"version"` // Version of the server + ProtocolVersion string `json:"version"` // Version of the server } From c20d36d2d2dd5cb9808978858d906f33be8d3c4f Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sat, 26 Oct 2024 09:20:29 +0200 Subject: [PATCH 4/5] break: rename `GoTomatoPomodoroConfig` -> `PomodoroConfig` --- internal/shared/configDefaults.go | 2 +- internal/websocket/client_commands.go | 2 +- pkg/models/client.go | 6 +++--- pkg/models/config.go | 2 +- pkg/models/server.go | 14 +++++++------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/internal/shared/configDefaults.go b/internal/shared/configDefaults.go index b4b82ff..f274555 100644 --- a/internal/shared/configDefaults.go +++ b/internal/shared/configDefaults.go @@ -9,7 +9,7 @@ var DefaultServerConfig = models.GoTomatoServerConfig{ ListenPort: 8080, } -var DefaultPomodoroConfig = models.GoTomatoPomodoroConfig{ +var DefaultPomodoroConfig = models.PomodoroConfig{ Work: 25 * 60, ShortBreak: 5 * 60, LongBreak: 15 * 60, diff --git a/internal/websocket/client_commands.go b/internal/websocket/client_commands.go index d5c953b..cafcd67 100644 --- a/internal/websocket/client_commands.go +++ b/internal/websocket/client_commands.go @@ -49,7 +49,7 @@ func handleClientCommands(ws *websocket.Conn) { } case "updateSettings": if !pomodoro.IsPomodoroOngoing() { - if clientCommand.Settings != (models.GoTomatoPomodoroConfig{}) { + if clientCommand.Settings != (models.PomodoroConfig{}) { shared.Message.Settings = clientCommand.Settings shared.Message.TimeLeft = clientCommand.Settings.Work } diff --git a/pkg/models/client.go b/pkg/models/client.go index 34b6455..8116d8b 100644 --- a/pkg/models/client.go +++ b/pkg/models/client.go @@ -8,9 +8,9 @@ import ( // ClientCommand represents a command from the client (start/stop). type ClientCommand struct { - Command string `json:"command"` // comman send to the server - Password string `json:"password"` // pomodoro control password - Settings GoTomatoPomodoroConfig `json:"settings"` // pomodoro config + Command string `json:"command"` // comman send to the server + Password string `json:"password"` // pomodoro control password + Settings PomodoroConfig `json:"settings"` // pomodoro config } type Client struct { diff --git a/pkg/models/config.go b/pkg/models/config.go index af51d23..b9d66c7 100644 --- a/pkg/models/config.go +++ b/pkg/models/config.go @@ -1,6 +1,6 @@ package models -type GoTomatoPomodoroConfig struct { +type PomodoroConfig struct { Work int `json:"work"` // Length of work sessions in seconds ShortBreak int `json:"shortBreak"` // Length of short break in seconds LongBreak int `json:"longBreak"` // Length if ling break in seconds diff --git a/pkg/models/server.go b/pkg/models/server.go index a432499..092c557 100644 --- a/pkg/models/server.go +++ b/pkg/models/server.go @@ -2,11 +2,11 @@ package models // ServerMessage represents the data sent to the client via WebSocket. type ServerMessage struct { - Mode string `json:"mode"` // "Idle", "Work", "ShortBreak", "LongBreak" or "End" - Settings GoTomatoPomodoroConfig `json:"settings"` // The currrent pomodoro settings - Session int `json:"session"` // Current session number - TimeLeft int `json:"time_left"` // Remaining time in seconds - Ongoing bool `json:"ongoing"` // Ongoing pomodoro - Paused bool `json:"paused"` // Is timer paused - ProtocolVersion string `json:"version"` // Version of the server + Mode string `json:"mode"` // "Idle", "Work", "ShortBreak", "LongBreak" or "End" + Settings PomodoroConfig `json:"settings"` // The currrent pomodoro settings + Session int `json:"session"` // Current session number + TimeLeft int `json:"time_left"` // Remaining time in seconds + Ongoing bool `json:"ongoing"` // Ongoing pomodoro + Paused bool `json:"paused"` // Is timer paused + ProtocolVersion string `json:"version"` // Version of the server } From ffc994126b1349930a20941357b3f97d2c0cfc2f Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sat, 26 Oct 2024 09:22:21 +0200 Subject: [PATCH 5/5] break: rename `GoTomatoServerConfig` -> `ServerConfig` --- cmd/server/main.go | 2 +- internal/shared/configDefaults.go | 2 +- pkg/models/config.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index f78b256..5d0b3a0 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -28,7 +28,7 @@ func Start() { os.Exit(0) } - serverConfig := models.GoTomatoServerConfig{ + serverConfig := models.ServerConfig{ ListenAddress: *listenAddress, ListenPort: *listenPort, } diff --git a/internal/shared/configDefaults.go b/internal/shared/configDefaults.go index f274555..a3840e0 100644 --- a/internal/shared/configDefaults.go +++ b/internal/shared/configDefaults.go @@ -4,7 +4,7 @@ import ( "git.smsvc.net/pomodoro/GoTomato/pkg/models" ) -var DefaultServerConfig = models.GoTomatoServerConfig{ +var DefaultServerConfig = models.ServerConfig{ ListenAddress: "0.0.0.0", ListenPort: 8080, } diff --git a/pkg/models/config.go b/pkg/models/config.go index b9d66c7..50c7923 100644 --- a/pkg/models/config.go +++ b/pkg/models/config.go @@ -7,7 +7,7 @@ type PomodoroConfig struct { Sessions int `json:"sessions"` // Number of total sessions } -type GoTomatoServerConfig struct { +type ServerConfig struct { ListenAddress string `json:"listenAddress"` // Server listen address ListenPort int `json:"listenPort"` // Server listen port }