Improve login view and add .well-known resolution
This commit is contained in:
parent
b6e20af056
commit
8a0a3a6487
4
go.mod
4
go.mod
@ -19,7 +19,7 @@ require (
|
|||||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2
|
golang.org/x/net v0.0.0-20200202094626-16171245cfb2
|
||||||
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2
|
gopkg.in/toast.v1 v1.0.0-20180812000517-0a84660828b2
|
||||||
gopkg.in/yaml.v2 v2.2.8
|
gopkg.in/yaml.v2 v2.2.8
|
||||||
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200218232310-9638cb6d80d2
|
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200219223957-21a588b7e623
|
||||||
maunium.net/go/mauview v0.0.0-20200219201346-81706f13fc83
|
maunium.net/go/mauview v0.0.0-20200219222453-b984e20438e6
|
||||||
maunium.net/go/tcell v1.1.2-0.20200218183045-87c4a25c5b09
|
maunium.net/go/tcell v1.1.2-0.20200218183045-87c4a25c5b09
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
go.sum
@ -76,11 +76,15 @@ maunium.net/go/mautrix v0.1.0-alpha.3.0.20200218231230-3f49fda72ac9 h1:emsSg9ZDi
|
|||||||
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200218231230-3f49fda72ac9/go.mod h1:g10T1fh2Q2HkJWycVs93eBXdWpqD67f1YVQhNxdIDr4=
|
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200218231230-3f49fda72ac9/go.mod h1:g10T1fh2Q2HkJWycVs93eBXdWpqD67f1YVQhNxdIDr4=
|
||||||
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200218232310-9638cb6d80d2 h1:X4ONPO3NyjYqYJZHztKnFB8hgljwvFvVsytbfG9TIpc=
|
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200218232310-9638cb6d80d2 h1:X4ONPO3NyjYqYJZHztKnFB8hgljwvFvVsytbfG9TIpc=
|
||||||
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200218232310-9638cb6d80d2/go.mod h1:g10T1fh2Q2HkJWycVs93eBXdWpqD67f1YVQhNxdIDr4=
|
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200218232310-9638cb6d80d2/go.mod h1:g10T1fh2Q2HkJWycVs93eBXdWpqD67f1YVQhNxdIDr4=
|
||||||
|
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200219223957-21a588b7e623 h1:StXwGEEdQA+aACru6CSPXPafhQqYCc9CnQW4fIwz+KU=
|
||||||
|
maunium.net/go/mautrix v0.1.0-alpha.3.0.20200219223957-21a588b7e623/go.mod h1:g10T1fh2Q2HkJWycVs93eBXdWpqD67f1YVQhNxdIDr4=
|
||||||
maunium.net/go/mauview v0.0.0-20200218183549-88ecb1321176 h1:KoTm7ASEzFIZ1SvPWuWYzpkeA+wiR1fuUu4l7TCHcE0=
|
maunium.net/go/mauview v0.0.0-20200218183549-88ecb1321176 h1:KoTm7ASEzFIZ1SvPWuWYzpkeA+wiR1fuUu4l7TCHcE0=
|
||||||
maunium.net/go/mauview v0.0.0-20200218183549-88ecb1321176/go.mod h1:jwg3Ow7akzsCX3q38pZAfmEC5gGN8gXwMyyjy/yZVMg=
|
maunium.net/go/mauview v0.0.0-20200218183549-88ecb1321176/go.mod h1:jwg3Ow7akzsCX3q38pZAfmEC5gGN8gXwMyyjy/yZVMg=
|
||||||
maunium.net/go/mauview v0.0.0-20200218231215-04d01c601d5b h1:Bfov5IkJQpkqDexiFioHIZpx4XL7AILDA1GwLVdqtBw=
|
maunium.net/go/mauview v0.0.0-20200218231215-04d01c601d5b h1:Bfov5IkJQpkqDexiFioHIZpx4XL7AILDA1GwLVdqtBw=
|
||||||
maunium.net/go/mauview v0.0.0-20200218231215-04d01c601d5b/go.mod h1:jwg3Ow7akzsCX3q38pZAfmEC5gGN8gXwMyyjy/yZVMg=
|
maunium.net/go/mauview v0.0.0-20200218231215-04d01c601d5b/go.mod h1:jwg3Ow7akzsCX3q38pZAfmEC5gGN8gXwMyyjy/yZVMg=
|
||||||
maunium.net/go/mauview v0.0.0-20200219201346-81706f13fc83 h1:KdMJGXJw9Z/uBzg+19hjnfnhzw7mNXl4eCe5Epbx/Dw=
|
maunium.net/go/mauview v0.0.0-20200219201346-81706f13fc83 h1:KdMJGXJw9Z/uBzg+19hjnfnhzw7mNXl4eCe5Epbx/Dw=
|
||||||
maunium.net/go/mauview v0.0.0-20200219201346-81706f13fc83/go.mod h1:jwg3Ow7akzsCX3q38pZAfmEC5gGN8gXwMyyjy/yZVMg=
|
maunium.net/go/mauview v0.0.0-20200219201346-81706f13fc83/go.mod h1:jwg3Ow7akzsCX3q38pZAfmEC5gGN8gXwMyyjy/yZVMg=
|
||||||
|
maunium.net/go/mauview v0.0.0-20200219222453-b984e20438e6 h1:yYs5rsnDQrZie4eeWlcgdw4QSO0eFCiAoA8aiiE+yok=
|
||||||
|
maunium.net/go/mauview v0.0.0-20200219222453-b984e20438e6/go.mod h1:jwg3Ow7akzsCX3q38pZAfmEC5gGN8gXwMyyjy/yZVMg=
|
||||||
maunium.net/go/tcell v1.1.2-0.20200218183045-87c4a25c5b09 h1:hu+R+0nodoZPS19WGyYiw/d63+/NQS/R3Duw3d9HqAU=
|
maunium.net/go/tcell v1.1.2-0.20200218183045-87c4a25c5b09 h1:hu+R+0nodoZPS19WGyYiw/d63+/NQS/R3Duw3d9HqAU=
|
||||||
maunium.net/go/tcell v1.1.2-0.20200218183045-87c4a25c5b09/go.mod h1:Ru7KmI5AU7xHUx6hGltgJvknrS+8jlGGMKK15pZuc9k=
|
maunium.net/go/tcell v1.1.2-0.20200218183045-87c4a25c5b09/go.mod h1:Ru7KmI5AU7xHUx6hGltgJvknrS+8jlGGMKK15pZuc9k=
|
||||||
|
@ -89,7 +89,7 @@ func (log mxLogger) Debugfln(message string, args ...interface{}) {
|
|||||||
// InitClient initializes the mautrix client and connects to the homeserver specified in the config.
|
// InitClient initializes the mautrix client and connects to the homeserver specified in the config.
|
||||||
func (c *Container) InitClient() error {
|
func (c *Container) InitClient() error {
|
||||||
if len(c.config.HS) == 0 {
|
if len(c.config.HS) == 0 {
|
||||||
return fmt.Errorf("no homeserver in config")
|
return fmt.Errorf("no homeserver entered")
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.client != nil {
|
if c.client != nil {
|
||||||
|
@ -74,48 +74,73 @@ func (ui *GomuksUI) NewLoginView() mauview.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hs := ui.gmx.Config().HS
|
hs := ui.gmx.Config().HS
|
||||||
view.homeserver.SetText(hs)
|
view.homeserver.SetPlaceholder("https://example.com").SetText(hs)
|
||||||
view.username.SetText(ui.gmx.Config().UserID)
|
view.username.SetPlaceholder("@user:example.com").SetText(ui.gmx.Config().UserID)
|
||||||
view.password.SetMaskCharacter('*')
|
view.password.SetPlaceholder("correct horse battery staple").SetMaskCharacter('*')
|
||||||
|
|
||||||
view.quitButton.SetOnClick(func() { ui.gmx.Stop(true) }).SetBackgroundColor(tcell.ColorDarkCyan)
|
view.quitButton.SetOnClick(func() { ui.gmx.Stop(true) }).SetBackgroundColor(tcell.ColorDarkCyan)
|
||||||
view.loginButton.SetOnClick(view.Login).SetBackgroundColor(tcell.ColorDarkCyan)
|
view.loginButton.SetOnClick(view.Login).SetBackgroundColor(tcell.ColorDarkCyan)
|
||||||
|
|
||||||
view.SetColumns([]int{1, 10, 1, 9, 1, 9, 1, 10, 1})
|
view.
|
||||||
view.SetRows([]int{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})
|
SetColumns([]int{1, 10, 1, 30, 1}).
|
||||||
view.AddFormItem(view.username, 3, 1, 5, 1).
|
SetRows([]int{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})
|
||||||
AddFormItem(view.password, 3, 3, 5, 1).
|
view.
|
||||||
AddFormItem(view.homeserver, 3, 5, 5, 1).
|
AddFormItem(view.username, 3, 1, 1, 1).
|
||||||
AddFormItem(view.loginButton, 5, 7, 3, 1).
|
AddFormItem(view.password, 3, 3, 1, 1).
|
||||||
AddFormItem(view.quitButton, 1, 7, 3, 1).
|
AddFormItem(view.homeserver, 3, 5, 1, 1).
|
||||||
|
AddFormItem(view.loginButton, 1, 7, 3, 1).
|
||||||
|
AddFormItem(view.quitButton, 1, 9, 3, 1).
|
||||||
AddComponent(view.usernameLabel, 1, 1, 1, 1).
|
AddComponent(view.usernameLabel, 1, 1, 1, 1).
|
||||||
AddComponent(view.passwordLabel, 1, 3, 1, 1).
|
AddComponent(view.passwordLabel, 1, 3, 1, 1).
|
||||||
AddComponent(view.homeserverLabel, 1, 5, 1, 1)
|
AddComponent(view.homeserverLabel, 1, 5, 1, 1)
|
||||||
|
view.SetOnFocusChanged(view.focusChanged)
|
||||||
view.FocusNextItem()
|
view.FocusNextItem()
|
||||||
ui.loginView = view
|
ui.loginView = view
|
||||||
|
|
||||||
view.container = mauview.Center(mauview.NewBox(view).SetTitle("Log in to Matrix"), 45, 11)
|
view.container = mauview.Center(mauview.NewBox(view).SetTitle("Log in to Matrix"), 45, 13)
|
||||||
view.container.SetAlwaysFocusChild(true)
|
view.container.SetAlwaysFocusChild(true)
|
||||||
return view.container
|
return view.container
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (view *LoginView) resolveWellKnown() {
|
||||||
|
_, homeserver, err := mautrix.ParseUserID(view.username.GetText())
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
view.homeserver.SetText("Resolving...")
|
||||||
|
resp, err := mautrix.DiscoverClientAPI(homeserver)
|
||||||
|
if err != nil {
|
||||||
|
view.homeserver.SetText("")
|
||||||
|
view.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
view.homeserver.SetText(resp.Homeserver.BaseURL)
|
||||||
|
view.parent.Render()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (view *LoginView) focusChanged(from, to mauview.Component) {
|
||||||
|
if from == view.username && view.homeserver.GetText() == "" {
|
||||||
|
go view.resolveWellKnown()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (view *LoginView) Error(err string) {
|
func (view *LoginView) Error(err string) {
|
||||||
if len(err) == 0 && view.error != nil {
|
if len(err) == 0 && view.error != nil {
|
||||||
debug.Print("Hiding error")
|
debug.Print("Hiding error")
|
||||||
view.RemoveComponent(view.error)
|
view.RemoveComponent(view.error)
|
||||||
view.container.SetHeight(11)
|
view.container.SetHeight(13)
|
||||||
view.SetRows([]int{1, 1, 1, 1, 1, 1, 1, 1, 1})
|
view.SetRows([]int{1, 1, 1, 1, 1, 1, 1, 1, 1})
|
||||||
view.error = nil
|
view.error = nil
|
||||||
} else if len(err) > 0 {
|
} else if len(err) > 0 {
|
||||||
debug.Print("Showing error", err)
|
debug.Print("Showing error", err)
|
||||||
if view.error == nil {
|
if view.error == nil {
|
||||||
view.error = mauview.NewTextView().SetTextColor(tcell.ColorRed)
|
view.error = mauview.NewTextView().SetTextColor(tcell.ColorRed)
|
||||||
view.AddComponent(view.error, 1, 9, 7, 1)
|
view.AddComponent(view.error, 1, 11, 3, 1)
|
||||||
}
|
}
|
||||||
view.error.SetText(err)
|
view.error.SetText(err)
|
||||||
errorHeight := int(math.Ceil(float64(mauview.StringWidth(err)) / 45))
|
errorHeight := int(math.Ceil(float64(mauview.StringWidth(err)) / 45))
|
||||||
view.container.SetHeight(12 + errorHeight)
|
view.container.SetHeight(14 + errorHeight)
|
||||||
view.SetRow(9, errorHeight)
|
view.SetRow(11, errorHeight)
|
||||||
}
|
}
|
||||||
|
|
||||||
view.parent.Render()
|
view.parent.Render()
|
||||||
@ -124,14 +149,11 @@ func (view *LoginView) Error(err string) {
|
|||||||
func (view *LoginView) actuallyLogin(hs, mxid, password string) {
|
func (view *LoginView) actuallyLogin(hs, mxid, password string) {
|
||||||
debug.Printf("Logging into %s as %s...", hs, mxid)
|
debug.Printf("Logging into %s as %s...", hs, mxid)
|
||||||
view.config.HS = hs
|
view.config.HS = hs
|
||||||
err := view.matrix.InitClient()
|
|
||||||
if err != nil {
|
if err := view.matrix.InitClient(); err != nil {
|
||||||
debug.Print("Init error:", err)
|
debug.Print("Init error:", err)
|
||||||
view.Error(err.Error())
|
view.Error(err.Error())
|
||||||
return
|
} else if err = view.matrix.Login(mxid, password); err != nil {
|
||||||
}
|
|
||||||
err = view.matrix.Login(mxid, password)
|
|
||||||
if err != nil {
|
|
||||||
if httpErr, ok := err.(mautrix.HTTPError); ok {
|
if httpErr, ok := err.(mautrix.HTTPError); ok {
|
||||||
if httpErr.RespError != nil {
|
if httpErr.RespError != nil {
|
||||||
view.Error(httpErr.RespError.Err)
|
view.Error(httpErr.RespError.Err)
|
||||||
|
Loading…
Reference in New Issue
Block a user