forked from sunglocto/lambda
add login flow and put config in configdir
This commit is contained in:
102
main.go
102
main.go
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"os"
|
||||
"sync"
|
||||
"bytes"
|
||||
|
||||
"context"
|
||||
"fmt"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"github.com/diamondburned/gotk4/pkg/glib/v2"
|
||||
"github.com/diamondburned/gotk4/pkg/gtk/v4"
|
||||
"github.com/kr/pretty"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"gosrc.io/xmpp"
|
||||
@@ -65,15 +67,106 @@ func init() {
|
||||
}()
|
||||
}
|
||||
|
||||
func main() {
|
||||
func dropToSignInPage(err error) {
|
||||
app := gtk.NewApplication("net.sunglocto.lambda.login", gio.ApplicationFlagsNone)
|
||||
app.ConnectActivate(func() {
|
||||
form_box := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||
|
||||
b, err := os.ReadFile("lambda.toml")
|
||||
server_box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
username_box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
password_box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
nickname_box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
insecure_box := gtk.NewBox(gtk.OrientationHorizontal, 0)
|
||||
|
||||
server_label := gtk.NewLabel("Server: ")
|
||||
username_label := gtk.NewLabel("Username: ")
|
||||
password_label := gtk.NewLabel("Password: ")
|
||||
nickname_label := gtk.NewLabel("Nickname: ")
|
||||
insecure_label := gtk.NewLabel("Insecure: ")
|
||||
|
||||
server_entry := gtk.NewEntry()
|
||||
server_entry.SetHAlign(gtk.AlignEnd)
|
||||
|
||||
username_entry := gtk.NewEntry()
|
||||
username_entry.SetHAlign(gtk.AlignEnd)
|
||||
|
||||
password_entry := gtk.NewPasswordEntry()
|
||||
password_entry.SetHAlign(gtk.AlignEnd)
|
||||
|
||||
nickname_entry := gtk.NewEntry()
|
||||
nickname_entry.SetHAlign(gtk.AlignEnd)
|
||||
|
||||
insecure_check := gtk.NewCheckButton()
|
||||
insecure_check.SetHAlign(gtk.AlignEnd)
|
||||
|
||||
|
||||
server_box.Append(server_label)
|
||||
server_box.Append(server_entry)
|
||||
|
||||
username_box.Append(username_label)
|
||||
username_box.Append(username_entry)
|
||||
|
||||
password_box.Append(password_label)
|
||||
password_box.Append(password_entry)
|
||||
|
||||
nickname_box.Append(nickname_label)
|
||||
nickname_box.Append(nickname_entry)
|
||||
|
||||
insecure_box.Append(insecure_label)
|
||||
insecure_box.Append(insecure_check)
|
||||
|
||||
form_box.Append(server_box)
|
||||
form_box.Append(username_box)
|
||||
form_box.Append(password_box)
|
||||
form_box.Append(nickname_box)
|
||||
form_box.Append(insecure_box)
|
||||
|
||||
sumbit_btn := gtk.NewButtonWithLabel("Submit")
|
||||
sumbit_btn.ConnectClicked(func() {
|
||||
conf := new(lambdaConfig)
|
||||
conf.Server = server_entry.Text()
|
||||
conf.Username = username_entry.Text()
|
||||
conf.Password = password_entry.Text()
|
||||
conf.Nick = nickname_entry.Text()
|
||||
conf.Insecure = insecure_check.Active()
|
||||
|
||||
var b bytes.Buffer
|
||||
e := toml.NewEncoder(&b)
|
||||
e.Encode(conf)
|
||||
|
||||
p, _ := ensureConfig()
|
||||
os.WriteFile(filepath.Join(p, "lambda.toml"), b.Bytes(), 0644)
|
||||
window.SetVisible(false)
|
||||
main()
|
||||
os.Exit(0)
|
||||
})
|
||||
|
||||
form_box.Append(sumbit_btn)
|
||||
|
||||
window = gtk.NewApplicationWindow(app)
|
||||
window.SetChild(form_box)
|
||||
window.SetResizable(false)
|
||||
window.SetVisible(true)
|
||||
})
|
||||
|
||||
if code := app.Run(os.Args); code == 0 {
|
||||
os.Exit(code)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
p, _ := ensureConfig()
|
||||
b, err := os.ReadFile(filepath.Join(p, "lambda.toml"))
|
||||
if err != nil {
|
||||
showErrorDialog(err)
|
||||
panic(err)
|
||||
dropToSignInPage(err)
|
||||
return
|
||||
// panic(err)
|
||||
}
|
||||
|
||||
_, err = toml.Decode(string(b), &loadedConfig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
config := xmpp.Config{
|
||||
TransportConfiguration: xmpp.TransportConfiguration{
|
||||
@@ -288,6 +381,7 @@ func main() {
|
||||
})
|
||||
|
||||
go func() {
|
||||
time.Sleep(3 * time.Second)
|
||||
err = cm.Run()
|
||||
if err != nil {
|
||||
showErrorDialog(err)
|
||||
|
||||
Reference in New Issue
Block a user