1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Move loading of the GitHub user into startup (#999)

Having the calls on exit delayed the exiting of the app
by a second or more, which was noticable and annoying.

This change loads the GitHub user data asynchronously while the
app is running, removing the delay on exit.

Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
Chris Cummer 2020-10-12 12:23:39 -07:00 committed by GitHub
parent 1afaa2ba45
commit 35499987ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 7 deletions

View File

@ -23,19 +23,14 @@ const exitMessageHeader = `
// DisplayExitMessage displays the onscreen exit message when the app quits
func (wtfApp *WtfApp) DisplayExitMessage() {
githubAPIKey := readGitHubAPIKey(wtfApp.config)
ghUser := support.NewGitHubUser(githubAPIKey)
exitMessageIsDisplayable := readDisplayableConfig(wtfApp.config)
wtfApp.displayExitMsg(ghUser, exitMessageIsDisplayable)
wtfApp.displayExitMsg(wtfApp.ghUser, exitMessageIsDisplayable)
}
/* -------------------- Unexported Functions -------------------- */
func (wtfApp *WtfApp) displayExitMsg(ghUser *support.GitHubUser, exitMessageIsDisplayable bool) string {
_ = ghUser.Load()
// If a sponsor or contributor and opt out of seeing the exit message, do not display it
if (ghUser.IsContributor || ghUser.IsSponsor) && !exitMessageIsDisplayable {
return ""

View File

@ -10,6 +10,7 @@ import (
"github.com/radovskyb/watcher"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/support"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/wtf"
)
@ -21,6 +22,7 @@ type WtfApp struct {
config *config.Config
configFilePath string
display *Display
ghUser *support.GitHubUser
focusTracker FocusTracker
pages *tview.Pages
validator *ModuleValidator
@ -46,6 +48,10 @@ func NewWtfApp(app *tview.Application, config *config.Config, configFilePath str
wtfApp.widgets = MakeWidgets(wtfApp.app, wtfApp.pages, wtfApp.config)
wtfApp.display = NewDisplay(wtfApp.widgets, wtfApp.config)
wtfApp.focusTracker = NewFocusTracker(wtfApp.app, wtfApp.widgets, wtfApp.config)
githubAPIKey := readGitHubAPIKey(wtfApp.config)
wtfApp.ghUser = support.NewGitHubUser(githubAPIKey)
wtfApp.validator = NewModuleValidator()
wtfApp.pages.AddPage("grid", wtfApp.display.Grid, true, true)
@ -67,8 +73,11 @@ func NewWtfApp(app *tview.Application, config *config.Config, configFilePath str
// Start initializes the app
func (wtfApp *WtfApp) Start() {
wtfApp.scheduleWidgets()
go wtfApp.scheduleWidgets()
go wtfApp.watchForConfigChanges()
go func() { _ = wtfApp.ghUser.Load() }()
}
// Stop kills all the currently-running widgets in this app