feat: refactor shared.Message to a channel
- remove `shared` package and shared.Message - rename `notifications` package to `frontend` - introduce a channel send the received ServerMessages to the frontend handler(s) - move keyhandler to goroutine - simplify password handling in Start function - update import names when importing from GoTomoto
This commit is contained in:
parent
cc24dd6775
commit
bbc9977f1c
10 changed files with 108 additions and 82 deletions
|
@ -3,15 +3,16 @@ package websocket
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.smsvc.net/pomodoro/ChronoTomato/internal/notifications"
|
||||
"git.smsvc.net/pomodoro/ChronoTomato/internal/shared"
|
||||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
var Done = make(chan struct{})
|
||||
|
||||
func ProcessServerMessages(conn *websocket.Conn) {
|
||||
func ProcessServerMessages(conn *websocket.Conn, channel chan<- GoTomato.ServerMessage) {
|
||||
|
||||
var serverMessage GoTomato.ServerMessage
|
||||
|
||||
defer close(Done)
|
||||
|
||||
|
@ -28,14 +29,14 @@ func ProcessServerMessages(conn *websocket.Conn) {
|
|||
return
|
||||
}
|
||||
|
||||
err = json.Unmarshal(message, &shared.ServerMessage)
|
||||
err = json.Unmarshal(message, &serverMessage)
|
||||
if err != nil {
|
||||
log.Error("Error unmarshalling!", "reason", err)
|
||||
continue
|
||||
}
|
||||
|
||||
notifications.DesktopNotifications()
|
||||
notifications.TerminalOutput()
|
||||
channel <- serverMessage
|
||||
channel <- serverMessage
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,12 +2,12 @@ package websocket
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
GoTomato "git.smsvc.net/pomodoro/GoTomato/pkg/models"
|
||||
"github.com/charmbracelet/log"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
func sendClientCommand(conn *websocket.Conn, msg models.ClientCommand) {
|
||||
func sendClientCommand(conn *websocket.Conn, msg GoTomato.ClientCommand) {
|
||||
messageBytes, err := json.Marshal(msg)
|
||||
|
||||
if err != nil {
|
||||
|
@ -23,7 +23,7 @@ func sendClientCommand(conn *websocket.Conn, msg models.ClientCommand) {
|
|||
}
|
||||
|
||||
func SendCmd(conn *websocket.Conn, pwd string, cmd string) {
|
||||
message := models.ClientCommand{
|
||||
message := GoTomato.ClientCommand{
|
||||
Command: cmd,
|
||||
Password: pwd,
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ func SendCmd(conn *websocket.Conn, pwd string, cmd string) {
|
|||
sendClientCommand(conn, message)
|
||||
}
|
||||
|
||||
func Send_updateSettings(conn *websocket.Conn, pwd string, settings models.GoTomatoPomodoroConfig) {
|
||||
message := models.ClientCommand{
|
||||
func Send_updateSettings(conn *websocket.Conn, pwd string, settings GoTomato.GoTomatoPomodoroConfig) {
|
||||
message := GoTomato.ClientCommand{
|
||||
Command: "updateSettings",
|
||||
Password: pwd,
|
||||
PomodoroSettings: settings,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue