diff --git a/pkg/xbvr/api_config.go b/pkg/xbvr/api_config.go
index 14f3761f9..0abcd6f20 100644
--- a/pkg/xbvr/api_config.go
+++ b/pkg/xbvr/api_config.go
@@ -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 {
@@ -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))
@@ -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()
diff --git a/pkg/xbvr/server.go b/pkg/xbvr/server.go
index 0e01f9e14..c17bfa9af 100644
--- a/pkg/xbvr/server.go
+++ b/pkg/xbvr/server.go
@@ -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")
diff --git a/ui/src/Navbar.vue b/ui/src/Navbar.vue
index fd15921da..3f8758a15 100644
--- a/ui/src/Navbar.vue
+++ b/ui/src/Navbar.vue
@@ -1,28 +1,65 @@
-
+
+
+
+ XBVR {{currentVersion}}
+
+
+
+
+ Scenes
+
+
+ Files
+
+
+ Options
+
+
+
\ No newline at end of file
+ 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";
+ }
+ })
+ }
+ });
+ }
+ }
+
+
+
\ No newline at end of file