diff --git a/cmd/client/api/api.go b/cmd/client/api/api.go index bcc39fe..9d2aa6e 100644 --- a/cmd/client/api/api.go +++ b/cmd/client/api/api.go @@ -99,7 +99,7 @@ type Session struct { token []byte } -func (session Session) List() (apps []user_handler.App, err error) { +func (session Session) List() (server user_handler.Server, err error) { defer func() { if err != nil { err = ErrNetworkMsg{ @@ -129,8 +129,7 @@ func (session Session) List() (apps []user_handler.App, err error) { err = fmt.Errorf("status: %d - %s", resp.StatusCode, string(b)) return } - apps = make([]user_handler.App, 0) - err = json.Unmarshal(b, &apps) + err = json.Unmarshal(b, &server) return } diff --git a/cmd/client/models/models.go b/cmd/client/models/models.go index ab35bf0..e9475ba 100644 --- a/cmd/client/models/models.go +++ b/cmd/client/models/models.go @@ -6,6 +6,7 @@ import ( "github.com/ross96D/updater/cmd/client/components/list" "github.com/ross96D/updater/server/user_handler" + "github.com/ross96D/updater/share" ) type Password string @@ -46,6 +47,7 @@ type Server struct { Url *url.URL `json:"url"` UserName string `json:"username"` Password Password `json:"password"` + Version share.VersionData `json:"version"` Apps []user_handler.App `json:"apps"` Status list.Status `json:"-"` } diff --git a/cmd/client/state/state.go b/cmd/client/state/state.go index 988e69a..9fde67c 100644 --- a/cmd/client/state/state.go +++ b/cmd/client/state/state.go @@ -110,7 +110,7 @@ func NewState(servers []models.Server) *GlobalState { type FetchResultMsg struct { ServerName string - Apps []user_handler.App + Server user_handler.Server } type ErrFetchFailMsg struct { @@ -140,11 +140,11 @@ func (gs *GlobalState) FetchCmd() tea.Cmd { if err != nil { return ErrFetchFailCmd(server.ServerName, err) } - apps, err := session.List() + s, err := session.List() if err != nil { return ErrFetchFailCmd(server.ServerName, err) } - return FetchResultMsg{ServerName: server.ServerName, Apps: apps} + return FetchResultMsg{ServerName: server.ServerName, Server: s} } } for _, server := range *gs.servers { diff --git a/cmd/client/views/app.go b/cmd/client/views/app.go index 8340f3e..a10184f 100644 --- a/cmd/client/views/app.go +++ b/cmd/client/views/app.go @@ -61,7 +61,8 @@ func (model *app) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return model, nil } server := model.state.Get(index) - server.Apps = msg.Apps + server.Apps = msg.Server.Apps + server.Version = msg.Server.Version server.Status = listcomp.Ready model.state.Set(index, server) return model, tea.Batch(state.GlobalStateSyncCmd, state.SaveCmd) diff --git a/cmd/client/views/home.go b/cmd/client/views/home.go index de2b12d..e7db8d4 100644 --- a/cmd/client/views/home.go +++ b/cmd/client/views/home.go @@ -153,7 +153,9 @@ func (hv *HomeView) init() { for i := 0; i < length; i++ { server := hv.State.GetRef(i) items = append(items, list.Item[*models.Server]{ - Message: server.ServerName + " " + (*url.URL)(server.Url).String(), + Message: server.Version.String() + " " + + server.ServerName + " " + + (*url.URL)(server.Url).String(), Value: server, StatusValue: server.Status, }) diff --git a/server/user_handler/handler.go b/server/user_handler/handler.go index a8c6a8d..6e00b48 100644 --- a/server/user_handler/handler.go +++ b/server/user_handler/handler.go @@ -137,6 +137,11 @@ func HandlerUserUpdate(ctx context.Context, payload []byte, dryRun bool) error { } +type Server struct { + Apps []App `json:"apps"` + Version share.VersionData `json:"version"` +} + type App struct { configuration.Application Index int `json:"index"` @@ -156,5 +161,6 @@ func HandleUserAppsList(w io.Writer) error { enc := json.NewEncoder(w) enc.SetIndent("", "\t") - return enc.Encode(apps) + + return enc.Encode(Server{Apps: apps, Version: share.Version()}) }