Skip to content

Commit

Permalink
Merge pull request #60 from anywherelan/dirty_builds_update
Browse files Browse the repository at this point in the history
dirty builds can update now
  • Loading branch information
GrigoryKrasnochub authored Oct 31, 2022
2 parents 1ccdc67 + f57bd85 commit 1d5ed40
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
4 changes: 4 additions & 0 deletions cmd/awl-tray/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ func onReady() {
}
if conf.Update.TrayAutoCheckEnabled {
go func() {
if config.IsDevVersion() {
logger.Info("updates auto check is disabled for dev version")
return
}
interval, err := time.ParseDuration(conf.Update.TrayAutoCheckInterval)
if err != nil {
logger.Errorf("update auto check: interval parse: %v", err)
Expand Down
16 changes: 9 additions & 7 deletions cmd/awl-tray/tray.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,14 @@ func checkForUpdatesWithDesktopNotification() {
logger.Errorf("update auto check: check for updates: %v", err)
return
}
if updStatus {
notifyErr := beeep.Notify("Anywherelan: new version available!",
fmt.Sprintf("Version %s: %s available for installation!\nUse tray menu option %q\n",
updService.NewVersion.VersionTag(), updService.NewVersion.VersionName(), updateMenuLabel), tempIconFilepath)
if notifyErr != nil {
logger.Errorf("show notification: new version available: %v", notifyErr)
}
if !updStatus {
return
}

notifyErr := beeep.Notify("Anywherelan: new version available!",
fmt.Sprintf("Version %s: %s available for installation!\nUse tray menu option %q\n",
updService.NewVersion.VersionTag(), updService.NewVersion.VersionName(), updateMenuLabel), tempIconFilepath)
if notifyErr != nil {
logger.Errorf("show notification: new version available: %v", notifyErr)
}
}
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ func (c *Config) LogLevel() zapcore.Level {
return lvl
}

// DevMode
// Possible duplicate of IsDevVersion()
// Based on Config.LoggerLevel (could be used by any user)
func (c *Config) DevMode() bool {
return c.LoggerLevel == "dev"
}
Expand Down
11 changes: 10 additions & 1 deletion config/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ import (
"strings"
)

const DevVersion = "dev"

var (
Version = "dev"
Version = DevVersion
UserAgent = UserAgentPrefix + Version
UserAgentPrefix = "awl/"
)

// IsDevVersion
// Possible duplicate of *Config.DevMode()
// Based on build version (unchangeable after build, could be used only by developers)
func IsDevVersion() bool {
return Version == DevVersion
}

func VersionFromUserAgent(userAgent string) string {
return strings.TrimPrefix(userAgent, UserAgentPrefix)
}
15 changes: 14 additions & 1 deletion update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"path/filepath"
"regexp"
"runtime"
"strings"
"unicode"

"github.com/GrigoryKrasnochub/updaterini"
"github.com/anywherelan/awl/config"
Expand Down Expand Up @@ -42,6 +44,10 @@ var (
)

func NewUpdateService(c *config.Config, logger *log.ZapEventLogger, appType ApplicationType) (UpdateService, error) {
if config.IsDevVersion() {
return UpdateService{}, errors.New("updates are unsupported for dev version")
}

channels := make([]updaterini.Channel, 1)
channels[0] = updaterini.NewReleaseChannel(true)

Expand All @@ -67,7 +73,14 @@ func NewUpdateService(c *config.Config, logger *log.ZapEventLogger, appType Appl
filenamesRegex[0] = awlTrayFilenamesRegex
}

appConf, err := updaterini.NewApplicationConfig(config.Version, channels, filenamesRegex)
// TODO update when issue will be fixed https://github.com/GrigoryKrasnochub/updaterini/issues/6
version := config.Version
splitVer := strings.Split(config.Version, "-")
if len(splitVer) > 1 && (len(splitVer[1]) == 0 || unicode.IsDigit([]rune(splitVer[1])[0])) {
version = splitVer[0]
}

appConf, err := updaterini.NewApplicationConfig(version, channels, filenamesRegex)
if err != nil {
return UpdateService{}, err
}
Expand Down

0 comments on commit 1d5ed40

Please sign in to comment.