forked from sunglocto/lambda
seperate signin logic into its own file and have error handling
This commit is contained in:
107
gtk-signin.go
Normal file
107
gtk-signin.go
Normal file
@@ -0,0 +1,107 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
|
||||
"os"
|
||||
"bytes"
|
||||
|
||||
"github.com/diamondburned/gotk4/pkg/gio/v2"
|
||||
"github.com/diamondburned/gotk4/pkg/gtk/v4"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
func dropToSignInPage(err error) {
|
||||
app := gtk.NewApplication("net.sunglocto.lambda.login", gio.ApplicationFlagsNone)
|
||||
app.ConnectActivate(func() {
|
||||
form_box := gtk.NewBox(gtk.OrientationVertical, 0)
|
||||
|
||||
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, err := ensureConfig()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user