package ui import ( "gioui.org/layout" "gioui.org/unit" "gioui.org/widget" "gioui.org/widget/material" "git.wxccs.org/iceking2nd/winauth-go/internal/authenticator" "git.wxccs.org/iceking2nd/winauth-go/internal/i18n" "git.wxccs.org/iceking2nd/winauth-go/internal/win32" ) // bnetInfoDialog shows the Battle.Net serial number and restore code. // The restore code can be copied to the clipboard. type bnetInfoDialog struct { serial string restoreCode string copyBtn widget.Clickable closeBtn widget.Clickable copied bool } func newBnetInfoDialog(bn *authenticator.BattleNetAuthenticator) *bnetInfoDialog { return &bnetInfoDialog{ serial: bn.Serial, restoreCode: bn.RestoreCode(), } } func (d *bnetInfoDialog) Layout( gtx layout.Context, th *material.Theme, onClose func(), ) layout.Dimensions { if d.closeBtn.Clicked(gtx) { onClose() return layout.Dimensions{Size: gtx.Constraints.Max} } if d.copyBtn.Clicked(gtx) { if err := win32.SetClipboardText(d.restoreCode); err == nil { d.copied = true } } body := func(gtx layout.Context) layout.Dimensions { return layout.Flex{Axis: layout.Vertical}.Layout(gtx, layout.Rigid(material.Body2(th, i18n.T("bnet_info_intro")).Layout), layout.Rigid(layout.Spacer{Height: unit.Dp(12)}.Layout), layout.Rigid(func(gtx layout.Context) layout.Dimensions { return layout.Flex{Axis: layout.Horizontal}.Layout(gtx, layout.Rigid(material.Body2(th, i18n.T("label_serial")+": ").Layout), layout.Rigid(material.Body1(th, d.serial).Layout), ) }), layout.Rigid(layout.Spacer{Height: unit.Dp(8)}.Layout), layout.Rigid(func(gtx layout.Context) layout.Dimensions { return layout.Flex{Axis: layout.Horizontal}.Layout(gtx, layout.Rigid(material.Body2(th, i18n.T("label_restore_code")+": ").Layout), layout.Rigid(material.Body1(th, d.restoreCode).Layout), ) }), layout.Rigid(layout.Spacer{Height: unit.Dp(8)}.Layout), layout.Rigid(func(gtx layout.Context) layout.Dimensions { copyLabel := i18n.T("btn_copy") if d.copied { copyLabel = i18n.T("msg_copied") } return material.Button(th, &d.copyBtn, copyLabel).Layout(gtx) }), layout.Rigid(layout.Spacer{Height: unit.Dp(4)}.Layout), layout.Rigid(material.Caption(th, i18n.T("hint_bnet_restore_code_secret")).Layout), ) } return modalCardCancel(gtx, th, i18n.T("dialog_bnet_info_title"), i18n.T("btn_close"), &d.closeBtn, body) }