From f4bc37b6db5d10e0ee2debfbb187b73691cb09f9 Mon Sep 17 00:00:00 2001 From: sewn Date: Sat, 13 Jul 2024 22:49:30 +0300 Subject: [PATCH] splash(dialog): support 'more info' xdg-open button --- splash/dialog.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/splash/dialog.go b/splash/dialog.go index da5b9bf..5610afa 100644 --- a/splash/dialog.go +++ b/splash/dialog.go @@ -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 { @@ -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) { @@ -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{ @@ -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 { @@ -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) + }), ) }), )