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
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue