2018-08-27 20:08:10 +10:00
|
|
|
package gui
|
|
|
|
|
2020-11-21 18:58:55 +11:00
|
|
|
import (
|
|
|
|
"github.com/jesseduffield/gocui"
|
2022-01-29 19:09:20 +11:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
2022-03-24 13:19:46 +01:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
2020-11-21 18:58:55 +11:00
|
|
|
)
|
2018-08-27 20:08:10 +10:00
|
|
|
|
2020-08-23 12:20:49 +10:00
|
|
|
func (gui *Gui) showUpdatePrompt(newVersion string) error {
|
2022-03-24 13:19:46 +01:00
|
|
|
message := utils.ResolvePlaceholderString(
|
|
|
|
gui.Tr.UpdateAvailable, map[string]string{
|
|
|
|
"newVersion": newVersion,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2022-03-30 08:48:29 +02:00
|
|
|
return gui.c.Confirm(types.ConfirmOpts{
|
2022-03-24 13:19:46 +01:00
|
|
|
Title: gui.Tr.UpdateAvailableTitle,
|
|
|
|
Prompt: message,
|
2022-01-28 20:44:36 +11:00
|
|
|
HandleConfirm: func() error {
|
2020-08-15 16:36:39 +10:00
|
|
|
gui.startUpdating(newVersion)
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
})
|
2018-08-27 20:08:10 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) onUserUpdateCheckFinish(newVersion string, err error) error {
|
|
|
|
if err != nil {
|
2022-01-16 14:46:53 +11:00
|
|
|
return gui.c.Error(err)
|
2018-08-27 20:08:10 +10:00
|
|
|
}
|
|
|
|
if newVersion == "" {
|
2022-03-24 13:19:46 +01:00
|
|
|
return gui.c.ErrorMsg(gui.Tr.FailedToRetrieveLatestVersionErr)
|
2018-08-27 20:08:10 +10:00
|
|
|
}
|
|
|
|
return gui.showUpdatePrompt(newVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) onBackgroundUpdateCheckFinish(newVersion string, err error) error {
|
|
|
|
if err != nil {
|
|
|
|
// ignoring the error for now so that I'm not annoying users
|
2022-01-16 14:46:53 +11:00
|
|
|
gui.c.Log.Error(err.Error())
|
2018-08-27 20:08:10 +10:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if newVersion == "" {
|
|
|
|
return nil
|
|
|
|
}
|
2022-01-16 14:46:53 +11:00
|
|
|
if gui.c.UserConfig.Update.Method == "background" {
|
2018-08-27 20:08:10 +10:00
|
|
|
gui.startUpdating(newVersion)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return gui.showUpdatePrompt(newVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) startUpdating(newVersion string) {
|
|
|
|
gui.State.Updating = true
|
2022-03-24 13:19:46 +01:00
|
|
|
statusId := gui.statusManager.addWaitingStatus(gui.Tr.UpdateInProgressWaitingStatus)
|
2020-11-18 09:08:32 +11:00
|
|
|
gui.Updater.Update(newVersion, func(err error) error { return gui.onUpdateFinish(statusId, err) })
|
2018-08-27 20:08:10 +10:00
|
|
|
}
|
|
|
|
|
2020-11-18 09:08:32 +11:00
|
|
|
func (gui *Gui) onUpdateFinish(statusId int, err error) error {
|
2018-08-27 20:08:10 +10:00
|
|
|
gui.State.Updating = false
|
2020-11-18 09:08:32 +11:00
|
|
|
gui.statusManager.removeStatus(statusId)
|
2022-08-06 18:50:52 +10:00
|
|
|
gui.c.OnUIThread(func() error {
|
2022-01-15 12:04:00 +11:00
|
|
|
_ = gui.renderString(gui.Views.AppStatus, "")
|
|
|
|
if err != nil {
|
2022-03-24 13:19:46 +01:00
|
|
|
errMessage := utils.ResolvePlaceholderString(
|
|
|
|
gui.Tr.UpdateFailedErr, map[string]string{
|
|
|
|
"errMessage": err.Error(),
|
|
|
|
},
|
|
|
|
)
|
|
|
|
return gui.c.ErrorMsg(errMessage)
|
2022-01-15 12:04:00 +11:00
|
|
|
}
|
2022-03-24 13:42:57 +01:00
|
|
|
return gui.c.Alert(gui.Tr.UpdateCompletedTitle, gui.Tr.UpdateCompleted)
|
2022-01-15 12:04:00 +11:00
|
|
|
})
|
|
|
|
|
2018-08-27 20:08:10 +10:00
|
|
|
return nil
|
|
|
|
}
|
2018-08-27 20:26:49 +10:00
|
|
|
|
2020-08-15 17:23:16 +10:00
|
|
|
func (gui *Gui) createUpdateQuitConfirmation() error {
|
2022-03-30 08:48:29 +02:00
|
|
|
return gui.c.Confirm(types.ConfirmOpts{
|
2022-03-24 13:19:46 +01:00
|
|
|
Title: gui.Tr.ConfirmQuitDuringUpdateTitle,
|
|
|
|
Prompt: gui.Tr.ConfirmQuitDuringUpdate,
|
2022-01-28 20:44:36 +11:00
|
|
|
HandleConfirm: func() error {
|
2020-08-15 16:36:39 +10:00
|
|
|
return gocui.ErrQuit
|
|
|
|
},
|
|
|
|
})
|
2018-08-27 20:26:49 +10:00
|
|
|
}
|