Skip to content

Commit

Permalink
Display current version number in UI, and check for latest
Browse files Browse the repository at this point in the history
  • Loading branch information
cld9x committed Aug 5, 2019
1 parent 03ede9e commit d0c57ec
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 27 deletions.
28 changes: 28 additions & 0 deletions pkg/xbvr/api_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ import (
"github.com/emicklei/go-restful"
"github.com/emicklei/go-restful-openapi"
"github.com/pkg/errors"
"github.com/tidwall/gjson"
"gopkg.in/resty.v1"
)

type NewVolumeRequest struct {
Path string `json:"path"`
}

type VersionCheckResponse struct {
CurrentVersion string `json:"current_version"`
LatestVersion string `json:"latest_version"`
}

type ConfigResource struct{}

func (i ConfigResource) WebService() *restful.WebService {
Expand All @@ -25,6 +32,9 @@ func (i ConfigResource) WebService() *restful.WebService {
Consumes(restful.MIME_JSON).
Produces(restful.MIME_JSON)

ws.Route(ws.GET("/version-check").To(i.versionCheck).
Metadata(restfulspec.KeyOpenAPITags, tags))

ws.Route(ws.GET("/volume").To(i.listVolume).
Metadata(restfulspec.KeyOpenAPITags, tags))

Expand All @@ -37,6 +47,24 @@ func (i ConfigResource) WebService() *restful.WebService {
return ws
}

func (i ConfigResource) versionCheck(req *restful.Request, resp *restful.Response) {
out := VersionCheckResponse{LatestVersion: currentVersion, CurrentVersion: currentVersion}

if currentVersion != "CURRENT" {
r, err := resty.R().
SetHeader("User-Agent", "XBVR/"+currentVersion).
Get("https://updates.xbvr.app/latest.json")
if err != nil || r.StatusCode() != 200 {
resp.WriteHeaderAndEntity(http.StatusOK, out)
return
}

out.LatestVersion = gjson.Get(r.String(), "latestVersion").String()
}

resp.WriteHeaderAndEntity(http.StatusOK, out)
}

func (i ConfigResource) listVolume(req *restful.Request, resp *restful.Response) {
db, _ := GetDB()
defer db.Close()
Expand Down
9 changes: 6 additions & 3 deletions pkg/xbvr/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ import (
)

var (
DEBUG = os.Getenv("DEBUG")
httpAddr = "0.0.0.0:9999"
wsAddr = "0.0.0.0:9998"
DEBUG = os.Getenv("DEBUG")
httpAddr = "0.0.0.0:9999"
wsAddr = "0.0.0.0:9998"
currentVersion = ""
)

func StartServer(version, commit, branch, date string) {
currentVersion = version

// Remove old locks
RemoveLock("scrape")
RemoveLock("update-scenes")
Expand Down
85 changes: 61 additions & 24 deletions ui/src/Navbar.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,65 @@
<template>
<nav class="navbar is-fixed-top" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item">
<h1 class="title">XBVR</h1>
</a>
</div>

<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item">
<router-link to="./">Scenes</router-link>
</a>
<a class="navbar-item">
<router-link to="./files">Files</router-link>
</a>
<a class="navbar-item">
<router-link to="./options">Options</router-link>
</a>
</div>
</div>
</nav>
<b-navbar :fixed-top="true">
<template slot="brand">
<b-navbar-item>
<h1 class="title">XBVR <small>{{currentVersion}}</small></h1>
</b-navbar-item>
</template>
<template slot="start">
<b-navbar-item>
<router-link to="./">Scenes</router-link>
</b-navbar-item>
<b-navbar-item>
<router-link to="./files">Files</router-link>
</b-navbar-item>
<b-navbar-item>
<router-link to="./options">Options</router-link>
</b-navbar-item>
</template>
</b-navbar>
</template>

<script>
let d = document.documentElement;
d.className += " has-navbar-fixed-top";
</script>
import ky from "ky";
export default {
data() {
return {
currentVersion: "",
latestVersion: "",
}
},
mounted() {
ky.get(`/api/config/version-check`).json().then(data => {
this.currentVersion = data.current_version;
this.latestVersion = data.latest_version;
if (this.currentVersion !== this.latestVersion && this.currentVersion !== "CURRENT") {
this.$buefy.snackbar.open({
message: `Version ${this.latestVersion} available!`,
type: 'is-warning',
position: 'is-top',
actionText: 'Download now',
indefinite: true,
onAction: () => {
window.location = "https://github.com/cld9x/xbvr/releases";
}
})
}
});
}
}
</script>

<style scoped>
h1 {
display: flex;
align-items: center;
}
h1 small {
font-size: 0.5em;
margin-left: 0.5em;
opacity: 0.5;
}
</style>

0 comments on commit d0c57ec

Please sign in to comment.