mirror of
https://github.com/muesli/telephant
synced 2024-11-12 23:07:14 +00:00
Improved error handling in connect/auth stage
This commit is contained in:
parent
fb41281f8e
commit
332c6ecdde
3 changed files with 18 additions and 10 deletions
|
@ -9,8 +9,8 @@ import (
|
|||
type UIBridge struct {
|
||||
core.QObject
|
||||
|
||||
_ func(instance string) `slot:"connectButton"`
|
||||
_ func(code string, redirectURI string) `slot:"authButton"`
|
||||
_ func(instance string) bool `slot:"connectButton"`
|
||||
_ func(code string, redirectURI string) bool `slot:"authButton"`
|
||||
|
||||
_ func(replyid string, message string) `slot:"postButton"`
|
||||
_ func(id string) `slot:"shareButton"`
|
||||
|
|
|
@ -68,8 +68,10 @@ Popup {
|
|||
|
||||
onClicked: {
|
||||
var instance = instanceArea.text
|
||||
connectSwipeView.currentIndex = 1
|
||||
uiBridge.connectButton(instance)
|
||||
var result = uiBridge.connectButton(instance)
|
||||
if (result) {
|
||||
connectSwipeView.currentIndex = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -115,8 +117,10 @@ Popup {
|
|||
|
||||
onClicked: {
|
||||
var code = codeArea.text
|
||||
connectDialog.close()
|
||||
uiBridge.authButton(code, settings.redirectURL)
|
||||
var result = uiBridge.authButton(code, settings.redirectURL)
|
||||
if (result) {
|
||||
connectDialog.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
12
telephant.go
12
telephant.go
|
@ -20,14 +20,15 @@ var (
|
|||
accountMessagesModel = NewMessageModel(nil)
|
||||
)
|
||||
|
||||
func connectToInstance(instance string) {
|
||||
func connectToInstance(instance string) bool {
|
||||
var authURI string
|
||||
var redirectURI string
|
||||
var err error
|
||||
tc, authURI, redirectURI, err = mastodon.RegisterAccount(instance)
|
||||
if err != nil {
|
||||
fmt.Println("Error registering app:", err)
|
||||
return
|
||||
accountBridge.SetError(err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
configBridge.SetAuthURL(authURI)
|
||||
|
@ -35,13 +36,15 @@ func connectToInstance(instance string) {
|
|||
|
||||
fmt.Println("auth uri:", authURI)
|
||||
fmt.Println("redirect uri:", redirectURI)
|
||||
return true
|
||||
}
|
||||
|
||||
func authInstance(code, redirectURI string) {
|
||||
func authInstance(code, redirectURI string) bool {
|
||||
instance, token, clientID, clientSecret, err := tc.Authenticate(code, redirectURI)
|
||||
fmt.Println("authenticate:", err)
|
||||
if err != nil {
|
||||
return
|
||||
accountBridge.SetError(err.Error())
|
||||
return false
|
||||
}
|
||||
|
||||
config.Account[0].Instance = instance
|
||||
|
@ -49,6 +52,7 @@ func authInstance(code, redirectURI string) {
|
|||
config.Account[0].ClientSecret = clientSecret
|
||||
config.Account[0].Token = token
|
||||
setupMastodon(config.Account[0])
|
||||
return true
|
||||
}
|
||||
|
||||
// reply is used to post a new message
|
||||
|
|
Loading…
Reference in a new issue