mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-11-18 03:49:50 -06:00
Print a reminder of an available update when lazygit exits
Users who use lazygit for short sessions, and never leave it idle for a minute, don't get to see the update menu until a week after the update came out. Print a short message to the terminal after lazygit exits, the way gh and npm do. The user is back in the shell at that point, where they can run the command that we show. Do this at most once a day, and not on a day when the user responded to the update menu. The message doesn't count as a response to the menu. If other lazygit instances show the menu, it stays open there, and an idle lazygit can still show it later that day. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2396d6e738
commit
d9b8fe5587
6 files changed
+117
No files matched your search
@@ -263,6 +263,8 @@ type UpdatesState struct {
|
||||
RespondedVersion string
|
||||
// The version that the user doesn't want to be reminded of
|
||||
SkippedVersion string
|
||||
// When lazygit last printed a reminder after exiting
|
||||
LastExitMessage int64
|
||||
|
||||
// The version that an update installed in place of the executable at
|
||||
// InstalledPath. It takes effect when lazygit is restarted.
|
||||
|
||||
@@ -156,6 +156,61 @@ func (self *UpdateHelper) Note() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// ExitMessage returns a message about an available update that we print after
|
||||
// lazygit exits, or "" if no reminder is due. This reaches users who never
|
||||
// leave lazygit idle, and they are in the shell, where they can update right
|
||||
// away.
|
||||
func (self *UpdateHelper) ExitMessage() string {
|
||||
version := self.updater.ClaimExitMessage()
|
||||
if version == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
lines := []string{utils.ResolvePlaceholderString(
|
||||
self.c.Tr.NewVersionAvailable,
|
||||
map[string]string{
|
||||
"newVersion": version.String(),
|
||||
"currentVersion": self.updater.CurrentVersion().String(),
|
||||
},
|
||||
)}
|
||||
|
||||
installation := self.updater.Installation()
|
||||
installationInstructions := utils.ResolvePlaceholderString(
|
||||
self.c.Tr.ExitMessageInstallationInstructions,
|
||||
map[string]string{"url": constants.Links.InstallationInstructions},
|
||||
)
|
||||
switch {
|
||||
case installation.Kind == updates.InstallKindRelease:
|
||||
if err := self.updater.CheckCanInstall(); err != nil {
|
||||
lines = append(lines,
|
||||
utils.ResolvePlaceholderString(
|
||||
self.c.Tr.UpdateFolderNotWritable,
|
||||
map[string]string{"folder": filepath.Dir(installation.ExecutablePath)},
|
||||
),
|
||||
installationInstructions,
|
||||
)
|
||||
} else if key := self.c.UserConfig().Keybinding.Status.CheckForUpdate.String(); key != "" {
|
||||
lines = append(lines, utils.ResolvePlaceholderString(
|
||||
self.c.Tr.ExitMessageInstallWithKey, map[string]string{"key": key},
|
||||
))
|
||||
}
|
||||
case installation.UpdateCommand() != "":
|
||||
lines = append(lines, utils.ResolvePlaceholderString(
|
||||
self.c.Tr.ExitMessageUpdateCommand, map[string]string{"command": installation.UpdateCommand()},
|
||||
))
|
||||
default:
|
||||
lines = append(lines, self.c.Tr.ExitMessageCheckPackageManager, installationInstructions)
|
||||
}
|
||||
|
||||
lines = append(lines,
|
||||
utils.ResolvePlaceholderString(
|
||||
self.c.Tr.ExitMessageReleaseNotes, map[string]string{"url": constants.Links.Releases},
|
||||
),
|
||||
self.c.Tr.TurnOffUpdateReminders,
|
||||
)
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
// ShowUpdateMenu shows the menu for the update that the note in the
|
||||
// bottom-right corner tells the user about
|
||||
func (self *UpdateHelper) ShowUpdateMenu() error {
|
||||
|
||||
@@ -1059,6 +1059,10 @@ func (gui *Gui) RunAndHandleError(startArgs appTypes.StartArgs) error {
|
||||
}
|
||||
}
|
||||
|
||||
if message := gui.helpers.Update.ExitMessage(); message != "" {
|
||||
fmt.Println(message)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -292,6 +292,11 @@ type TranslationSet struct {
|
||||
RemindMeTomorrow string
|
||||
SkipThisVersion string
|
||||
TurnOffUpdateReminders string
|
||||
ExitMessageInstallWithKey string
|
||||
ExitMessageUpdateCommand string
|
||||
ExitMessageCheckPackageManager string
|
||||
ExitMessageInstallationInstructions string
|
||||
ExitMessageReleaseNotes string
|
||||
IntroPopupMessage string
|
||||
NonReloadableConfigWarningTitle string
|
||||
NonReloadableConfigWarning string
|
||||
@@ -1531,6 +1536,11 @@ func EnglishTranslationSet() *TranslationSet {
|
||||
RemindMeTomorrow: "Remind me tomorrow",
|
||||
SkipThisVersion: "Skip this version",
|
||||
TurnOffUpdateReminders: "To turn off these reminders, set update.method to never in your config file.",
|
||||
ExitMessageInstallWithKey: "To install it, start lazygit and press {{.key}} in the status panel.",
|
||||
ExitMessageUpdateCommand: "To update, run: {{.command}}",
|
||||
ExitMessageCheckPackageManager: "Check whether your package manager has it yet, or install lazygit from our releases.",
|
||||
ExitMessageInstallationInstructions: "Installation instructions: {{.url}}",
|
||||
ExitMessageReleaseNotes: "Release notes: {{.url}}",
|
||||
IntroPopupMessage: englishIntroPopupMessage,
|
||||
NonReloadableConfigWarningTitle: "Config changed",
|
||||
NonReloadableConfigWarning: englishNonReloadableConfigWarning,
|
||||
|
||||
@@ -41,6 +41,8 @@ const (
|
||||
// responded to the menu for a long time, e.g. because they never leave
|
||||
// lazygit idle.
|
||||
ReminderMenuAtStartup
|
||||
// Print a message to the terminal after lazygit exits
|
||||
ReminderExitMessage
|
||||
)
|
||||
|
||||
// The part of config.AppConfigurer that the updater needs
|
||||
@@ -269,6 +271,20 @@ func (u *Updater) DueReminder(reminder Reminder) *types.VersionNumber {
|
||||
return u.dueReminder(u.readAppState(), reminder)
|
||||
}
|
||||
|
||||
// ClaimExitMessage returns the version to remind the user of in a message
|
||||
// after lazygit exits, or nil if no reminder is due, and records that we print
|
||||
// the message. We print it at most once a day.
|
||||
func (u *Updater) ClaimExitMessage() *types.VersionNumber {
|
||||
var version *types.VersionNumber
|
||||
u.updateAppState(func(state *config.AppState) {
|
||||
version = u.dueReminder(state, ReminderExitMessage)
|
||||
if version != nil {
|
||||
state.Updates.LastExitMessage = u.now().Unix()
|
||||
}
|
||||
})
|
||||
return version
|
||||
}
|
||||
|
||||
func (u *Updater) dueReminder(state *config.AppState, reminder Reminder) *types.VersionNumber {
|
||||
if !u.RemindersEnabled() {
|
||||
return nil
|
||||
@@ -290,6 +306,10 @@ func (u *Updater) dueReminder(state *config.AppState, reminder Reminder) *types.
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if reminder == ReminderExitMessage &&
|
||||
u.now().Sub(time.Unix(state.Updates.LastExitMessage, 0)) < reminderInterval {
|
||||
return nil
|
||||
}
|
||||
return status.AvailableVersion
|
||||
}
|
||||
|
||||
|
||||
@@ -351,6 +351,32 @@ func TestIsHandledAfter(t *testing.T) {
|
||||
assert.True(t, updater.IsHandledAfter(shownAt))
|
||||
}
|
||||
|
||||
func TestClaimExitMessage(t *testing.T) {
|
||||
now := time.Date(2026, 11, 3, 12, 0, 0, 0, time.UTC)
|
||||
v0670 := &types.VersionNumber{Major: 0, Minor: 67, Patch: 0}
|
||||
|
||||
updater := newTestUpdater(t, nil, "0.66.2", Installation{Kind: InstallKindRelease, ExecutablePath: "/bin/lazygit"})
|
||||
updater.now = func() time.Time { return now }
|
||||
state := updater.appState.(*fakeAppStateStore).state
|
||||
state.Updates = config.UpdatesState{LatestVersion: "v0.67.0", LatestVersionFoundAt: now.Add(-8 * 24 * time.Hour).Unix()}
|
||||
|
||||
assert.Equal(t, v0670, updater.ClaimExitMessage())
|
||||
assert.Nil(t, updater.ClaimExitMessage())
|
||||
|
||||
// The exit message isn't a response to the menu, so the menu still
|
||||
// appears
|
||||
assert.Equal(t, v0670, updater.DueReminder(ReminderMenuWhenIdle))
|
||||
assert.Equal(t, v0670, updater.DueReminder(ReminderMenuAtStartup))
|
||||
|
||||
now = now.Add(25 * time.Hour)
|
||||
assert.Equal(t, v0670, updater.ClaimExitMessage())
|
||||
|
||||
// After a response to the menu, there's no exit message for a day
|
||||
now = now.Add(25 * time.Hour)
|
||||
updater.RecordResponse(v0670)
|
||||
assert.Nil(t, updater.ClaimExitMessage())
|
||||
}
|
||||
|
||||
func TestRemindersAreOffWithUpdateMethodNever(t *testing.T) {
|
||||
updater := newTestUpdater(t, nil, "0.66.2", Installation{Kind: InstallKindRelease, ExecutablePath: "/bin/lazygit"})
|
||||
updater.appState.(*fakeAppStateStore).state.Updates = config.UpdatesState{LatestVersion: "v0.67.0"}
|
||||
|
||||
Reference in new issue
Block a user