Skip to content

Commit d9a3bdb

Browse files
committed
optimize update check
1 parent ace92fb commit d9a3bdb

3 files changed

Lines changed: 26 additions & 34 deletions

File tree

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
default: release
1+
default: build
2+
3+
build:
4+
go build -o podwise .
25

36
release:
47
@$(if $(strip $(version)),:,$(error version is required: make release version=v1.2.3))
58
git tag $(version) && git push origin $(version)
6-
goreleaser release --snapshot --clean
9+
goreleaser release --snapshot --clean
10+
11+
upload:
12+
@$(if $(strip $(version)),:,$(error version is required: make release version=v1.2.3))
13+
gh release create $(version) ./dist/*.tar.gz ./dist/*.zip checksums.txt --generate-notes --title "v$(version)" --latest

cmd/root.go

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,50 +29,35 @@ mind maps, highlights and more.`,
2929
func Execute(version, commit, date string) {
3030
rootCmd.Version = fmt.Sprintf("%s (commit %s, built %s)", version, commit, date)
3131

32-
updateCh := maybeStartUpdateCheck(version)
32+
var updateResult *update.Result
33+
maybeStartUpdateCheck(version, &updateResult)
3334

3435
if err := rootCmd.Execute(); err != nil {
3536
async.Wait() // Wait for background tasks before exit
3637
os.Exit(1)
3738
}
3839

39-
printUpdateNotice(updateCh)
40-
async.Wait() // Wait for background tasks before exit
40+
async.Wait() // Wait for background tasks (including update check) before exit
41+
printUpdateNotice(updateResult)
4142
}
4243

43-
// maybeStartUpdateCheck starts an async update check and returns a channel that
44-
// will receive the result. The channel is closed immediately when the check
45-
// should be skipped (MCP mode, non-TTY, or PODWISE_NO_UPDATE_CHECK env var set).
46-
func maybeStartUpdateCheck(version string) <-chan update.Result {
47-
ch := make(chan update.Result, 1)
48-
44+
// maybeStartUpdateCheck starts an async update check using the async package.
45+
// The check is skipped in MCP mode, non-TTY environments, or when PODWISE_NO_UPDATE_CHECK is set.
46+
// The result is stored in the provided pointer after the check completes.
47+
func maybeStartUpdateCheck(version string, result **update.Result) {
4948
if isMCPCommand() || !isTerminal(os.Stderr) || os.Getenv("PODWISE_NO_UPDATE_CHECK") != "" {
50-
close(ch)
51-
return ch
49+
return
5250
}
5351

54-
go func() {
55-
ch <- update.Check(version)
56-
}()
57-
58-
return ch
52+
async.Go(func() {
53+
r := update.Check(version)
54+
*result = &r
55+
})
5956
}
6057

61-
// printUpdateNotice performs a non-blocking read of the update channel and
62-
// prints a notice to stderr when a newer version is available.
63-
func printUpdateNotice(ch <-chan update.Result) {
64-
var result update.Result
65-
select {
66-
case r, ok := <-ch:
67-
if !ok {
68-
return
69-
}
70-
result = r
71-
default:
72-
return
73-
}
74-
75-
if !result.HasUpdate {
58+
// printUpdateNotice prints a notice to stderr when a newer version is available.
59+
func printUpdateNotice(result *update.Result) {
60+
if result == nil || !result.HasUpdate {
7661
return
7762
}
7863

internal/update/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func UpgradeHint() string {
6262
if execPath, err := os.Executable(); err == nil {
6363
lower := strings.ToLower(execPath)
6464
if strings.Contains(lower, "/homebrew/") || strings.Contains(lower, "/linuxbrew/") {
65-
return "brew upgrade podwise"
65+
return "brew update && brew upgrade podwise"
6666
}
6767
}
6868
return fmt.Sprintf(

0 commit comments

Comments
 (0)