|
@@ -28,7 +28,6 @@ var (
|
|
|
messageInputField *tview.InputField
|
|
messageInputField *tview.InputField
|
|
|
mainFlex *tview.Flex
|
|
mainFlex *tview.Flex
|
|
|
|
|
|
|
|
- loginVia string
|
|
|
|
|
kr keyring.Keyring
|
|
kr keyring.Keyring
|
|
|
config *util.Config
|
|
config *util.Config
|
|
|
discordSession *session.Session
|
|
discordSession *session.Session
|
|
@@ -55,7 +54,6 @@ func main() {
|
|
|
config = util.NewConfig()
|
|
config = util.NewConfig()
|
|
|
|
|
|
|
|
app = ui.NewApp(onAppInputCapture)
|
|
app = ui.NewApp(onAppInputCapture)
|
|
|
- loginModal = ui.NewLoginModal(onLoginModalDone)
|
|
|
|
|
guildsDropDown = ui.NewGuildsDropDown(onGuildsDropDownSelected, config.Theme)
|
|
guildsDropDown = ui.NewGuildsDropDown(onGuildsDropDownSelected, config.Theme)
|
|
|
channelsTreeNode = tview.NewTreeNode("")
|
|
channelsTreeNode = tview.NewTreeNode("")
|
|
|
channelsTreeView = ui.NewChannelsTreeView(channelsTreeNode, onChannelsTreeViewSelected, config.Theme)
|
|
channelsTreeView = ui.NewChannelsTreeView(channelsTreeNode, onChannelsTreeViewSelected, config.Theme)
|
|
@@ -70,7 +68,8 @@ func main() {
|
|
|
|
|
|
|
|
discordSession = newSession("", "", token)
|
|
discordSession = newSession("", "", token)
|
|
|
} else {
|
|
} else {
|
|
|
- app.SetRoot(loginModal, true)
|
|
|
|
|
|
|
+ loginForm = ui.NewLoginForm(onLoginFormLoginButtonSelected)
|
|
|
|
|
+ app.SetRoot(loginForm, true)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if err := app.Run(); err != nil {
|
|
if err := app.Run(); err != nil {
|
|
@@ -95,18 +94,6 @@ func onAppInputCapture(e *tcell.EventKey) *tcell.EventKey {
|
|
|
return e
|
|
return e
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func onLoginModalDone(i int, label string) {
|
|
|
|
|
- if label == ui.LoginViaEmailPasswordLoginModalButton {
|
|
|
|
|
- loginVia = "emailpassword"
|
|
|
|
|
- loginForm = ui.NewLoginForm(loginVia, onLoginFormLoginButtonSelected)
|
|
|
|
|
- app.SetRoot(loginForm, true)
|
|
|
|
|
- } else if label == ui.LoginViaTokenLoginModalButton {
|
|
|
|
|
- loginVia = "token"
|
|
|
|
|
- loginForm = ui.NewLoginForm(loginVia, onLoginFormLoginButtonSelected)
|
|
|
|
|
- app.SetRoot(loginForm, true)
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
func newSession(email string, password string, token string) *session.Session {
|
|
func newSession(email string, password string, token string) *session.Session {
|
|
|
api.UserAgent = "" +
|
|
api.UserAgent = "" +
|
|
|
"Mozilla/5.0 (X11; Linux x86_64) " +
|
|
"Mozilla/5.0 (X11; Linux x86_64) " +
|
|
@@ -224,28 +211,17 @@ func onChannelsTreeViewSelected(n *tview.TreeNode) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func onLoginFormLoginButtonSelected() {
|
|
func onLoginFormLoginButtonSelected() {
|
|
|
- if loginVia == "emailpassword" {
|
|
|
|
|
- email := loginForm.GetFormItemByLabel("Email").(*tview.InputField).GetText()
|
|
|
|
|
- password := loginForm.GetFormItemByLabel("Password").(*tview.InputField).GetText()
|
|
|
|
|
- if email == "" || password == "" {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- discordSession = newSession(email, password, "")
|
|
|
|
|
-
|
|
|
|
|
- go util.SetItem(kr, "token", discordSession.Token)
|
|
|
|
|
- } else if loginVia == "token" {
|
|
|
|
|
- token := loginForm.GetFormItemByLabel("Token").(*tview.InputField).GetText()
|
|
|
|
|
- if token == "" {
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- discordSession = newSession("", "", token)
|
|
|
|
|
-
|
|
|
|
|
- go util.SetItem(kr, "token", token)
|
|
|
|
|
|
|
+ email := loginForm.GetFormItemByLabel("Email").(*tview.InputField).GetText()
|
|
|
|
|
+ password := loginForm.GetFormItemByLabel("Password").(*tview.InputField).GetText()
|
|
|
|
|
+ if email == "" || password == "" {
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
app.
|
|
app.
|
|
|
SetRoot(mainFlex, true).
|
|
SetRoot(mainFlex, true).
|
|
|
SetFocus(guildsDropDown)
|
|
SetFocus(guildsDropDown)
|
|
|
|
|
+
|
|
|
|
|
+ discordSession = newSession(email, password, "")
|
|
|
|
|
+
|
|
|
|
|
+ go util.SetItem(kr, "token", discordSession.Token)
|
|
|
}
|
|
}
|