summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormatejcik <ja@matejcik.cz>2019-07-19 13:56:53 +0200
committerJesse Duffield <jessedduffield@gmail.com>2019-09-08 11:20:15 +1000
commit8f786e3fd98bc410f1879c44f93dc01a99d5f582 (patch)
tree57d7c28328d21a45c154be46890df14dc4df2823
parent1c704e11f22371d70ad88dbf8934d3fe742c305c (diff)
configurable auto-fetch
-rw-r--r--pkg/config/app_config.go1
-rw-r--r--pkg/gui/gui.go38
2 files changed, 23 insertions, 16 deletions
diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go
index d5a880b72..4116bf501 100644
--- a/pkg/config/app_config.go
+++ b/pkg/config/app_config.go
@@ -249,6 +249,7 @@ func GetDefaultConfig() []byte {
merging:
manualCommit: false
skipHookPrefix: 'WIP'
+ autoFetch: true
update:
method: prompt # can be: prompt | background | never
days: 14 # how often a update is checked for
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index ce339e61f..50ca1abea 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -619,6 +619,25 @@ func (gui *Gui) goEvery(interval time.Duration, function func() error) {
}()
}
+func (gui *Gui) startBackgroundFetch() error {
+ g := gui.g
+ gui.waitForIntro.Wait()
+ isNew := gui.Config.GetIsNewRepo()
+ if !isNew {
+ time.After(60 * time.Second)
+ }
+ _, err := gui.fetch(g, g.CurrentView(), false)
+ if err != nil && strings.Contains(err.Error(), "exit status 128") && isNew {
+ _ = gui.createConfirmationPanel(g, g.CurrentView(), gui.Tr.SLocalize("NoAutomaticGitFetchTitle"), gui.Tr.SLocalize("NoAutomaticGitFetchBody"), nil, nil)
+ } else {
+ gui.goEvery(time.Second*60, func() error {
+ _, err := gui.fetch(gui.g, gui.g.CurrentView(), false)
+ return err
+ })
+ }
+ return nil
+}
+
// Run setup the gui with keybindings and start the mainloop
func (gui *Gui) Run() error {
g, err := gocui.NewGui(gocui.OutputNormal, OverlappingEdges)
@@ -643,22 +662,9 @@ func (gui *Gui) Run() error {
gui.waitForIntro.Add(1)
}
- go func() {
- gui.waitForIntro.Wait()
- isNew := gui.Config.GetIsNewRepo()
- if !isNew {
- time.After(60 * time.Second)
- }
- _, err := gui.fetch(g, g.CurrentView(), false)
- if err != nil && strings.Contains(err.Error(), "exit status 128") && isNew {
- _ = gui.createConfirmationPanel(g, g.CurrentView(), gui.Tr.SLocalize("NoAutomaticGitFetchTitle"), gui.Tr.SLocalize("NoAutomaticGitFetchBody"), nil, nil)
- } else {
- gui.goEvery(time.Second*60, func() error {
- _, err := gui.fetch(gui.g, gui.g.CurrentView(), false)
- return err
- })
- }
- }()
+ if gui.Config.GetUserConfig().GetBool("gui.git.autoFetch") {
+ go gui.startBackgroundFetch()
+ }
gui.goEvery(time.Second*10, gui.refreshFiles)
gui.goEvery(time.Millisecond*50, gui.renderAppStatus)