From 1d032875b73f5c368b5f1ac2f43813ee5eba3f79 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Mon, 12 Oct 2020 11:27:31 -0700 Subject: [PATCH] Move loading of the GitHub user into startup 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 --- app/exit_message.go | 7 +------ app/wtf_app.go | 11 ++++++++++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/app/exit_message.go b/app/exit_message.go index 4a26c002..6db7df57 100644 --- a/app/exit_message.go +++ b/app/exit_message.go @@ -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 "" diff --git a/app/wtf_app.go b/app/wtf_app.go index 9ff8e910..b6c799f2 100644 --- a/app/wtf_app.go +++ b/app/wtf_app.go @@ -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