Skip to content

Commit

Permalink
splash(dialog): support 'more info' xdg-open button
Browse files Browse the repository at this point in the history
  • Loading branch information
apprehensions committed Jul 13, 2024
1 parent 04aedc7 commit f4bc37b
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions splash/dialog.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
//
// The dialog window size will automatically resize itself vertically
// according to how many lines the text takes.
func (ui *Splash) Dialog(txt string, user bool) (r bool) {
func (ui *Splash) Dialog(txt string, user bool, xdg string) (r bool) {
var ops op.Ops

if !ui.Config.Enabled {
Expand Down Expand Up @@ -65,6 +65,7 @@ func (ui *Splash) Dialog(txt string, user bool) (r bool) {

var yesButton widget.Clickable // Okay if !user
var noButton widget.Clickable
var xdgButton widget.Clickable

for {
switch e := w.Event().(type) {
Expand All @@ -81,6 +82,11 @@ func (ui *Splash) Dialog(txt string, user bool) (r bool) {
if noButton.Clicked(gtx) {
w.Perform(system.ActionClose)
}
if xdgButton.Clicked(gtx) {
if err := XDGOpen(xdg).Start(); err != nil {
log.Printf("Dialog: xdg-open: %s", err)
}
}

layout.UniformInset(18).Layout(gtx, func(gtx C) D {
return layout.Flex{
Expand All @@ -104,7 +110,13 @@ func (ui *Splash) Dialog(txt string, user bool) (r bool) {
}.Layout(gtx,
layout.Rigid(func(gtx C) D {
if !user {
return button(th, &yesButton, "Okay").Layout(gtx)
r := unit.Dp(16)
if xdg == "" {
r = 0
}
return layout.Inset{Right: r}.Layout(gtx, func(gtx C) D {
return button(th, &yesButton, "Okay").Layout(gtx)
})
}

return layout.Inset{Right: unit.Dp(16)}.Layout(gtx, func(gtx C) D {
Expand All @@ -120,6 +132,13 @@ func (ui *Splash) Dialog(txt string, user bool) (r bool) {
btn.Background = rgb(ui.Config.CancelColor)
return btn.Layout(gtx)
}),
layout.Rigid(func(gtx C) D {
if user || xdg == "" {
return D{}
}

return button(th, &xdgButton, "More Info").Layout(gtx)
}),
)
}),
)
Expand Down

0 comments on commit f4bc37b

Please sign in to comment.