Independence of token flag from keyring (dbus)
This commit is contained in:
parent
652083ad94
commit
386ebfb494
2 changed files with 12 additions and 18 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/diamondburned/arikawa/v3/api"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/zalando/go-keyring"
|
||||
)
|
||||
|
||||
type LoginForm struct {
|
||||
|
|
@ -22,6 +23,7 @@ func newLoginForm() *LoginForm {
|
|||
lf.AddInputField("Email", "", 0, nil, nil)
|
||||
lf.AddPasswordField("Password", "", 0, 0, nil)
|
||||
lf.AddPasswordField("Code (optional)", "", 0, 0, nil)
|
||||
lf.AddCheckbox("Remember Me", true, nil)
|
||||
lf.AddButton("Login", lf.onLoginButtonSelected)
|
||||
|
||||
lf.SetTitle("Login")
|
||||
|
|
@ -64,11 +66,14 @@ func (lf *LoginForm) onLoginButtonSelected() {
|
|||
}
|
||||
|
||||
mainFlex = newMainFlex()
|
||||
|
||||
// We got the token, return with a new Session.
|
||||
if err = openState(l.Token); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
app.SetRoot(mainFlex, true)
|
||||
|
||||
rememberMe := lf.GetFormItem(4).(*tview.Checkbox).IsChecked()
|
||||
if rememberMe {
|
||||
go keyring.Set(config.Name, "token", l.Token)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
21
main.go
21
main.go
|
|
@ -21,7 +21,8 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&token, "token", "", "The authentication token.")
|
||||
t, _ := keyring.Get(config.Name, "token")
|
||||
flag.StringVar(&token, "token", t, "The authentication token.")
|
||||
|
||||
path, err := os.UserCacheDir()
|
||||
if err != nil {
|
||||
|
|
@ -47,17 +48,7 @@ func init() {
|
|||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
var err error
|
||||
if token != "" {
|
||||
go keyring.Set(config.Name, "token", token)
|
||||
} else {
|
||||
token, err = keyring.Get(config.Name, "token")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err = config.Load(); err != nil {
|
||||
if err := config.Load(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
@ -66,8 +57,7 @@ func main() {
|
|||
app.SetRoot(newLoginForm(), true)
|
||||
} else {
|
||||
mainFlex = newMainFlex()
|
||||
|
||||
if err = openState(token); err != nil {
|
||||
if err := openState(token); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
@ -75,8 +65,7 @@ func main() {
|
|||
}
|
||||
|
||||
app.EnableMouse(config.Current.Mouse)
|
||||
err = app.Run()
|
||||
if err != nil {
|
||||
if err := app.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue