2018-08-27 12:08:10 +02:00
|
|
|
package gui
|
|
|
|
|
2020-11-21 09:58:55 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/jesseduffield/gocui"
|
2022-01-29 10:09:20 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
2020-11-21 09:58:55 +02:00
|
|
|
)
|
2018-08-27 12:08:10 +02:00
|
|
|
|
2020-08-23 04:20:49 +02:00
|
|
|
func (gui *Gui) showUpdatePrompt(newVersion string) error {
|
2022-01-29 10:09:20 +02:00
|
|
|
return gui.c.Ask(types.AskOpts{
|
2022-01-28 11:44:36 +02:00
|
|
|
Title: "New version available!",
|
|
|
|
Prompt: fmt.Sprintf("Download version %s? (enter/esc)", newVersion),
|
|
|
|
HandleConfirm: func() error {
|
2020-08-15 08:36:39 +02:00
|
|
|
gui.startUpdating(newVersion)
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
})
|
2018-08-27 12:08:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) onUserUpdateCheckFinish(newVersion string, err error) error {
|
|
|
|
if err != nil {
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.Error(err)
|
2018-08-27 12:08:10 +02:00
|
|
|
}
|
|
|
|
if newVersion == "" {
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.ErrorMsg("New version not found")
|
2018-08-27 12:08:10 +02: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 05:46:53 +02:00
|
|
|
gui.c.Log.Error(err.Error())
|
2018-08-27 12:08:10 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if newVersion == "" {
|
|
|
|
return nil
|
|
|
|
}
|
2022-01-16 05:46:53 +02:00
|
|
|
if gui.c.UserConfig.Update.Method == "background" {
|
2018-08-27 12:08:10 +02:00
|
|
|
gui.startUpdating(newVersion)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return gui.showUpdatePrompt(newVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) startUpdating(newVersion string) {
|
|
|
|
gui.State.Updating = true
|
2020-11-18 00:08:32 +02:00
|
|
|
statusId := gui.statusManager.addWaitingStatus("updating")
|
|
|
|
gui.Updater.Update(newVersion, func(err error) error { return gui.onUpdateFinish(statusId, err) })
|
2018-08-27 12:08:10 +02:00
|
|
|
}
|
|
|
|
|
2020-11-18 00:08:32 +02:00
|
|
|
func (gui *Gui) onUpdateFinish(statusId int, err error) error {
|
2018-08-27 12:08:10 +02:00
|
|
|
gui.State.Updating = false
|
2020-11-18 00:08:32 +02:00
|
|
|
gui.statusManager.removeStatus(statusId)
|
2022-01-15 03:04:00 +02:00
|
|
|
gui.OnUIThread(func() error {
|
|
|
|
_ = gui.renderString(gui.Views.AppStatus, "")
|
|
|
|
if err != nil {
|
2022-01-16 05:46:53 +02:00
|
|
|
return gui.c.ErrorMsg("Update failed: " + err.Error())
|
2022-01-15 03:04:00 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
|
2018-08-27 12:08:10 +02:00
|
|
|
return nil
|
|
|
|
}
|
2018-08-27 12:26:49 +02:00
|
|
|
|
2020-08-15 09:23:16 +02:00
|
|
|
func (gui *Gui) createUpdateQuitConfirmation() error {
|
2022-01-29 10:09:20 +02:00
|
|
|
return gui.c.Ask(types.AskOpts{
|
2022-01-28 11:44:36 +02:00
|
|
|
Title: "Currently Updating",
|
|
|
|
Prompt: "An update is in progress. Are you sure you want to quit?",
|
|
|
|
HandleConfirm: func() error {
|
2020-08-15 08:36:39 +02:00
|
|
|
return gocui.ErrQuit
|
|
|
|
},
|
|
|
|
})
|
2018-08-27 12:26:49 +02:00
|
|
|
}
|