add update check
This commit is contained in:
parent
7194fefc5c
commit
ead5522c68
|
@ -15,7 +15,7 @@ and [Lip Gloss](https://github.com/charmbracelet/lipgloss).
|
||||||
- [x] Statistics are saved to `~/.wordle.json` for use in other programs
|
- [x] Statistics are saved to `~/.wordle.json` for use in other programs
|
||||||
- [x] Same word list as the official website
|
- [x] Same word list as the official website
|
||||||
- [ ] Leaderboard of people on current tilde
|
- [ ] Leaderboard of people on current tilde
|
||||||
- [ ] Update checking
|
- [x] Update checking
|
||||||
- [ ] Export to sharable message/emojis
|
- [ ] Export to sharable message/emojis
|
||||||
- [ ] Share to Mastodon
|
- [ ] Share to Mastodon
|
||||||
- [ ] Play previous days
|
- [ ] Play previous days
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -3,6 +3,7 @@ module tildegit.org/jakew/wordle
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/Masterminds/semver/v3 v3.1.1
|
||||||
github.com/charmbracelet/bubbletea v0.19.3
|
github.com/charmbracelet/bubbletea v0.19.3
|
||||||
github.com/charmbracelet/lipgloss v0.4.0
|
github.com/charmbracelet/lipgloss v0.4.0
|
||||||
)
|
)
|
||||||
|
|
2
go.sum
2
go.sum
|
@ -1,3 +1,5 @@
|
||||||
|
github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc=
|
||||||
|
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
|
||||||
github.com/charmbracelet/bubbletea v0.19.3 h1:OKeO/Y13rQQqt4snX+lePB0QrnW80UdrMNolnCcmoAw=
|
github.com/charmbracelet/bubbletea v0.19.3 h1:OKeO/Y13rQQqt4snX+lePB0QrnW80UdrMNolnCcmoAw=
|
||||||
github.com/charmbracelet/bubbletea v0.19.3/go.mod h1:VuXF2pToRxDUHcBUcPmCRUHRvFATM4Ckb/ql1rBl3KA=
|
github.com/charmbracelet/bubbletea v0.19.3/go.mod h1:VuXF2pToRxDUHcBUcPmCRUHRvFATM4Ckb/ql1rBl3KA=
|
||||||
github.com/charmbracelet/lipgloss v0.4.0 h1:768h64EFkGUr8V5yAKV7/Ta0NiVceiPaV+PphaW1K9g=
|
github.com/charmbracelet/lipgloss v0.4.0 h1:768h64EFkGUr8V5yAKV7/Ta0NiVceiPaV+PphaW1K9g=
|
||||||
|
|
8
main.go
8
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"os"
|
"os"
|
||||||
|
@ -8,6 +9,7 @@ import (
|
||||||
"tildegit.org/jakew/wordle/game/score"
|
"tildegit.org/jakew/wordle/game/score"
|
||||||
"tildegit.org/jakew/wordle/game/util"
|
"tildegit.org/jakew/wordle/game/util"
|
||||||
"tildegit.org/jakew/wordle/game/words"
|
"tildegit.org/jakew/wordle/game/words"
|
||||||
|
"tildegit.org/jakew/wordle/update"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -165,6 +167,12 @@ func (m model) View() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
updateMsg := update.CheckVersion(update.GetGiteaRelease("tildegit.org", "jakew", "wordle"), BuildVersion)
|
||||||
|
if updateMsg != "" {
|
||||||
|
fmt.Println(fmt.Sprintf("%v. Press enter to continue...", updateMsg))
|
||||||
|
bufio.NewReader(os.Stdin).ReadBytes('\n')
|
||||||
|
}
|
||||||
|
|
||||||
p := tea.NewProgram(initialModel())
|
p := tea.NewProgram(initialModel())
|
||||||
if err := p.Start(); err != nil {
|
if err := p.Start(); err != nil {
|
||||||
fmt.Printf("Something has gone wrong: %v", err)
|
fmt.Printf("Something has gone wrong: %v", err)
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package update
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"github.com/Masterminds/semver/v3"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetGiteaRelease(instance string, owner string, repo string) *semver.Version {
|
||||||
|
res, err := http.Get(fmt.Sprintf("https://%v/api/v1/repos/%v/%v/releases", instance, owner, repo))
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
|
||||||
|
var data []struct {
|
||||||
|
TagName string `json:"tag_name"`
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(body, &data)
|
||||||
|
if err != nil || len(data) < 1 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
v, err := semver.NewVersion(data[0].TagName)
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckVersion(latest *semver.Version, current string) string {
|
||||||
|
if latest == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
current1, err := semver.NewVersion(current)
|
||||||
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if latest.GreaterThan(current1) {
|
||||||
|
return fmt.Sprintf("A new version, %s, is available for download", latest)
|
||||||
|
} else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
var (
|
||||||
|
BuildVersion string = "?"
|
||||||
|
)
|
Loading…
Reference in New Issue