diff options
author | matejcik <ja@matejcik.cz> | 2019-07-19 13:56:53 +0200 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2019-09-08 11:20:15 +1000 |
commit | 8f786e3fd98bc410f1879c44f93dc01a99d5f582 (patch) | |
tree | 57d7c28328d21a45c154be46890df14dc4df2823 /pkg/gui | |
parent | 1c704e11f22371d70ad88dbf8934d3fe742c305c (diff) |
configurable auto-fetch
Diffstat (limited to 'pkg/gui')
-rw-r--r-- | pkg/gui/gui.go | 38 |
1 files changed, 22 insertions, 16 deletions
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) |