Skip to content

Commit

Permalink
Show dialogue when attempting to open info link fails (#2899)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield authored Aug 9, 2023
2 parents cdea5b4 + 5477605 commit 4ffb6c0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
22 changes: 20 additions & 2 deletions pkg/gui/information_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/jesseduffield/lazygit/pkg/constants"
"github.com/jesseduffield/lazygit/pkg/gui/style"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/mattn/go-runewidth"
)

Expand Down Expand Up @@ -39,11 +40,28 @@ func (gui *Gui) handleInfoClick() error {
return activeMode.Reset()
}

var title, url string

// if we're not in an active mode we show the donate button
if cx <= runewidth.StringWidth(gui.c.Tr.Donate) {
return gui.os.OpenLink(constants.Links.Donate)
url = constants.Links.Donate
title = gui.c.Tr.Donate
} else if cx <= runewidth.StringWidth(gui.c.Tr.Donate)+1+runewidth.StringWidth(gui.c.Tr.AskQuestion) {
return gui.os.OpenLink(constants.Links.Discussions)
url = constants.Links.Discussions
title = gui.c.Tr.AskQuestion
}
err := gui.os.OpenLink(url)
if err != nil {
// Opening the link via the OS failed for some reason. (For example, this
// can happen if the `os.openLink` config key references a command that
// doesn't exist, or that errors when called.)
//
// In that case, rather than crash the app, fall back to simply showing a
// dialog asking the user to visit the URL.
placeholders := map[string]string{"url": url}
message := utils.ResolvePlaceholderString(gui.c.Tr.PleaseGoToURL, placeholders)
return gui.c.Alert(title, message)
}

return nil
}
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ type TranslationSet struct {
MarkAsBaseCommit string
MarkAsBaseCommitTooltip string
MarkedCommitMarker string
PleaseGoToURL string
Actions Actions
Bisect Bisect
Log Log
Expand Down Expand Up @@ -1347,6 +1348,7 @@ func EnglishTranslationSet() TranslationSet {
MarkAsBaseCommit: "Mark commit as base commit for rebase",
MarkAsBaseCommitTooltip: "Select a base commit for the next rebase; this will effectively perform a 'git rebase --onto'.",
MarkedCommitMarker: "↑↑↑ Will rebase from here ↑↑↑",
PleaseGoToURL: "Please go to {{.url}}",
Actions: Actions{
// TODO: combine this with the original keybinding descriptions (those are all in lowercase atm)
CheckoutCommit: "Checkout commit",
Expand Down
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ var tests = []*components.IntegrationTest{
ui.Accordion,
ui.DoublePopup,
ui.EmptyMenu,
ui.OpenLinkFailure,
ui.SwitchTabFromMenu,
undo.UndoCheckoutAndDrop,
undo.UndoDrop,
Expand Down
24 changes: 24 additions & 0 deletions pkg/integration/tests/ui/open_link_failure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ui

import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var OpenLinkFailure = NewIntegrationTest(NewIntegrationTestArgs{
Description: "When opening links via the OS fails, show a dialog instead.",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.OS.OpenLink = "exit 42"
},
SetupRepo: func(shell *Shell) {},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Information().Click(0, 0)

t.ExpectPopup().Confirmation().
Title(Equals("Donate")).
Content(Equals("Please go to https://github.com/sponsors/jesseduffield")).
Confirm()
},
})

0 comments on commit 4ffb6c0

Please sign in to comment.