diff --git a/internal/app/app.go b/internal/app/app.go index c3748b15070324e9fa438b7ff56f15f76375974a..8519f258502ad10f146870b89c7bb5f0f50994e4 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -408,5 +408,6 @@ func (app *App) checkForUpdates(ctx context.Context) { app.events <- pubsub.UpdateAvailableMsg{ CurrentVersion: info.Current, LatestVersion: info.Latest, + IsDevelopment: info.IsDevelopment(), } } diff --git a/internal/pubsub/events.go b/internal/pubsub/events.go index 27cd47c4061ccfd11e4a9250b1a2fe319e477044..dadecaa14545337404c15000da37fbd5901932df 100644 --- a/internal/pubsub/events.go +++ b/internal/pubsub/events.go @@ -31,4 +31,5 @@ type ( type UpdateAvailableMsg struct { CurrentVersion string LatestVersion string + IsDevelopment bool } diff --git a/internal/tui/tui.go b/internal/tui/tui.go index 54bec287b2957fe97d377a3e34b9954c38338b71..e4eea700a4c109fa291fbaad3dc764e6df23921b 100644 --- a/internal/tui/tui.go +++ b/internal/tui/tui.go @@ -376,6 +376,9 @@ func (a *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) { case pubsub.UpdateAvailableMsg: // Show update notification in status bar statusMsg := fmt.Sprintf("Crush update available: v%s → v%s.", msg.CurrentVersion, msg.LatestVersion) + if msg.IsDevelopment { + statusMsg = fmt.Sprintf("This is a development version of Crush. The latest version is v%s.", msg.LatestVersion) + } s, statusCmd := a.status.Update(util.InfoMsg{ Type: util.InfoTypeInfo, Msg: statusMsg, diff --git a/internal/update/update.go b/internal/update/update.go index 0a3178d818207f11a7f46560065c4d47e8a1f5e7..b4982996126eb5d95d7f9acf22721ddc7378aedc 100644 --- a/internal/update/update.go +++ b/internal/update/update.go @@ -25,6 +25,10 @@ type Info struct { URL string } +func (i Info) IsDevelopment() bool { + return i.Current == "devel" || i.Current == "unknown" || strings.Contains(i.Current, "dirty") +} + // Available returns true if there's an update available. // // If both current and latest are stable versions, returns true if versions are @@ -52,10 +56,6 @@ func Check(ctx context.Context, current string, client Client) (Info, error) { Latest: current, } - if info.Current == "devel" || info.Current == "unknown" || strings.Contains(info.Current, "dirty") { - return info, nil - } - release, err := client.Latest(ctx) if err != nil { return info, fmt.Errorf("failed to fetch latest release: %w", err) diff --git a/internal/update/update_test.go b/internal/update/update_test.go index 488c7dfd4b29dec4dfe5d13958c13dcb914e5961..87e3849eb5a9ddc06b1e22c15c0bdde0b7739085 100644 --- a/internal/update/update_test.go +++ b/internal/update/update_test.go @@ -7,13 +7,6 @@ import ( "github.com/stretchr/testify/require" ) -func TestCheckForUpdate_DevelopmentVersion(t *testing.T) { - info, err := Check(t.Context(), "unknown", testClient{"v0.11.0"}) - require.NoError(t, err) - require.NotNil(t, info) - require.False(t, info.Available()) -} - func TestCheckForUpdate_Old(t *testing.T) { info, err := Check(t.Context(), "v0.10.0", testClient{"v0.11.0"}) require.NoError(t, err)