fix version check

This commit is contained in:
2025-08-08 09:47:48 -07:00
parent 336340269b
commit e7b5215d0f
3 changed files with 20 additions and 4 deletions

1
go.mod
View File

@@ -4,6 +4,7 @@ go 1.24.3
require (
github.com/BurntSushi/toml v1.5.0
github.com/Masterminds/semver/v3 v3.4.0
github.com/go-ole/go-ole v1.3.0
)

2
go.sum
View File

@@ -1,5 +1,7 @@
github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0=
github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=

View File

@@ -5,6 +5,8 @@ import (
"io"
"net/http"
"regexp"
"github.com/Masterminds/semver/v3"
)
const (
@@ -28,11 +30,22 @@ func needUpdate() (bool, error) {
return false, fmt.Errorf("unable to read response body: %v", err)
}
re := regexp.MustCompile(`const version = "([\d.]+)"`)
fmt.Println(string(b))
re := regexp.MustCompile(`version\s+=\s+"(\d+.\d+.\d+)"`)
ver := re.FindStringSubmatch(string(b))
if len(ver) < 2 || ver[1] == "" {
return false, fmt.Errorf("unable to find version in response")
if ver[1] == "" {
return false, fmt.Errorf("unable to parse version number")
}
return ver[1] != version, nil
curVer, err := semver.NewVersion(version)
if err != nil {
return false, fmt.Errorf("unable to parse current version to semver: %v", err)
}
newVer, err := semver.NewVersion(ver[1])
if err != nil {
return false, fmt.Errorf("unable to parse new version to semver: %v", err)
}
return curVer != newVer, nil
}