From d78e90822af16df50bb162f5f0cb002f5ad86871 Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 25 Nov 2022 22:52:32 +0100 Subject: [PATCH] Fix version updates not shown in UI (#5230) --- cmd/root.go | 8 ++++---- server/http_handler.go | 4 +++- server/updater/github.go | 10 +++++++--- server/updater/run.go | 4 ++-- server/updater/run_gokrazy.go | 4 ++-- server/version.go | 6 ------ 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 10b3f6d29..c825d6add 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -146,6 +146,9 @@ func runRoot(cmd *cobra.Command, args []string) { valueChan := make(chan util.Param) go tee.Run(valueChan) + // capture log messages for UI + util.CaptureLogs(valueChan) + // setup environment if err == nil { err = configureEnvironment(cmd, conf) @@ -241,10 +244,7 @@ func runRoot(cmd *cobra.Command, args []string) { // show and check version valueChan <- util.Param{Key: "version", Val: server.FormattedVersion()} - go updater.Run(log, httpd, tee, valueChan) - - // capture log messages for UI - util.CaptureLogs(valueChan) + go updater.Run(log, httpd, valueChan) // expose sponsor to UI if sponsor.Subject != "" { diff --git a/server/http_handler.go b/server/http_handler.go index c5aaf8398..85bd5b82b 100644 --- a/server/http_handler.go +++ b/server/http_handler.go @@ -22,6 +22,8 @@ import ( "golang.org/x/text/language" ) +var ignoreState = []string{"releaseNotes"} // excessive size + func indexHandler() http.HandlerFunc { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=UTF-8") @@ -173,7 +175,7 @@ func boolGetHandler(get func() bool) http.HandlerFunc { func stateHandler(cache *util.Cache) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { res := cache.State() - for _, k := range []string{"availableVersion", "releaseNotes"} { + for _, k := range ignoreState { delete(res, k) } jsonResult(w, res) diff --git a/server/updater/github.go b/server/updater/github.go index fe60330ca..26f0ae861 100644 --- a/server/updater/github.go +++ b/server/updater/github.go @@ -9,12 +9,16 @@ import ( "strings" "time" - "github.com/evcc-io/evcc/server" "github.com/google/go-github/v32/github" "github.com/hashicorp/go-version" ) -const timeout = 30 * time.Second +const ( + owner = "evcc-io" + repository = "evcc" + + timeout = 30 * time.Second +) // Repo is a github repository adapter type Repo struct { @@ -73,7 +77,7 @@ func (r *Repo) ReleaseNotes(from string) (rendered string, err error) { var md string if md, _, err = r.Markdown(context.Background(), notes, &github.MarkdownOptions{ Mode: "gfm", - Context: fmt.Sprintf("%s/%s", server.Owner, server.Repository), + Context: fmt.Sprintf("%s/%s", r.owner, r.repository), }); err != nil { return } diff --git a/server/updater/run.go b/server/updater/run.go index df4ea71fb..2efd01a83 100644 --- a/server/updater/run.go +++ b/server/updater/run.go @@ -9,11 +9,11 @@ import ( ) // Run regularly checks version -func Run(log *util.Logger, httpd webServer, tee util.TeeAttacher, outChan chan<- util.Param) { +func Run(log *util.Logger, httpd webServer, outChan chan<- util.Param) { u := &watch{ log: log, outChan: outChan, - repo: NewRepo(server.Owner, server.Repository), + repo: NewRepo(owner, repository), } c := make(chan *github.RepositoryRelease, 1) diff --git a/server/updater/run_gokrazy.go b/server/updater/run_gokrazy.go index e3bb2acb5..90c7ea74e 100644 --- a/server/updater/run_gokrazy.go +++ b/server/updater/run_gokrazy.go @@ -14,11 +14,11 @@ import ( var latest *github.RepositoryRelease // Run regularly checks version -func Run(log *util.Logger, httpd webServer, tee util.TeeAttacher, outChan chan<- util.Param) { +func Run(log *util.Logger, httpd webServer, outChan chan<- util.Param) { u := &watch{ log: log, outChan: outChan, - repo: NewRepo(server.Owner, server.Repository), + repo: NewRepo(owner, repository), } httpd.Router().PathPrefix("/api/update").HandlerFunc(u.updateHandler) diff --git a/server/version.go b/server/version.go index c0892658f..6d97b1ffc 100644 --- a/server/version.go +++ b/server/version.go @@ -3,12 +3,6 @@ package server import "fmt" var ( - // Repository name - Repository = "evcc" - - // Owner of repository - Owner = "andig" - // Version of executable Version = "0.0.1-alpha"