Skip to content

Commit

Permalink
Use our new hyperlink support in the information view
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhaller committed Aug 18, 2024
1 parent b15b2a9 commit a464aa9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 29 deletions.
27 changes: 2 additions & 25 deletions pkg/gui/information_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ func (gui *Gui) informationStr() string {
}

if gui.g.Mouse {
donate := style.FgMagenta.SetUnderline().Sprint(gui.c.Tr.Donate)
askQuestion := style.FgYellow.SetUnderline().Sprint(gui.c.Tr.AskQuestion)
donate := style.FgMagenta.Sprint(style.PrintHyperlink(gui.c.Tr.Donate, constants.Links.Donate))
askQuestion := style.FgYellow.Sprint(style.PrintHyperlink(gui.c.Tr.AskQuestion, constants.Links.Discussions))
return fmt.Sprintf("%s %s %s", donate, askQuestion, gui.Config.GetVersion())
} else {
return gui.Config.GetVersion()
Expand All @@ -39,28 +39,5 @@ 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 <= utils.StringWidth(gui.c.Tr.Donate) {
url = constants.Links.Donate
title = gui.c.Tr.Donate
} else if cx <= utils.StringWidth(gui.c.Tr.Donate)+1+utils.StringWidth(gui.c.Tr.AskQuestion) {
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: 0 additions & 2 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,6 @@ type TranslationSet struct {
MarkAsBaseCommitTooltip string
MarkedCommitMarker string
FailedToOpenURL string
PleaseGoToURL string
NoCopiedCommits string
DisabledMenuItemPrefix string
QuickStartInteractiveRebase string
Expand Down Expand Up @@ -1772,7 +1771,6 @@ func EnglishTranslationSet() *TranslationSet {
MarkAsBaseCommitTooltip: "Select a base commit for the next rebase. When you rebase onto a branch, only commits above the base commit will be brought across. This uses the `git rebase --onto` command.",
MarkedCommitMarker: "↑↑↑ Will rebase from here ↑↑↑",
FailedToOpenURL: "Failed to open URL %s\n\nError: %v",
PleaseGoToURL: "Please go to {{.url}}",
DisabledMenuItemPrefix: "Disabled: ",
NoCopiedCommits: "No copied commits",
QuickStartInteractiveRebase: "Start interactive rebase",
Expand Down
4 changes: 2 additions & 2 deletions pkg/integration/tests/ui/open_link_failure.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ var OpenLinkFailure = NewIntegrationTest(NewIntegrationTestArgs{
t.Views().Information().Click(0, 0)

t.ExpectPopup().Confirmation().
Title(Equals("Donate")).
Content(Equals("Please go to https://github.com/sponsors/jesseduffield")).
Title(Equals("Error")).
Content(Equals("Failed to open URL https://github.com/sponsors/jesseduffield\n\nError: exit status 42")).
Confirm()
},
})

0 comments on commit a464aa9

Please sign in to comment.