Implemented version update info

pull/24/head v0.0.7
マリウス 2 years ago
parent 0b26f216e2
commit bc70b2fb6d
No known key found for this signature in database
GPG Key ID: 272ED814BF63261F

@ -3,6 +3,8 @@ package main
import (
"context"
"embed"
"encoding/json"
"net/http"
"net/url"
"os"
"runtime"
@ -63,7 +65,7 @@ func main() {
var articlesRoots []*models.Article
TUI := tui.Init(&EMBEDFS, cfg, logger)
TUI.SetVersion(version)
TUI.SetVersion(version, getLatestVersion())
TUI.ArticlesDatasource = &articles
TUI.ArticlesRoots = &articlesRoots
@ -114,3 +116,22 @@ func main() {
TUI.Launch()
}
func getLatestVersion() (string) {
var client = &http.Client{Timeout: 10 * time.Second}
r, err := client.Get(
"https://api.github.com/repos/mrusme/superhighway84/releases/latest",
)
if err != nil {
return version
}
defer r.Body.Close()
var result map[string]interface{}
json.NewDecoder(r.Body).Decode(&result)
if val, exist := result["tag_name"]; exist == true {
return val.(string)
}
return version
}

@ -16,7 +16,7 @@ var HEADER_LOGO =
[teal] / / / // [-][hotpink]/ __/_ _____ ___ ____/ / (_)__ _/ / _ _____ ___ __( _ )/ / /[-]
[teal] _\ _\_\_\\_[-][fuchsia]\ \/ // / _ \/ -_) __/ _ \/ / _ \/ _ \ |/|/ / _ \/ // / _ /_ _/[-]
[darkcyan] / / / // [-][hotpink]/___/\_,_/ .__/\__/_/ /_//_/_/\_, /_//_/__,__/\_,_/\_, /\___/ /_/[-] [dimgray]%s[-]
[hotpink] /_/ /___/ /___/[-]
[hotpink] /_/ /___/ /___/[-] [yellow]%s[-]
`
var STATS_TEMPLATE =
@ -171,10 +171,22 @@ func (mainscreen *Mainscreen) SetInfo(info map[string]string) {
)
}
func (mainscreen *Mainscreen) SetVersion(version string) {
func (mainscreen *Mainscreen) SetVersion(version string, versionLatest string) {
v := version
if version == "v0.0.0" {
v = "DeLorean @ 1.21 Gigawatts"
}
l := ""
if versionLatest != version &&
version != "v0.0.0" {
l = fmt.Sprintf("%s update available!", versionLatest)
}
mainscreen.Header.SetText(
fmt.Sprintf(HEADER_LOGO,
version,
v,
l,
),
)
}

@ -34,6 +34,7 @@ type TUI struct {
Stats map[string]int64
Version string
VersionLatest string
}
type View interface {
@ -239,8 +240,9 @@ func (t* TUI) SetStats(peers, rateIn, rateOut, totalIn, totalOut int64) () {
t.App.Draw()
}
func (t* TUI) SetVersion(version string) {
func (t* TUI) SetVersion(version string, versionLatest string) {
t.Version = version
t.Views["mainscreen"].(*Mainscreen).SetVersion(t.Version)
t.VersionLatest = versionLatest
t.Views["mainscreen"].(*Mainscreen).SetVersion(t.Version, t.VersionLatest)
}

Loading…
Cancel
Save