-
Notifications
You must be signed in to change notification settings - Fork 7
/
step2.go
82 lines (67 loc) · 1.77 KB
/
step2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package auth
import (
"context"
"github.com/diamondburned/gotk4/pkg/core/glib"
"github.com/diamondburned/gotk4/pkg/gtk/v4"
"github.com/diamondburned/gotkit/app"
"github.com/diamondburned/gotkit/gtkutil/cssutil"
"github.com/diamondburned/gotkit/gtkutil/textutil"
"github.com/diamondburned/gotktrix/internal/components/assistant"
"github.com/diamondburned/gotktrix/internal/gotktrix"
"github.com/pkg/errors"
)
var homeserverStepCSS = cssutil.Applier("auth-homeserver-step", ``)
func homeserverStep(a *Assistant) *assistant.Step {
inputBox, inputs := a.makeInputs("Homeserver")
inputs[0].SetText("matrix.org")
errLabel := makeErrorLabel()
errLabel.Hide()
step := assistant.NewStep("Homeserver", "Connect")
step.CanBack = true
content := step.ContentArea()
content.SetOrientation(gtk.OrientationVertical)
content.Append(inputBox)
content.Append(errLabel)
homeserverStepCSS(content)
step.Done = func(step *assistant.Step) {
ctx := a.CancellableBusy(a.ctx)
go func() {
onErr := func(err error) {
glib.IdleAdd(func() {
errLabel.SetMarkup(textutil.ErrorMarkup(err.Error()))
errLabel.Show()
a.Continue()
})
}
c, err := gotktrix.Discover(inputs[0].Text(), gotktrix.Opts{
Client: a.client.WithContext(ctx),
ConfigPath: app.FromContext(ctx),
})
if err != nil {
onErr(err)
return
}
methods, err := c.LoginMethods()
if err != nil {
onErr(err)
return
}
var pass bool
for _, method := range methods {
if supportedLoginMethods[method] {
pass = true
break
}
}
if !pass {
onErr(errors.New("no supported login methods found"))
return
}
glib.IdleAdd(func() {
c := c.WithContext(context.Background())
a.chooseHomeserver(c, methods)
})
}()
}
return step
}