From de5bcb8b9c65e63a992ce278e63f0f8e31a57969 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 10 Nov 2019 22:07:45 +1100 Subject: [PATCH] add some shameless self promotion --- pkg/config/app_config.go | 5 +-- pkg/gui/confirmation_panel.go | 2 +- pkg/gui/gui.go | 57 +++++++++++++++++++++++++++-------- pkg/i18n/english.go | 13 ++++++++ 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 50690c8c5..d0294de01 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -37,7 +37,7 @@ type AppConfigurer interface { GetUserConfig() *viper.Viper GetUserConfigDir() string GetAppState() *AppState - WriteToUserConfig(string, string) error + WriteToUserConfig(string, interface{}) error SaveAppState() error LoadAppState() error SetIsNewRepo(bool) @@ -192,7 +192,7 @@ func LoadAndMergeFile(v *viper.Viper, filename string) (string, error) { } // WriteToUserConfig adds a key/value pair to the user's config and saves it -func (c *AppConfig) WriteToUserConfig(key, value string) error { +func (c *AppConfig) WriteToUserConfig(key string, value interface{}) error { // reloading the user config directly (without defaults) so that we're not // writing any defaults back to the user's config v, _, err := LoadConfig("config", false) @@ -263,6 +263,7 @@ update: method: prompt # can be: prompt | background | never days: 14 # how often a update is checked for reporting: 'undetermined' # one of: 'on' | 'off' | 'undetermined' +splashUpdatesIndex: 0 confirmOnQuit: false `) } diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index d0516f2e8..6913400a1 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -56,7 +56,7 @@ func (gui *Gui) getMessageHeight(wrap bool, message string, width int) int { func (gui *Gui) getConfirmationPanelDimensions(g *gocui.Gui, wrap bool, prompt string) (int, int, int, int) { width, height := g.Size() - panelWidth := width / 2 + panelWidth := 4 * width / 7 panelHeight := gui.getMessageHeight(wrap, prompt, panelWidth) return width/2 - panelWidth/2, height/2 - panelHeight/2 - panelHeight%2 - 1, diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index b75d73e87..b65f01747 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -30,6 +30,8 @@ import ( "github.com/sirupsen/logrus" ) +const StartupPopupVersion = 1 + // OverlappingEdges determines if panel edges overlap var OverlappingEdges = false @@ -618,20 +620,42 @@ func (gui *Gui) loadNewRepo() error { return err } - if gui.Config.GetUserConfig().GetString("reporting") == "undetermined" { - if err := gui.promptAnonymousReporting(); err != nil { - return err - } - } return nil } -func (gui *Gui) promptAnonymousReporting() error { +func (gui *Gui) showInitialPopups(tasks []func(chan struct{}) error) { + gui.waitForIntro.Add(len(tasks)) + done := make(chan struct{}) + + go func() { + for _, task := range tasks { + go func() { + if err := task(done); err != nil { + _ = gui.createErrorPanel(gui.g, err.Error()) + } + }() + + <-done + gui.waitForIntro.Done() + } + }() +} + +func (gui *Gui) showShamelessSelfPromotionMessage(done chan struct{}) error { + onConfirm := func(g *gocui.Gui, v *gocui.View) error { + done <- struct{}{} + return gui.Config.WriteToUserConfig("startupPopupVersion", StartupPopupVersion) + } + + return gui.createConfirmationPanel(gui.g, nil, true, gui.Tr.SLocalize("ShamelessSelfPromotionTitle"), gui.Tr.SLocalize("ShamelessSelfPromotionMessage"), onConfirm, onConfirm) +} + +func (gui *Gui) promptAnonymousReporting(done chan struct{}) error { return gui.createConfirmationPanel(gui.g, nil, true, gui.Tr.SLocalize("AnonymousReportingTitle"), gui.Tr.SLocalize("AnonymousReportingPrompt"), func(g *gocui.Gui, v *gocui.View) error { - gui.waitForIntro.Done() + done <- struct{}{} return gui.Config.WriteToUserConfig("reporting", "on") }, func(g *gocui.Gui, v *gocui.View) error { - gui.waitForIntro.Done() + done <- struct{}{} return gui.Config.WriteToUserConfig("reporting", "off") }) } @@ -717,15 +741,22 @@ func (gui *Gui) Run() error { return err } + popupTasks := []func(chan struct{}) error{} if gui.Config.GetUserConfig().GetString("reporting") == "undetermined" { - gui.waitForIntro.Add(2) - } else { - gui.waitForIntro.Add(1) + popupTasks = append(popupTasks, gui.promptAnonymousReporting) } + configPopupVersion := gui.Config.GetUserConfig().GetInt("StartupPopupVersion") + // -1 means we've disabled these popups + if configPopupVersion != -1 && configPopupVersion < StartupPopupVersion { + popupTasks = append(popupTasks, gui.showShamelessSelfPromotionMessage) + } + gui.showInitialPopups(popupTasks) + gui.waitForIntro.Add(1) if gui.Config.GetUserConfig().GetBool("git.autoFetch") { go gui.startBackgroundFetch() } + gui.goEvery(time.Second*10, gui.refreshFiles) gui.goEvery(time.Millisecond*50, gui.renderAppStatus) @@ -735,6 +766,8 @@ func (gui *Gui) Run() error { return err } + gui.Log.Warn("starting main loop") + err = g.MainLoop() return err } @@ -806,7 +839,7 @@ func (gui *Gui) handleDonate(g *gocui.Gui, v *gocui.View) error { if cx > len(gui.Tr.SLocalize("Donate")) { return nil } - return gui.OSCommand.OpenLink("https://donorbox.org/lazygit") + return gui.OSCommand.OpenLink("https://github.com/sponsors/jesseduffield") } // setColorScheme sets the color scheme for the app based on the user config diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 3d19c0e8a..96880cc7d 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -438,6 +438,19 @@ func addEnglish(i18nObject *i18n.Bundle) error { }, &i18n.Message{ ID: "AnonymousReportingPrompt", Other: "Would you like to enable anonymous reporting data to help improve lazygit? (enter/esc)", + }, &i18n.Message{ + ID: "ShamelessSelfPromotionTitle", + Other: "Shameless Self Promotion", + }, &i18n.Message{ + ID: "ShamelessSelfPromotionMessage", + Other: `Thanks for using lazygit! Three things to share with you: + +1) lazygit now has basic mouse support! + +2) If you want to learn about lazygit's features, watch this vid: + https://youtu.be/CPLdltN7wgE + +3) Github are now matching any donations dollar-for-dollar for the next 12 months, so if you've been tossing up over whether to click the donate link in the bottom right corner, now is the time!`, }, &i18n.Message{ ID: "GitconfigParseErr", Other: `Gogit failed to parse your gitconfig file due to the presence of unquoted '\' characters. Removing these should fix the issue.`,