| 27 | } |
| 28 | |
| 29 | func (self *BackgroundRoutineMgr) startBackgroundRoutines() { |
| 30 | userConfig := self.gui.UserConfig() |
| 31 | |
| 32 | if userConfig.Git.AutoFetch { |
| 33 | fetchInterval := userConfig.Refresher.FetchInterval |
| 34 | if fetchInterval > 0 { |
| 35 | go utils.Safe(self.startBackgroundFetch) |
| 36 | } else { |
| 37 | self.gui.c.Log.Errorf( |
| 38 | "Value of config option 'refresher.fetchInterval' (%d) is invalid, disabling auto-fetch", |
| 39 | fetchInterval) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | if userConfig.Git.AutoRefresh { |
| 44 | refreshInterval := userConfig.Refresher.RefreshInterval |
| 45 | if refreshInterval > 0 { |
| 46 | go utils.Safe(self.startBackgroundFilesRefresh) |
| 47 | } else { |
| 48 | self.gui.c.Log.Errorf( |
| 49 | "Value of config option 'refresher.refreshInterval' (%d) is invalid, disabling auto-refresh", |
| 50 | refreshInterval) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | if self.gui.Config.GetDebug() { |
| 55 | self.goEvery(time.Second*time.Duration(10), self.gui.stopChan, func(_ bool) error { |
| 56 | formatBytes := func(b uint64) string { |
| 57 | const unit = 1000 |
| 58 | if b < unit { |
| 59 | return fmt.Sprintf("%d B", b) |
| 60 | } |
| 61 | div, exp := uint64(unit), 0 |
| 62 | for n := b / unit; n >= unit; n /= unit { |
| 63 | div *= unit |
| 64 | exp++ |
| 65 | } |
| 66 | return fmt.Sprintf("%.1f %cB", |
| 67 | float64(b)/float64(div), "kMGTPE"[exp]) |
| 68 | } |
| 69 | |
| 70 | m := runtime.MemStats{} |
| 71 | runtime.ReadMemStats(&m) |
| 72 | self.gui.c.Log.Infof("Heap memory in use: %s", formatBytes(m.HeapAlloc)) |
| 73 | return nil |
| 74 | }) |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | func (self *BackgroundRoutineMgr) startBackgroundFetch() { |
| 79 | self.gui.waitForIntro.Wait() |