Skip to content

Commit

Permalink
Add old version update check
Browse files Browse the repository at this point in the history
  • Loading branch information
koho committed May 13, 2024
1 parent 14acaab commit 85f44b9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/res/res.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
const (
ProjectURL = "https://github.com/koho/frpmgr"
FRPProjectURL = "https://github.com/fatedier/frp"
UpdateURL = "https://api.github.com/repos/koho/frpmgr/releases/latest"
UpdateURL = "https://api.github.com/repos/koho/frpmgr/releases"
ShareLinkScheme = "frp://"
)

Expand Down
27 changes: 27 additions & 0 deletions pkg/version/parser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package version

import (
"fmt"
"regexp"
"strconv"
)

// Parse parses a version string into its major, minor, and patch components.
func Parse(s string) (major, minor, patch int, err error) {
re := regexp.MustCompile(`^v?(\d+)\.(\d+)\.(\d+)$`)
matches := re.FindStringSubmatch(s)
if matches == nil {
err = fmt.Errorf("invalid version string: %s", s)
return
}
major, err = strconv.Atoi(matches[1])
if err != nil {
return
}
minor, err = strconv.Atoi(matches[2])
if err != nil {
return
}
patch, err = strconv.Atoi(matches[3])
return
}
24 changes: 20 additions & 4 deletions ui/aboutpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type GithubRelease struct {

type aboutViewModel struct {
GithubRelease
Releases []GithubRelease
Checking bool
NewVersion bool
TabIcon *walk.Icon
Expand Down Expand Up @@ -130,7 +131,8 @@ func (ap *AboutPage) checkUpdate(showErr bool) {
goto Fin
}
ap.viewModel.GithubRelease = GithubRelease{}
err = json.Unmarshal(body, &ap.viewModel.GithubRelease)
ap.viewModel.Releases = []GithubRelease{}
err = json.Unmarshal(body, &ap.viewModel.Releases)
Fin:
ap.Synchronize(func() {
ap.viewModel.Checking = false
Expand All @@ -141,9 +143,23 @@ func (ap *AboutPage) checkUpdate(showErr bool) {
}
return
}
if ap.viewModel.TagName != "" && ap.viewModel.TagName[1:] != version.Number {
ap.viewModel.NewVersion = true
} else {
major, minor, patch, err := version.Parse(version.Number)
if err != nil {
return
}
for _, v := range ap.viewModel.Releases {
rMajor, rMinor, rPatch, err := version.Parse(v.TagName)
if err != nil {
continue
}
// Find the latest available version
if rMajor == major && rMinor == minor && rPatch > patch {
patch = rPatch
ap.viewModel.NewVersion = true
ap.viewModel.GithubRelease = v
}
}
if ap.viewModel.TagName == "" {
ap.viewModel.NewVersion = false
if showErr {
showInfoMessage(ap.Form(), "", i18n.Sprintf("There are currently no updates available."))
Expand Down

0 comments on commit 85f44b9

Please sign in to comment.