1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package gui
import (
"fmt"
"github.com/jesseduffield/gocui"
)
func (gui *Gui) showUpdatePrompt(newVersion string) error {
return gui.ask(askOpts{
title: "New version available!",
prompt: fmt.Sprintf("Download version %s? (enter/esc)", newVersion),
handleConfirm: func() error {
gui.startUpdating(newVersion)
return nil
},
})
}
func (gui *Gui) onUserUpdateCheckFinish(newVersion string, err error) error {
if err != nil {
return gui.surfaceError(err)
}
if newVersion == "" {
return gui.createErrorPanel("New version not found")
}
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.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("updating")
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.renderString(gui.Views.AppStatus, "")
if err != nil {
return gui.createErrorPanel("Update failed: " + err.Error())
}
return nil
}
func (gui *Gui) createUpdateQuitConfirmation() error {
return gui.ask(askOpts{
title: "Currently Updating",
prompt: "An update is in progress. Are you sure you want to quit?",
handleConfirm: func() error {
return gocui.ErrQuit
},
})
}
|