summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-07-08 15:23:15 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-07-08 22:54:52 +1000
commitb19943af01c4f3f1bc7d358194e4c5b99f5b997b (patch)
tree3191cfd86c9ac02849ba590c1bf367eccc9ccb26
parent015a04fac6df267f0ba3a1abb1df35f5e18afec7 (diff)
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.
-rw-r--r--pkg/gui/background.go21
-rw-r--r--pkg/gui/gui.go4
2 files changed, 16 insertions, 9 deletions
diff --git a/pkg/gui/background.go b/pkg/gui/background.go
index 218bd8ce7..d789f1790 100644
--- a/pkg/gui/background.go
+++ b/pkg/gui/background.go
@@ -15,11 +15,11 @@ type BackgroundRoutineMgr struct {
// 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
// file refreshes
- pauseBackgroundThreads bool
+ pauseBackgroundRefreshes bool
}
-func (self *BackgroundRoutineMgr) PauseBackgroundThreads(pause bool) {
- self.pauseBackgroundThreads = pause
+func (self *BackgroundRoutineMgr) PauseBackgroundRefreshes(pause bool) {
+ self.pauseBackgroundRefreshes = pause
}
func (self *BackgroundRoutineMgr) startBackgroundRoutines() {
@@ -39,9 +39,7 @@ func (self *BackgroundRoutineMgr) startBackgroundRoutines() {
if userConfig.Git.AutoRefresh {
refreshInterval := userConfig.Refresher.RefreshInterval
if refreshInterval > 0 {
- self.goEvery(time.Second*time.Duration(refreshInterval), self.gui.stopChan, func() error {
- return self.gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES}})
- })
+ go utils.Safe(func() { self.startBackgroundFilesRefresh(refreshInterval) })
} else {
self.gui.c.Log.Errorf(
"Value of config option 'refresher.refreshInterval' (%d) is invalid, disabling auto-refresh",
@@ -52,6 +50,7 @@ func (self *BackgroundRoutineMgr) startBackgroundRoutines() {
func (self *BackgroundRoutineMgr) startBackgroundFetch() {
self.gui.waitForIntro.Wait()
+
isNew := self.gui.IsNewRepo
userConfig := self.gui.UserConfig
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) {
go utils.Safe(func() {
ticker := time.NewTicker(interval)
@@ -76,7 +83,7 @@ func (self *BackgroundRoutineMgr) goEvery(interval time.Duration, stop chan stru
for {
select {
case <-ticker.C:
- if self.pauseBackgroundThreads {
+ if self.pauseBackgroundRefreshes {
continue
}
self.gui.c.OnWorker(func() { _ = function() })
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index 5bba6b967..5f5955e5a 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -722,8 +722,8 @@ func (gui *Gui) runSubprocessWithSuspense(subprocess oscommands.ICmdObj) (bool,
return false, gui.c.Error(err)
}
- gui.BackgroundRoutineMgr.PauseBackgroundThreads(true)
- defer gui.BackgroundRoutineMgr.PauseBackgroundThreads(false)
+ gui.BackgroundRoutineMgr.PauseBackgroundRefreshes(true)
+ defer gui.BackgroundRoutineMgr.PauseBackgroundRefreshes(false)
cmdErr := gui.runSubprocess(subprocess)