Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: version check works now #20

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 49 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import (
"fyne.io/fyne/v2/widget"

"github.com/google/go-github/v39/github"
"fmt"
"strings"
"strconv"
)

const (
owner = "dpolakovics"
repo = "soundscape-sync"
currentTag = "v0.10"
owner = "dpolakovics"
repo = "soundscape-sync"
currentTag = "v0.9"
)

func main() {
Expand All @@ -34,24 +37,47 @@ func main() {
}

func checkForUpdates(a fyne.App, w fyne.Window) {
client := github.NewClient(nil)
release, _, err := client.Repositories.GetLatestRelease(context.Background(), owner, repo)
if err != nil {
dialog.ShowError(err, w)
return
}

latestTag := release.GetTagName()
if latestTag > currentTag {
updateDialog := dialog.NewCustom("Update Available", "Close",
container.NewVBox(
widget.NewLabel("A new version is available!"),
widget.NewButton("Open Release Page", func() {
u, _ := url.Parse(release.GetHTMLURL())
_ = a.OpenURL(u)
}),
), w)
updateDialog.Resize(fyne.NewSize(300, 150))
updateDialog.Show()
}
client := github.NewClient(nil)
release, _, err := client.Repositories.GetLatestRelease(context.Background(), owner, repo)
if err != nil {
dialog.ShowError(err, w)
return
}

latestTag := release.GetTagName()
fmt.Println("Latest tag:", latestTag)
if isNewerVersion(currentTag, latestTag) {
updateDialog := dialog.NewCustom("Update Available", "Close",
container.NewVBox(
widget.NewLabel("A new version is available!"),
widget.NewButton("Open Release Page", func() {
u, _ := url.Parse(release.GetHTMLURL())
_ = a.OpenURL(u)
}),
), w)
updateDialog.Resize(fyne.NewSize(300, 150))
updateDialog.Show()
}
}

func isNewerVersion(oldVer, newVer string) bool {
// Strip leading 'v'
oldVer = strings.TrimPrefix(oldVer, "v")
newVer = strings.TrimPrefix(newVer, "v")

oldParts := strings.Split(oldVer, ".")
newParts := strings.Split(newVer, ".")

for i := 0; i < len(oldParts) && i < len(newParts); i++ {
oldNum, _ := strconv.Atoi(oldParts[i])
newNum, _ := strconv.Atoi(newParts[i])
if newNum > oldNum {
return true
} else if newNum < oldNum {
return false
}
}

// If all matched so far, then a longer new version means it's newer
return len(newParts) > len(oldParts)
}
Loading