show dialog on later version found

This commit is contained in:
Drew Weymouth
2023-03-30 19:19:01 -07:00
parent 8d13575000
commit d59352cd4d
4 changed files with 96 additions and 17 deletions
+4
View File
@@ -36,6 +36,10 @@ type App struct {
cancel context.CancelFunc
}
func (a *App) VersionTag() string {
return a.appVersionTag
}
func StartupApp(appName, appVersionTag, configFile, latestReleaseURL string) (*App, error) {
a := &App{appName: appName, appVersionTag: appVersionTag, configFile: configFile}
a.bgrndCtx, a.cancel = context.WithCancel(context.Background())
+12 -7
View File
@@ -4,14 +4,15 @@ import (
"context"
"log"
"net/http"
"net/url"
"strings"
"time"
)
type UpdateChecker struct {
OnUpdatedVersionFound func(releaseURL string)
OnUpdatedVersionFound func()
foundUpdate bool
versionTagFound string
latestReleaseURL string
appVersionTag string
lastCheckedTag *string
@@ -41,17 +42,21 @@ func (u *UpdateChecker) Start(ctx context.Context, interval time.Duration) {
}()
}
func (u *UpdateChecker) UpdateAvailable() bool {
return u.foundUpdate
func (u *UpdateChecker) VersionTagFound() string {
return u.versionTagFound
}
func (u *UpdateChecker) LatestReleaseURL() *url.URL {
url, _ := url.Parse(u.latestReleaseURL)
return url
}
func (u *UpdateChecker) checkForUpdate() {
t := u.latestVersionTag()
if t != "" && t != *u.lastCheckedTag {
u.foundUpdate = true
*u.lastCheckedTag = t
u.versionTagFound = t
if u.OnUpdatedVersionFound != nil {
u.OnUpdatedVersionFound(u.latestReleaseURL)
u.OnUpdatedVersionFound()
}
}
}