2018-08-27 12:08:10 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import "github.com/jesseduffield/gocui"
|
|
|
|
|
|
|
|
func (gui *Gui) showUpdatePrompt(newVersion string) error {
|
|
|
|
currentView := gui.g.CurrentView()
|
2020-08-15 08:36:39 +02:00
|
|
|
|
2020-08-15 08:38:16 +02:00
|
|
|
return gui.ask(askOpts{
|
2020-08-15 08:36:39 +02:00
|
|
|
returnToView: currentView,
|
|
|
|
returnFocusOnClose: true,
|
|
|
|
title: "New version available!",
|
|
|
|
prompt: "Download latest version? (enter/esc)",
|
|
|
|
handleConfirm: func() error {
|
|
|
|
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 {
|
2020-03-28 02:47:54 +02:00
|
|
|
return gui.surfaceError(err)
|
2018-08-27 12:08:10 +02:00
|
|
|
}
|
|
|
|
if newVersion == "" {
|
2020-03-28 02:47:54 +02:00
|
|
|
return gui.createErrorPanel("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
|
|
|
|
gui.Log.Error(err.Error())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if newVersion == "" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if gui.Config.GetUserConfig().Get("update.method") == "background" {
|
|
|
|
gui.startUpdating(newVersion)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return gui.showUpdatePrompt(newVersion)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) startUpdating(newVersion string) {
|
|
|
|
gui.State.Updating = true
|
|
|
|
gui.statusManager.addWaitingStatus("updating")
|
|
|
|
gui.Updater.Update(newVersion, gui.onUpdateFinish)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) onUpdateFinish(err error) error {
|
|
|
|
gui.State.Updating = false
|
|
|
|
gui.statusManager.removeStatus("updating")
|
2020-08-15 08:36:39 +02:00
|
|
|
gui.renderString("appStatus", "")
|
2018-08-27 12:08:10 +02:00
|
|
|
if err != nil {
|
2020-03-28 02:47:54 +02:00
|
|
|
return gui.createErrorPanel("Update failed: " + err.Error())
|
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 {
|
2020-08-15 08:38:16 +02:00
|
|
|
return gui.ask(askOpts{
|
2020-08-15 09:23:16 +02:00
|
|
|
returnToView: gui.g.CurrentView(),
|
2020-08-15 08:36:39 +02:00
|
|
|
returnFocusOnClose: true,
|
|
|
|
title: "Currently Updating",
|
|
|
|
prompt: "An update is in progress. Are you sure you want to quit?",
|
|
|
|
handleConfirm: func() error {
|
|
|
|
return gocui.ErrQuit
|
|
|
|
},
|
|
|
|
})
|
2018-08-27 12:26:49 +02:00
|
|
|
}
|