1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-21 12:16:54 +02:00

Wait for intro before doing any of our refresh functions

We were doing this already for fetching but not for refreshing files so I'm making it consistent.
This commit is contained in:
Jesse Duffield 2023-07-08 15:23:15 +10:00
parent 015a04fac6
commit b19943af01
2 changed files with 16 additions and 9 deletions

View File

@ -15,11 +15,11 @@ type BackgroundRoutineMgr struct {
// if we've suspended the gui (e.g. because we've switched to a subprocess) // if we've suspended the gui (e.g. because we've switched to a subprocess)
// we typically want to pause some things that are running like background // we typically want to pause some things that are running like background
// file refreshes // file refreshes
pauseBackgroundThreads bool pauseBackgroundRefreshes bool
} }
func (self *BackgroundRoutineMgr) PauseBackgroundThreads(pause bool) { func (self *BackgroundRoutineMgr) PauseBackgroundRefreshes(pause bool) {
self.pauseBackgroundThreads = pause self.pauseBackgroundRefreshes = pause
} }
func (self *BackgroundRoutineMgr) startBackgroundRoutines() { func (self *BackgroundRoutineMgr) startBackgroundRoutines() {
@ -39,9 +39,7 @@ func (self *BackgroundRoutineMgr) startBackgroundRoutines() {
if userConfig.Git.AutoRefresh { if userConfig.Git.AutoRefresh {
refreshInterval := userConfig.Refresher.RefreshInterval refreshInterval := userConfig.Refresher.RefreshInterval
if refreshInterval > 0 { if refreshInterval > 0 {
self.goEvery(time.Second*time.Duration(refreshInterval), self.gui.stopChan, func() error { go utils.Safe(func() { self.startBackgroundFilesRefresh(refreshInterval) })
return self.gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
})
} else { } else {
self.gui.c.Log.Errorf( self.gui.c.Log.Errorf(
"Value of config option 'refresher.refreshInterval' (%d) is invalid, disabling auto-refresh", "Value of config option 'refresher.refreshInterval' (%d) is invalid, disabling auto-refresh",
@ -52,6 +50,7 @@ func (self *BackgroundRoutineMgr) startBackgroundRoutines() {
func (self *BackgroundRoutineMgr) startBackgroundFetch() { func (self *BackgroundRoutineMgr) startBackgroundFetch() {
self.gui.waitForIntro.Wait() self.gui.waitForIntro.Wait()
isNew := self.gui.IsNewRepo isNew := self.gui.IsNewRepo
userConfig := self.gui.UserConfig userConfig := self.gui.UserConfig
if !isNew { if !isNew {
@ -69,6 +68,14 @@ func (self *BackgroundRoutineMgr) startBackgroundFetch() {
} }
} }
func (self *BackgroundRoutineMgr) startBackgroundFilesRefresh(refreshInterval int) {
self.gui.waitForIntro.Wait()
self.goEvery(time.Second*time.Duration(refreshInterval), self.gui.stopChan, func() error {
return self.gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
})
}
func (self *BackgroundRoutineMgr) goEvery(interval time.Duration, stop chan struct{}, function func() error) { func (self *BackgroundRoutineMgr) goEvery(interval time.Duration, stop chan struct{}, function func() error) {
go utils.Safe(func() { go utils.Safe(func() {
ticker := time.NewTicker(interval) ticker := time.NewTicker(interval)
@ -76,7 +83,7 @@ func (self *BackgroundRoutineMgr) goEvery(interval time.Duration, stop chan stru
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
if self.pauseBackgroundThreads { if self.pauseBackgroundRefreshes {
continue continue
} }
self.gui.c.OnWorker(func() { _ = function() }) self.gui.c.OnWorker(func() { _ = function() })

View File

@ -722,8 +722,8 @@ func (gui *Gui) runSubprocessWithSuspense(subprocess oscommands.ICmdObj) (bool,
return false, gui.c.Error(err) return false, gui.c.Error(err)
} }
gui.BackgroundRoutineMgr.PauseBackgroundThreads(true) gui.BackgroundRoutineMgr.PauseBackgroundRefreshes(true)
defer gui.BackgroundRoutineMgr.PauseBackgroundThreads(false) defer gui.BackgroundRoutineMgr.PauseBackgroundRefreshes(false)
cmdErr := gui.runSubprocess(subprocess) cmdErr := gui.runSubprocess(subprocess)