Version check and upgrade prompt.
This commit is contained in:
parent
648b9ad886
commit
7b9620631e
@ -7,7 +7,8 @@ open my $fh, "<", "main.go" || die $!;
|
|||||||
|
|
||||||
my $version;
|
my $version;
|
||||||
while (<$fh>) {
|
while (<$fh>) {
|
||||||
$version = $1 if /^const\s+currentVersion.*?"(v[\d\.]+)"/;
|
# CurrentVersion: "v0.04"
|
||||||
|
$version = $1 if /CurrentVersion:\s*"(v[\d\.]+)"/;
|
||||||
}
|
}
|
||||||
close $fh;
|
close $fh;
|
||||||
|
|
||||||
|
5
go.mod
5
go.mod
@ -2,4 +2,7 @@ module github.com/tardisx/gropple
|
|||||||
|
|
||||||
go 1.16
|
go 1.16
|
||||||
|
|
||||||
require github.com/gorilla/mux v1.8.0
|
require (
|
||||||
|
github.com/gorilla/mux v1.8.0
|
||||||
|
golang.org/x/mod v0.5.1
|
||||||
|
)
|
||||||
|
13
go.sum
13
go.sum
@ -1,2 +1,15 @@
|
|||||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/mod v0.5.1 h1:OJxoQ/rynoF0dcCdI7cLPktw/hR2cueqYfjm43oqK38=
|
||||||
|
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
|
22
main.go
22
main.go
@ -18,6 +18,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/tardisx/gropple/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
type download struct {
|
type download struct {
|
||||||
@ -50,7 +51,7 @@ var defaultArgs = args{
|
|||||||
"--newline",
|
"--newline",
|
||||||
}
|
}
|
||||||
|
|
||||||
const currentVersion = "v0.04"
|
var versionInfo = version.Info{CurrentVersion: "v0.4.0"}
|
||||||
|
|
||||||
//go:embed web
|
//go:embed web
|
||||||
var webFS embed.FS
|
var webFS embed.FS
|
||||||
@ -83,6 +84,7 @@ func main() {
|
|||||||
r.HandleFunc("/fetch", FetchHandler)
|
r.HandleFunc("/fetch", FetchHandler)
|
||||||
r.HandleFunc("/fetch/info", FetchInfoHandler)
|
r.HandleFunc("/fetch/info", FetchInfoHandler)
|
||||||
r.HandleFunc("/fetch/info/{id}", FetchInfoOneHandler)
|
r.HandleFunc("/fetch/info/{id}", FetchInfoOneHandler)
|
||||||
|
r.HandleFunc("/version", VersionHandler)
|
||||||
|
|
||||||
http.Handle("/", r)
|
http.Handle("/", r)
|
||||||
|
|
||||||
@ -94,10 +96,26 @@ func main() {
|
|||||||
ReadTimeout: 5 * time.Second,
|
ReadTimeout: 5 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf("starting gropple %s - https://github.com/tardisx/gropple", currentVersion)
|
// check for a new version every 4 hours
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
versionInfo.UpdateGitHubVersion()
|
||||||
|
time.Sleep(time.Hour * 4)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
log.Printf("starting gropple %s - https://github.com/tardisx/gropple", versionInfo.CurrentVersion)
|
||||||
log.Printf("go to %s for details on installing the bookmarklet and to check status", address)
|
log.Printf("go to %s for details on installing the bookmarklet and to check status", address)
|
||||||
log.Fatal(srv.ListenAndServe())
|
log.Fatal(srv.ListenAndServe())
|
||||||
|
}
|
||||||
|
|
||||||
|
func VersionHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if versionInfo.GithubVersionFetched {
|
||||||
|
b, _ := json.Marshal(versionInfo)
|
||||||
|
w.Write(b)
|
||||||
|
} else {
|
||||||
|
w.WriteHeader(400)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
func HomeHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -1,4 +1,17 @@
|
|||||||
{{ define "content" }}
|
{{ define "content" }}
|
||||||
|
|
||||||
|
|
||||||
|
<div x-data="index()" x-init="fetch_data(); fetch_version()">
|
||||||
|
|
||||||
|
<h2>gropple</h2>
|
||||||
|
|
||||||
|
<p x-show="version && version.upgrade_available">
|
||||||
|
<a href="https://github.com/tardisx/gropple/releases">Upgrade is available</a> -
|
||||||
|
you have
|
||||||
|
<span x-text="version.current_version"></span> and
|
||||||
|
<span x-text="version.github_version"></span>
|
||||||
|
is available.</p>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<p>
|
<p>
|
||||||
Drag this bookmarklet: <a href="{{ .BookmarkletURL }}">Gropple</a> to your bookmark bar, and click it
|
Drag this bookmarklet: <a href="{{ .BookmarkletURL }}">Gropple</a> to your bookmark bar, and click it
|
||||||
@ -6,7 +19,6 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div x-data="index()" x-init="fetch_data()">
|
|
||||||
<table class="pure-table">
|
<table class="pure-table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -39,7 +51,19 @@
|
|||||||
<script>
|
<script>
|
||||||
function index() {
|
function index() {
|
||||||
return {
|
return {
|
||||||
items: [],
|
items: [], version: {},
|
||||||
|
fetch_version() {
|
||||||
|
fetch('/version')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(info => {
|
||||||
|
this.version = info;
|
||||||
|
setTimeout(() => { this.fetch_version() }, 1000 * 60 );
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.log('failed to fetch version info - will retry');
|
||||||
|
setTimeout(() => { this.fetch_version() }, 1000 );
|
||||||
|
});
|
||||||
|
},
|
||||||
fetch_data() {
|
fetch_data() {
|
||||||
fetch('/fetch/info')
|
fetch('/fetch/info')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
|
@ -13,10 +13,17 @@
|
|||||||
height: 100px;
|
height: 100px;
|
||||||
overflow:auto;
|
overflow:auto;
|
||||||
}
|
}
|
||||||
|
footer {
|
||||||
|
padding-top: 50px;
|
||||||
|
font-size: 30%;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body style="margin:4; padding:4">
|
<body style="margin:4; padding:4">
|
||||||
{{ template "content" . }}
|
{{ template "content" . }}
|
||||||
|
<footer>
|
||||||
|
Homepage: <a href="https://github.com/tardisx/gropple">https://github.com/tardisx/gropple</a>
|
||||||
|
</footer>
|
||||||
</body>
|
</body>
|
||||||
{{ template "js" . }}
|
{{ template "js" . }}
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user