mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
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 <chriscummer@me.com>
This commit is contained in:
parent
1afaa2ba45
commit
1d032875b7
@ -23,19 +23,14 @@ const exitMessageHeader = `
|
|||||||
|
|
||||||
// DisplayExitMessage displays the onscreen exit message when the app quits
|
// DisplayExitMessage displays the onscreen exit message when the app quits
|
||||||
func (wtfApp *WtfApp) DisplayExitMessage() {
|
func (wtfApp *WtfApp) DisplayExitMessage() {
|
||||||
githubAPIKey := readGitHubAPIKey(wtfApp.config)
|
|
||||||
ghUser := support.NewGitHubUser(githubAPIKey)
|
|
||||||
|
|
||||||
exitMessageIsDisplayable := readDisplayableConfig(wtfApp.config)
|
exitMessageIsDisplayable := readDisplayableConfig(wtfApp.config)
|
||||||
|
|
||||||
wtfApp.displayExitMsg(ghUser, exitMessageIsDisplayable)
|
wtfApp.displayExitMsg(wtfApp.ghUser, exitMessageIsDisplayable)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (wtfApp *WtfApp) displayExitMsg(ghUser *support.GitHubUser, exitMessageIsDisplayable bool) string {
|
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 a sponsor or contributor and opt out of seeing the exit message, do not display it
|
||||||
if (ghUser.IsContributor || ghUser.IsSponsor) && !exitMessageIsDisplayable {
|
if (ghUser.IsContributor || ghUser.IsSponsor) && !exitMessageIsDisplayable {
|
||||||
return ""
|
return ""
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/radovskyb/watcher"
|
"github.com/radovskyb/watcher"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/cfg"
|
"github.com/wtfutil/wtf/cfg"
|
||||||
|
"github.com/wtfutil/wtf/support"
|
||||||
"github.com/wtfutil/wtf/utils"
|
"github.com/wtfutil/wtf/utils"
|
||||||
"github.com/wtfutil/wtf/wtf"
|
"github.com/wtfutil/wtf/wtf"
|
||||||
)
|
)
|
||||||
@ -21,6 +22,7 @@ type WtfApp struct {
|
|||||||
config *config.Config
|
config *config.Config
|
||||||
configFilePath string
|
configFilePath string
|
||||||
display *Display
|
display *Display
|
||||||
|
ghUser *support.GitHubUser
|
||||||
focusTracker FocusTracker
|
focusTracker FocusTracker
|
||||||
pages *tview.Pages
|
pages *tview.Pages
|
||||||
validator *ModuleValidator
|
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.widgets = MakeWidgets(wtfApp.app, wtfApp.pages, wtfApp.config)
|
||||||
wtfApp.display = NewDisplay(wtfApp.widgets, wtfApp.config)
|
wtfApp.display = NewDisplay(wtfApp.widgets, wtfApp.config)
|
||||||
wtfApp.focusTracker = NewFocusTracker(wtfApp.app, 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.validator = NewModuleValidator()
|
||||||
|
|
||||||
wtfApp.pages.AddPage("grid", wtfApp.display.Grid, true, true)
|
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
|
// Start initializes the app
|
||||||
func (wtfApp *WtfApp) Start() {
|
func (wtfApp *WtfApp) Start() {
|
||||||
wtfApp.scheduleWidgets()
|
go wtfApp.scheduleWidgets()
|
||||||
|
|
||||||
go wtfApp.watchForConfigChanges()
|
go wtfApp.watchForConfigChanges()
|
||||||
|
|
||||||
|
go func() { _ = wtfApp.ghUser.Load() }()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop kills all the currently-running widgets in this app
|
// Stop kills all the currently-running widgets in this app
|
||||||
|
Loading…
x
Reference in New Issue
Block a user