summaryrefslogtreecommitdiffstats
path: root/pkg/gui/updates.go
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2022-12-30 23:24:24 +1100
committerJesse Duffield <jessedduffield@gmail.com>2023-04-30 13:19:52 +1000
commit8edad826caf2fa48bfad33f9f8c4f3ba49a052da (patch)
tree0b49145e4f656e72441199b5a5c30176c898d7a7 /pkg/gui/updates.go
parent826128a8e03fb50f7287029ebac93c85712faecb (diff)
Begin refactoring gui
This begins a big refactor of moving more code out of the Gui struct into contexts, controllers, and helpers. We also move some code into structs in the gui package purely for the sake of better encapsulation
Diffstat (limited to 'pkg/gui/updates.go')
-rw-r--r--pkg/gui/updates.go85
1 files changed, 0 insertions, 85 deletions
diff --git a/pkg/gui/updates.go b/pkg/gui/updates.go
deleted file mode 100644
index 93231e4f0..000000000
--- a/pkg/gui/updates.go
+++ /dev/null
@@ -1,85 +0,0 @@
-package gui
-
-import (
- "github.com/jesseduffield/gocui"
- "github.com/jesseduffield/lazygit/pkg/gui/types"
- "github.com/jesseduffield/lazygit/pkg/utils"
-)
-
-func (gui *Gui) showUpdatePrompt(newVersion string) error {
- message := utils.ResolvePlaceholderString(
- gui.Tr.UpdateAvailable, map[string]string{
- "newVersion": newVersion,
- },
- )
-
- return gui.c.Confirm(types.ConfirmOpts{
- Title: gui.Tr.UpdateAvailableTitle,
- Prompt: message,
- HandleConfirm: func() error {
- gui.startUpdating(newVersion)
- return nil
- },
- })
-}
-
-func (gui *Gui) onUserUpdateCheckFinish(newVersion string, err error) error {
- if err != nil {
- return gui.c.Error(err)
- }
- if newVersion == "" {
- return gui.c.ErrorMsg(gui.Tr.FailedToRetrieveLatestVersionErr)
- }
- 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.c.Log.Error(err.Error())
- return nil
- }
- if newVersion == "" {
- return nil
- }
- if gui.c.UserConfig.Update.Method == "background" {
- gui.startUpdating(newVersion)
- return nil
- }
- return gui.showUpdatePrompt(newVersion)
-}
-
-func (gui *Gui) startUpdating(newVersion string) {
- gui.State.Updating = true
- statusId := gui.statusManager.addWaitingStatus(gui.Tr.UpdateInProgressWaitingStatus)
- gui.Updater.Update(newVersion, func(err error) error { return gui.onUpdateFinish(statusId, err) })
-}
-
-func (gui *Gui) onUpdateFinish(statusId int, err error) error {
- gui.State.Updating = false
- gui.statusManager.removeStatus(statusId)
- gui.c.OnUIThread(func() error {
- _ = gui.renderString(gui.Views.AppStatus, "")
- if err != nil {
- errMessage := utils.ResolvePlaceholderString(
- gui.Tr.UpdateFailedErr, map[string]string{
- "errMessage": err.Error(),
- },
- )
- return gui.c.ErrorMsg(errMessage)
- }
- return gui.c.Alert(gui.Tr.UpdateCompletedTitle, gui.Tr.UpdateCompleted)
- })
-
- return nil
-}
-
-func (gui *Gui) createUpdateQuitConfirmation() error {
- return gui.c.Confirm(types.ConfirmOpts{
- Title: gui.Tr.ConfirmQuitDuringUpdateTitle,
- Prompt: gui.Tr.ConfirmQuitDuringUpdate,
- HandleConfirm: func() error {
- return gocui.ErrQuit
- },
- })
-}